From 39c1b5e8722dbf0bbb3ee45e201373099f075345 Mon Sep 17 00:00:00 2001 From: Jed Estep Date: Tue, 15 Dec 2015 16:04:53 -0800 Subject: Control fault injection with config files instead of build flags Bug: 26570379 Change-Id: I76109d09276d6e3ed3a32b6fedafb2582f545c0c (cherry picked from commit d940887dde23597dc358b16d96ca48dd7480fee6) --- updater/updater.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'updater/updater.cpp') diff --git a/updater/updater.cpp b/updater/updater.cpp index 0f22e6d04..efb4a8cec 100644 --- a/updater/updater.cpp +++ b/updater/updater.cpp @@ -25,6 +25,7 @@ #include "blockimg.h" #include "minzip/Zip.h" #include "minzip/SysUtil.h" +#include "config.h" // Generated by the makefile, this function defines the // RegisterDeviceExtensions() function, which calls all the @@ -82,6 +83,7 @@ int main(int argc, char** argv) { argv[3], strerror(err)); return 3; } + ota_io_init(&za); const ZipEntry* script_entry = mzFindZipEntry(&za, SCRIPT_NAME); if (script_entry == NULL) { -- cgit v1.2.3 From 3c62b67faf8a25f1dd1c44dc19759c3997fdfd36 Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Fri, 5 Feb 2016 18:25:58 -0800 Subject: Reboot and retry on I/O errors When I/O error happens, reboot and retry installation two times before we abort this OTA update. Bug: 25633753 Change-Id: Iba6d4203a343a725aa625a41d237606980d62f69 --- updater/updater.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'updater/updater.cpp') diff --git a/updater/updater.cpp b/updater/updater.cpp index efb4a8cec..1693fa1db 100644 --- a/updater/updater.cpp +++ b/updater/updater.cpp @@ -36,6 +36,8 @@ // (Note it's "updateR-script", not the older "update-script".) #define SCRIPT_NAME "META-INF/com/google/android/updater-script" +extern bool have_eio_error; + struct selabel_handle *sehandle; int main(int argc, char** argv) { @@ -141,6 +143,11 @@ int main(int argc, char** argv) { state.errmsg = NULL; char* result = Evaluate(&state, root); + + if (have_eio_error) { + fprintf(cmd_pipe, "retry_update\n"); + } + if (result == NULL) { if (state.errmsg == NULL) { printf("script aborted (no error message)\n"); -- cgit v1.2.3 From 4bbd5bf8a6383d31341221b97e5e320d5abba085 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 1 Apr 2016 18:24:39 -0700 Subject: Move selinux dependencies out of header files. Bug: http://b/27764900 Change-Id: Ib62a59edcb13054f40f514c404d32b87b14ed5f1 --- updater/updater.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'updater/updater.cpp') diff --git a/updater/updater.cpp b/updater/updater.cpp index 1693fa1db..0497d6a85 100644 --- a/updater/updater.cpp +++ b/updater/updater.cpp @@ -27,6 +27,9 @@ #include "minzip/SysUtil.h" #include "config.h" +#include +#include + // Generated by the makefile, this function defines the // RegisterDeviceExtensions() function, which calls all the // registration functions for device-specific extensions. -- cgit v1.2.3 From 59dcb9cbea8fb70ab933fd10d35582b08cd13f37 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 3 Oct 2016 18:06:46 -0700 Subject: edify: Move State.script and State.errmsg to std::string. This way we kill a few strdup() and free() calls. Test: 1. recovery_component_test still passes; 2. Applying an update with the new updater works; 3. The error code in a script with abort("E310: xyz") is recorded into last_install correctly. Change-Id: Ibda4da5937346e058a0d7cc81764d6f02920010a --- updater/updater.cpp | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'updater/updater.cpp') diff --git a/updater/updater.cpp b/updater/updater.cpp index c222cee0d..74a4048fb 100644 --- a/updater/updater.cpp +++ b/updater/updater.cpp @@ -14,21 +14,23 @@ * limitations under the License. */ +#include "updater.h" + #include #include #include #include +#include +#include +#include + +#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 -#include // Generated by the makefile, this function defines the // RegisterDeviceExtensions() function, which calls all the @@ -140,10 +142,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; - state.errmsg = NULL; + State state(script, &updater_info); if (argc == 5) { if (strcmp(argv[4], "retry") == 0) { @@ -160,22 +159,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 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"); } @@ -189,7 +187,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); -- cgit v1.2.3 From 0c7839ac14a00f32d740c23ddf6df65f2757ece5 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 10 Oct 2016 15:48:37 -0700 Subject: Refactor libupdater into a seperate module. So that we can write native tests for updater functions. This CL adds a testcase for getprop() function. Test: mmma bootable/recovery; Run recovery_component_test on device. Change-Id: Iff4c1ff63c5c71aded2f9686fed6b71cc298c228 --- updater/updater.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'updater/updater.cpp') diff --git a/updater/updater.cpp b/updater/updater.cpp index 74a4048fb..45e31e097 100644 --- a/updater/updater.cpp +++ b/updater/updater.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "updater.h" +#include "updater/updater.h" #include #include @@ -27,10 +27,10 @@ #include "config.h" #include "edify/expr.h" -#include "blockimg.h" -#include "install.h" -#include "minzip/Zip.h" #include "minzip/SysUtil.h" +#include "minzip/Zip.h" +#include "updater/blockimg.h" +#include "updater/install.h" // Generated by the makefile, this function defines the // RegisterDeviceExtensions() function, which calls all the -- cgit v1.2.3 From 39119ad8ecd00a9c19fb173c78cb4a8d22a4540a Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Mon, 10 Oct 2016 22:52:18 -0700 Subject: edify: Some clean-ups to libedify. - Remove dead declarations in expr.h: SetError(), GetError(), ClearError(). - Remove the declaration of Build() out of expr.h. - Use std::unordered_map to implement RegisterFunction() and FindFunction(); kill FinishRegistration(). - Add a testcase for calling unknown functions. Test: mmma bootable/recovery; recovery_component_test passes. Change-Id: I9af6825ae677f92b22d716a4a5682f58522af03b --- updater/updater.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'updater/updater.cpp') diff --git a/updater/updater.cpp b/updater/updater.cpp index 45e31e097..c752ebbf3 100644 --- a/updater/updater.cpp +++ b/updater/updater.cpp @@ -111,7 +111,6 @@ int main(int argc, char** argv) { RegisterInstallFunctions(); RegisterBlockImageFunctions(); RegisterDeviceExtensions(); - FinishRegistration(); // Parse the script. -- cgit v1.2.3 From aced5d9e4e438ba478ce54f9217166b8ab7cc24f Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Wed, 12 Oct 2016 10:55:04 -0700 Subject: Change StringValue to use std::string Changing the field of 'Value' in edify to std::string from char*. Meanwhile cleaning up the users of 'Value' and switching them to cpp style. Test: compontent tests passed. Bug: 31713288 Change-Id: Iec5a7d601b1e4ca40935bf1c70d325dafecec235 --- updater/updater.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'updater/updater.cpp') diff --git a/updater/updater.cpp b/updater/updater.cpp index c752ebbf3..47696b80c 100644 --- a/updater/updater.cpp +++ b/updater/updater.cpp @@ -151,13 +151,14 @@ int main(int argc, char** argv) { } } - char* result = Evaluate(&state, root); + std::string result; + bool status = Evaluate(&state, root, &result); if (have_eio_error) { fprintf(cmd_pipe, "retry_update\n"); } - if (result == NULL) { + if (!status) { if (state.errmsg.empty()) { printf("script aborted (no error message)\n"); fprintf(cmd_pipe, "ui_print script aborted (no error message)\n"); @@ -188,8 +189,7 @@ int main(int argc, char** argv) { return 7; } else { - fprintf(cmd_pipe, "ui_print script succeeded: result was [%s]\n", result); - free(result); + fprintf(cmd_pipe, "ui_print script succeeded: result was [%s]\n", result.c_str()); } if (updater_info.package_zip) { -- cgit v1.2.3 From 8cf5c8f60f51049278b08ae4cbc31df397b651fd Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Thu, 8 Sep 2016 20:10:11 -0700 Subject: Replace minzip with libziparchive Clean up the duplicated codes that handle the zip files in bootable/recovery; and rename the library of the remaining utility functions to libotautil. Test: Update package installed successfully on angler. Bug: 19472796 Change-Id: Iea8962fcf3004473cb0322b6bb3a9ea3ca7f679e --- updater/updater.cpp | 53 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 20 deletions(-) (limited to 'updater/updater.cpp') diff --git a/updater/updater.cpp b/updater/updater.cpp index 47696b80c..7327c52e3 100644 --- a/updater/updater.cpp +++ b/updater/updater.cpp @@ -21,14 +21,17 @@ #include #include +#include + #include #include #include +#include #include "config.h" #include "edify/expr.h" -#include "minzip/SysUtil.h" -#include "minzip/Zip.h" +#include "otautil/DirUtil.h" +#include "otautil/SysUtil.h" #include "updater/blockimg.h" #include "updater/install.h" @@ -82,28 +85,35 @@ int main(int argc, char** argv) { printf("failed to map package %s\n", argv[3]); return 3; } - ZipArchive za; - int err; - err = mzOpenZipArchive(map.addr, map.length, &za); - if (err != 0) { + ZipArchiveHandle za; + int open_err = OpenArchiveFromMemory(map.addr, map.length, argv[3], &za); + if (open_err != 0) { printf("failed to open package %s: %s\n", - argv[3], strerror(err)); + argv[3], ErrorCodeString(open_err)); + CloseArchive(za); return 3; } - ota_io_init(&za); - - const ZipEntry* script_entry = mzFindZipEntry(&za, SCRIPT_NAME); - if (script_entry == NULL) { - printf("failed to find %s in %s\n", SCRIPT_NAME, package_filename); + ota_io_init(za); + + ZipString script_name(SCRIPT_NAME); + ZipEntry script_entry; + int find_err = FindEntry(za, script_name, &script_entry); + if (find_err != 0) { + printf("failed to find %s in %s: %s\n", SCRIPT_NAME, package_filename, + ErrorCodeString(find_err)); + CloseArchive(za); return 4; } - char* script = reinterpret_cast(malloc(script_entry->uncompLen+1)); - if (!mzReadZipEntry(&za, script_entry, script, script_entry->uncompLen)) { - printf("failed to read script from package\n"); + std::string script; + script.resize(script_entry.uncompressed_length); + int extract_err = ExtractToMemory(za, &script_entry, reinterpret_cast(&script[0]), + script_entry.uncompressed_length); + if (extract_err != 0) { + printf("failed to read script from package: %s\n", ErrorCodeString(extract_err)); + CloseArchive(za); return 5; } - script[script_entry->uncompLen] = '\0'; // Configure edify's functions. @@ -116,9 +126,10 @@ int main(int argc, char** argv) { Expr* root; int error_count = 0; - int error = parse_string(script, &root, &error_count); + int error = parse_string(script.c_str(), &root, &error_count); if (error != 0 || error_count > 0) { printf("%d parse errors\n", error_count); + CloseArchive(za); return 6; } @@ -136,7 +147,7 @@ int main(int argc, char** argv) { UpdaterInfo updater_info; updater_info.cmd_pipe = cmd_pipe; - updater_info.package_zip = &za; + updater_info.package_zip = za; updater_info.version = atoi(version); updater_info.package_zip_addr = map.addr; updater_info.package_zip_len = map.length; @@ -187,16 +198,18 @@ int main(int argc, char** argv) { } } + if (updater_info.package_zip) { + CloseArchive(updater_info.package_zip); + } return 7; } else { fprintf(cmd_pipe, "ui_print script succeeded: result was [%s]\n", result.c_str()); } if (updater_info.package_zip) { - mzCloseZipArchive(updater_info.package_zip); + CloseArchive(updater_info.package_zip); } sysReleaseMap(&map); - free(script); return 0; } -- cgit v1.2.3 From 039f2da3e464034404afe27aebd93f84fba119b6 Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Tue, 22 Nov 2016 16:29:50 -0800 Subject: updater: Switch to libbase logging. Test: Build an updater into a package and apply it on device. Change-Id: I289b5768e9b1e44ef78e0479c64dbaa36fb1a685 --- updater/updater.cpp | 309 ++++++++++++++++++++++++++-------------------------- 1 file changed, 157 insertions(+), 152 deletions(-) (limited to 'updater/updater.cpp') diff --git a/updater/updater.cpp b/updater/updater.cpp index 7327c52e3..3e624dae7 100644 --- a/updater/updater.cpp +++ b/updater/updater.cpp @@ -23,6 +23,7 @@ #include +#include #include #include #include @@ -42,174 +43,178 @@ // Where in the package we expect to find the edify script to execute. // (Note it's "updateR-script", not the older "update-script".) -#define SCRIPT_NAME "META-INF/com/google/android/updater-script" +static constexpr const char* SCRIPT_NAME = "META-INF/com/google/android/updater-script"; extern bool have_eio_error; struct selabel_handle *sehandle; -int main(int argc, char** argv) { - // Various things log information to stdout or stderr more or less - // at random (though we've tried to standardize on stdout). The - // log file makes more sense if buffering is turned off so things - // appear in the right order. - setbuf(stdout, NULL); - setbuf(stderr, NULL); - - if (argc != 4 && argc != 5) { - printf("unexpected number of arguments (%d)\n", argc); - return 1; - } - - char* version = argv[1]; - if ((version[0] != '1' && version[0] != '2' && version[0] != '3') || - version[1] != '\0') { - // We support version 1, 2, or 3. - printf("wrong updater binary API; expected 1, 2, or 3; " - "got %s\n", - argv[1]); - return 2; - } - - // Set up the pipe for sending commands back to the parent process. - - int fd = atoi(argv[2]); - FILE* cmd_pipe = fdopen(fd, "wb"); - setlinebuf(cmd_pipe); - - // Extract the script from the package. - - const char* package_filename = argv[3]; - MemMapping map; - if (sysMapFile(package_filename, &map) != 0) { - printf("failed to map package %s\n", argv[3]); - return 3; - } - ZipArchiveHandle za; - int open_err = OpenArchiveFromMemory(map.addr, map.length, argv[3], &za); - if (open_err != 0) { - printf("failed to open package %s: %s\n", - argv[3], ErrorCodeString(open_err)); - CloseArchive(za); - return 3; - } - ota_io_init(za); - - ZipString script_name(SCRIPT_NAME); - ZipEntry script_entry; - int find_err = FindEntry(za, script_name, &script_entry); - if (find_err != 0) { - printf("failed to find %s in %s: %s\n", SCRIPT_NAME, package_filename, - ErrorCodeString(find_err)); - CloseArchive(za); - return 4; - } - - std::string script; - script.resize(script_entry.uncompressed_length); - int extract_err = ExtractToMemory(za, &script_entry, reinterpret_cast(&script[0]), - script_entry.uncompressed_length); - if (extract_err != 0) { - printf("failed to read script from package: %s\n", ErrorCodeString(extract_err)); - CloseArchive(za); - return 5; - } - - // Configure edify's functions. - - RegisterBuiltins(); - RegisterInstallFunctions(); - RegisterBlockImageFunctions(); - RegisterDeviceExtensions(); - - // Parse the script. - - Expr* root; - int error_count = 0; - int error = parse_string(script.c_str(), &root, &error_count); - if (error != 0 || error_count > 0) { - printf("%d parse errors\n", error_count); - CloseArchive(za); - return 6; - } - - struct selinux_opt seopts[] = { - { SELABEL_OPT_PATH, "/file_contexts" } - }; - - sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1); +static void UpdaterLogger(android::base::LogId /* id */, android::base::LogSeverity /* severity */, + const char* /* tag */, const char* /* file */, unsigned int /* line */, + const char* message) { + fprintf(stdout, "%s\n", message); +} - if (!sehandle) { - fprintf(cmd_pipe, "ui_print Warning: No file_contexts\n"); +int main(int argc, char** argv) { + // Various things log information to stdout or stderr more or less + // at random (though we've tried to standardize on stdout). The + // log file makes more sense if buffering is turned off so things + // appear in the right order. + setbuf(stdout, nullptr); + setbuf(stderr, nullptr); + + // We don't have logcat yet under recovery. Update logs will always be written to stdout + // (which is redirected to recovery.log). + android::base::InitLogging(argv, &UpdaterLogger); + + if (argc != 4 && argc != 5) { + LOG(ERROR) << "unexpected number of arguments: " << argc; + return 1; + } + + char* version = argv[1]; + if ((version[0] != '1' && version[0] != '2' && version[0] != '3') || version[1] != '\0') { + // We support version 1, 2, or 3. + LOG(ERROR) << "wrong updater binary API; expected 1, 2, or 3; got " << argv[1]; + return 2; + } + + // Set up the pipe for sending commands back to the parent process. + + int fd = atoi(argv[2]); + FILE* cmd_pipe = fdopen(fd, "wb"); + setlinebuf(cmd_pipe); + + // Extract the script from the package. + + const char* package_filename = argv[3]; + MemMapping map; + if (sysMapFile(package_filename, &map) != 0) { + LOG(ERROR) << "failed to map package " << argv[3]; + return 3; + } + ZipArchiveHandle za; + int open_err = OpenArchiveFromMemory(map.addr, map.length, argv[3], &za); + if (open_err != 0) { + LOG(ERROR) << "failed to open package " << argv[3] << ": " << ErrorCodeString(open_err); + CloseArchive(za); + return 3; + } + ota_io_init(za); + + ZipString script_name(SCRIPT_NAME); + ZipEntry script_entry; + int find_err = FindEntry(za, script_name, &script_entry); + if (find_err != 0) { + LOG(ERROR) << "failed to find " << SCRIPT_NAME << " in " << package_filename << ": " + << ErrorCodeString(find_err); + CloseArchive(za); + return 4; + } + + std::string script; + script.resize(script_entry.uncompressed_length); + int extract_err = ExtractToMemory(za, &script_entry, reinterpret_cast(&script[0]), + script_entry.uncompressed_length); + if (extract_err != 0) { + LOG(ERROR) << "failed to read script from package: " << ErrorCodeString(extract_err); + CloseArchive(za); + return 5; + } + + // Configure edify's functions. + + RegisterBuiltins(); + RegisterInstallFunctions(); + RegisterBlockImageFunctions(); + RegisterDeviceExtensions(); + + // Parse the script. + + Expr* root; + int error_count = 0; + int error = parse_string(script.c_str(), &root, &error_count); + if (error != 0 || error_count > 0) { + LOG(ERROR) << error_count << " parse errors"; + CloseArchive(za); + return 6; + } + + struct selinux_opt seopts[] = { { SELABEL_OPT_PATH, "/file_contexts" } }; + + sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1); + + if (!sehandle) { + fprintf(cmd_pipe, "ui_print Warning: No file_contexts\n"); + } + + // Evaluate the parsed script. + + UpdaterInfo updater_info; + updater_info.cmd_pipe = cmd_pipe; + updater_info.package_zip = za; + updater_info.version = atoi(version); + updater_info.package_zip_addr = map.addr; + updater_info.package_zip_len = map.length; + + State state(script, &updater_info); + + if (argc == 5) { + if (strcmp(argv[4], "retry") == 0) { + state.is_retry = true; + } else { + printf("unexpected argument: %s", argv[4]); } + } - // Evaluate the parsed script. + std::string result; + bool status = Evaluate(&state, root, &result); - UpdaterInfo updater_info; - updater_info.cmd_pipe = cmd_pipe; - updater_info.package_zip = za; - updater_info.version = atoi(version); - updater_info.package_zip_addr = map.addr; - updater_info.package_zip_len = map.length; + if (have_eio_error) { + fprintf(cmd_pipe, "retry_update\n"); + } - State state(script, &updater_info); - - if (argc == 5) { - if (strcmp(argv[4], "retry") == 0) { - state.is_retry = true; - } else { - printf("unexpected argument: %s", argv[4]); + if (!status) { + if (state.errmsg.empty()) { + LOG(ERROR) << "script aborted (no error message)"; + fprintf(cmd_pipe, "ui_print script aborted (no error message)\n"); + } else { + LOG(ERROR) << "script aborted: " << state.errmsg; + const std::vector 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.empty() && line[0] == 'E') { + if (sscanf(line.c_str(), "E%u: ", &state.error_code) != 1) { + LOG(ERROR) << "Failed to parse error code: [" << line << "]"; + } } + fprintf(cmd_pipe, "ui_print %s\n", line.c_str()); + } + fprintf(cmd_pipe, "ui_print\n"); } - std::string result; - bool status = Evaluate(&state, root, &result); - - if (have_eio_error) { - fprintf(cmd_pipe, "retry_update\n"); - } - - if (!status) { - 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.c_str()); - const std::vector 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.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.c_str()); - } - fprintf(cmd_pipe, "ui_print\n"); - } - - if (state.error_code != kNoError) { - fprintf(cmd_pipe, "log error: %d\n", state.error_code); - // Cause code should provide additional information about the abort; - // report only when an error exists. - if (state.cause_code != kNoCause) { - fprintf(cmd_pipe, "log cause: %d\n", state.cause_code); - } - } - - if (updater_info.package_zip) { - CloseArchive(updater_info.package_zip); - } - return 7; - } else { - fprintf(cmd_pipe, "ui_print script succeeded: result was [%s]\n", result.c_str()); + if (state.error_code != kNoError) { + fprintf(cmd_pipe, "log error: %d\n", state.error_code); + // Cause code should provide additional information about the abort; + // report only when an error exists. + if (state.cause_code != kNoCause) { + fprintf(cmd_pipe, "log cause: %d\n", state.cause_code); + } } if (updater_info.package_zip) { - CloseArchive(updater_info.package_zip); + CloseArchive(updater_info.package_zip); } - sysReleaseMap(&map); + return 7; + } else { + fprintf(cmd_pipe, "ui_print script succeeded: result was [%s]\n", result.c_str()); + } + + if (updater_info.package_zip) { + CloseArchive(updater_info.package_zip); + } + sysReleaseMap(&map); - return 0; + return 0; } -- cgit v1.2.3 From 4728242070ce806828024f00ab3dac6ba48f3206 Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Mon, 9 Jan 2017 13:45:37 -0800 Subject: Do not inject I/O fault on a retry We could inject I/O faults during an OTA update for test purpose. But we should skip the injection if the update is an retry. Otherwise the update test will simply keeps failing. Bug: 34159970 Test: Apply the same package on angler and the update succeeds on the 2nd try. Change-Id: Id274e5475e3bc8d25d50a8cf61a77d2e32c569d6 --- updater/updater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'updater/updater.cpp') diff --git a/updater/updater.cpp b/updater/updater.cpp index 3e624dae7..473066263 100644 --- a/updater/updater.cpp +++ b/updater/updater.cpp @@ -100,7 +100,6 @@ int main(int argc, char** argv) { CloseArchive(za); return 3; } - ota_io_init(za); ZipString script_name(SCRIPT_NAME); ZipEntry script_entry; @@ -166,6 +165,7 @@ int main(int argc, char** argv) { printf("unexpected argument: %s", argv[4]); } } + ota_io_init(za, state.is_retry); std::string result; bool status = Evaluate(&state, root, &result); -- cgit v1.2.3 From f013642477dbe0a5ed8d440571e9c8676ed42b2d Mon Sep 17 00:00:00 2001 From: Tao Bao Date: Sat, 21 Jan 2017 13:03:25 -0800 Subject: Print with newline for ui_print. Currently the ui_print command between the recovery and updater doesn't append newline. Updater has to send an extra "ui_print" command without any argument to get the line break. This looks unnecessary. And not all the callers (including the ones in bootable/recovery) are following this protocol when sending the ui_print command. This CL simplifies the protocol to always print with a newline for ui_print command. When updating from an old recovery with the new updater, all the ui_print'd strings would appear in one line as a side effect. But a) it would only affect the text-mode UI, which won't be shown to users; b) log files won't be affected. Bug: 32305035 Test: Apply an update with the new updater on top of an old and new recovery image respectively. Change-Id: I305a0ffc6f180daf60919cf99d24d1495d68749b --- updater/updater.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'updater/updater.cpp') diff --git a/updater/updater.cpp b/updater/updater.cpp index 473066263..22c060fcb 100644 --- a/updater/updater.cpp +++ b/updater/updater.cpp @@ -191,7 +191,6 @@ int main(int argc, char** argv) { } fprintf(cmd_pipe, "ui_print %s\n", line.c_str()); } - fprintf(cmd_pipe, "ui_print\n"); } if (state.error_code != kNoError) { -- cgit v1.2.3 From c444732540d5245b6219293e96d29f325daa7839 Mon Sep 17 00:00:00 2001 From: Tianjie Xu Date: Mon, 6 Mar 2017 14:44:59 -0800 Subject: Remove malloc in edify functions And switch them to std::vector & std::unique_ptr Bug: 32117870 Test: recovery tests passed on sailfish Change-Id: I5a45951c4bdf895be311d6d760e52e7a1b0798c3 --- updater/updater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'updater/updater.cpp') diff --git a/updater/updater.cpp b/updater/updater.cpp index 22c060fcb..0693cbd98 100644 --- a/updater/updater.cpp +++ b/updater/updater.cpp @@ -130,7 +130,7 @@ int main(int argc, char** argv) { // Parse the script. - Expr* root; + std::unique_ptr root; int error_count = 0; int error = parse_string(script.c_str(), &root, &error_count); if (error != 0 || error_count > 0) { -- cgit v1.2.3 From 17e6d3f3bcd27aedc2ff8fe796ce90dddb04a714 Mon Sep 17 00:00:00 2001 From: Mikhail Lappo Date: Thu, 23 Mar 2017 16:56:50 +0100 Subject: Fixed scanf modifier Scanf expectation is to have same type of pointer to store parsed value and modifier in format string --- updater/updater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'updater/updater.cpp') diff --git a/updater/updater.cpp b/updater/updater.cpp index 0693cbd98..c09e267a5 100644 --- a/updater/updater.cpp +++ b/updater/updater.cpp @@ -185,7 +185,7 @@ int main(int argc, char** argv) { // Parse the error code in abort message. // Example: "E30: This package is for bullhead devices." if (!line.empty() && line[0] == 'E') { - if (sscanf(line.c_str(), "E%u: ", &state.error_code) != 1) { + if (sscanf(line.c_str(), "E%d: ", &state.error_code) != 1) { LOG(ERROR) << "Failed to parse error code: [" << line << "]"; } } -- cgit v1.2.3 From e35926e1aff2e6b9b54656bd59c8178e295a1b7e Mon Sep 17 00:00:00 2001 From: Jeff Vander Stoep Date: Wed, 14 Jun 2017 15:30:39 -0700 Subject: Fix "No file_contexts" warning Fixed by Loading the file_contexts specified in libselinux, whereas previously recovery loaded /file_contexts which no longer exists. Bug: 62587423 Test: build and flash recovery on Angler. Warning is gone. Test: Wipe data and cache. Test: sideload OTA Change-Id: I11581c878b860ac5f412e6e8e7acde811f37870f (cherry picked from commit 2330dd8733ce0b207058e3003a3b1efebc022394) --- updater/updater.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'updater/updater.cpp') diff --git a/updater/updater.cpp b/updater/updater.cpp index c09e267a5..f3e282044 100644 --- a/updater/updater.cpp +++ b/updater/updater.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -139,9 +140,8 @@ int main(int argc, char** argv) { return 6; } - struct selinux_opt seopts[] = { { SELABEL_OPT_PATH, "/file_contexts" } }; - - sehandle = selabel_open(SELABEL_CTX_FILE, seopts, 1); + sehandle = selinux_android_file_context_handle(); + selinux_android_set_sehandle(sehandle); if (!sehandle) { fprintf(cmd_pipe, "ui_print Warning: No file_contexts\n"); -- cgit v1.2.3