summaryrefslogtreecommitdiffstats
path: root/updater/updater.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2016-10-04 03:06:46 +0200
committerTao Bao <tbao@google.com>2016-10-05 00:33:22 +0200
commit876b9391c084701b147af3b0d5c933d877bb6052 (patch)
tree603d90593492fb898a8f76824192aaa03630c614 /updater/updater.cpp
parentMerge "recovery: drop log/logger.h" am: 38b923ff6c am: 7cf7e6ce4f am: 0467a905cc (diff)
downloadandroid_bootable_recovery-876b9391c084701b147af3b0d5c933d877bb6052.tar
android_bootable_recovery-876b9391c084701b147af3b0d5c933d877bb6052.tar.gz
android_bootable_recovery-876b9391c084701b147af3b0d5c933d877bb6052.tar.bz2
android_bootable_recovery-876b9391c084701b147af3b0d5c933d877bb6052.tar.lz
android_bootable_recovery-876b9391c084701b147af3b0d5c933d877bb6052.tar.xz
android_bootable_recovery-876b9391c084701b147af3b0d5c933d877bb6052.tar.zst
android_bootable_recovery-876b9391c084701b147af3b0d5c933d877bb6052.zip
Diffstat (limited to 'updater/updater.cpp')
-rw-r--r--updater/updater.cpp37
1 files changed, 17 insertions, 20 deletions
diff --git a/updater/updater.cpp b/updater/updater.cpp
index 9fa01a53c..2497bd56d 100644
--- a/updater/updater.cpp
+++ b/updater/updater.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#include "updater.h"
+
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
@@ -21,16 +23,16 @@
#include <string>
+#include <android-base/strings.h>
+#include <selinux/label.h>
+#include <selinux/selinux.h>
+
+#include "config.h"
#include "edify/expr.h"
-#include "updater.h"
-#include "install.h"
#include "blockimg.h"
+#include "install.h"
#include "minzip/Zip.h"
#include "minzip/SysUtil.h"
-#include "config.h"
-
-#include <selinux/label.h>
-#include <selinux/selinux.h>
// Generated by the makefile, this function defines the
// RegisterDeviceExtensions() function, which calls all the
@@ -141,10 +143,7 @@ int main(int argc, char** argv) {
updater_info.package_zip_addr = map.addr;
updater_info.package_zip_len = map.length;
- State state;
- state.cookie = &updater_info;
- state.script = &script[0];
- state.errmsg = NULL;
+ State state(script, &updater_info);
if (argc == 5) {
if (strcmp(argv[4], "retry") == 0) {
@@ -161,22 +160,21 @@ int main(int argc, char** argv) {
}
if (result == NULL) {
- if (state.errmsg == NULL) {
+ if (state.errmsg.empty()) {
printf("script aborted (no error message)\n");
fprintf(cmd_pipe, "ui_print script aborted (no error message)\n");
} else {
- printf("script aborted: %s\n", state.errmsg);
- char* line = strtok(state.errmsg, "\n");
- while (line) {
+ printf("script aborted: %s\n", state.errmsg.c_str());
+ const std::vector<std::string> lines = android::base::Split(state.errmsg, "\n");
+ for (const std::string& line : lines) {
// Parse the error code in abort message.
// Example: "E30: This package is for bullhead devices."
- if (*line == 'E') {
- if (sscanf(line, "E%u: ", &state.error_code) != 1) {
- printf("Failed to parse error code: [%s]\n", line);
+ if (!line.empty() && line[0] == 'E') {
+ if (sscanf(line.c_str(), "E%u: ", &state.error_code) != 1) {
+ printf("Failed to parse error code: [%s]\n", line.c_str());
}
}
- fprintf(cmd_pipe, "ui_print %s\n", line);
- line = strtok(NULL, "\n");
+ fprintf(cmd_pipe, "ui_print %s\n", line.c_str());
}
fprintf(cmd_pipe, "ui_print\n");
}
@@ -190,7 +188,6 @@ int main(int argc, char** argv) {
}
}
- free(state.errmsg);
return 7;
} else {
fprintf(cmd_pipe, "ui_print script succeeded: result was [%s]\n", result);