summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--adb_install.cpp2
-rw-r--r--install.cpp8
-rw-r--r--minui/graphics.cpp63
-rw-r--r--recovery.cpp6
-rw-r--r--roots.cpp2
-rw-r--r--update_verifier/update_verifier.cpp70
-rw-r--r--updater/blockimg.cpp2
-rw-r--r--updater/install.cpp4
8 files changed, 79 insertions, 78 deletions
diff --git a/adb_install.cpp b/adb_install.cpp
index fab72f8a4..79b8df91b 100644
--- a/adb_install.cpp
+++ b/adb_install.cpp
@@ -78,7 +78,7 @@ int apply_from_adb(RecoveryUI* ui, bool* wipe_cache, const char* install_file) {
pid_t child;
if ((child = fork()) == 0) {
execl("/sbin/recovery", "recovery", "--adbd", NULL);
- _exit(-1);
+ _exit(EXIT_FAILURE);
}
// FUSE_SIDELOAD_HOST_PATHNAME will start to exist once the host
diff --git a/install.cpp b/install.cpp
index 553ebae10..f51bbf05c 100644
--- a/install.cpp
+++ b/install.cpp
@@ -382,8 +382,12 @@ static int try_update_binary(const char* path, ZipArchiveHandle zip, bool* wipe_
umask(022);
close(pipefd[0]);
execv(chr_args[0], const_cast<char**>(chr_args));
- PLOG(ERROR) << "Can't run " << chr_args[0];
- _exit(-1);
+ // Bug: 34769056
+ // We shouldn't use LOG/PLOG in the forked process, since they may cause
+ // the child process to hang. This deadlock results from an improperly
+ // copied mutex in the ui functions.
+ fprintf(stdout, "E:Can't run %s (%s)\n", chr_args[0], strerror(errno));
+ _exit(EXIT_FAILURE);
}
close(pipefd[1]);
diff --git a/minui/graphics.cpp b/minui/graphics.cpp
index 3b3bb65b5..41e24f13f 100644
--- a/minui/graphics.cpp
+++ b/minui/graphics.cpp
@@ -16,21 +16,9 @@
#include "graphics.h"
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
-
-#include <fcntl.h>
-#include <stdio.h>
-
-#include <sys/ioctl.h>
-#include <sys/mman.h>
-#include <sys/types.h>
-
-#include <linux/fb.h>
-#include <linux/kd.h>
-
-#include <time.h>
#include "font_10x18.h"
#include "minui/minui.h"
@@ -319,55 +307,6 @@ static void gr_init_font(void)
gr_font->char_height = font.char_height;
}
-#if 0
-// Exercises many of the gr_*() functions; useful for testing.
-static void gr_test() {
- GRSurface** images;
- int frames;
- int result = res_create_multi_surface("icon_installing", &frames, &images);
- if (result < 0) {
- printf("create surface %d\n", result);
- gr_exit();
- return;
- }
-
- time_t start = time(NULL);
- int x;
- for (x = 0; x <= 1200; ++x) {
- if (x < 400) {
- gr_color(0, 0, 0, 255);
- } else {
- gr_color(0, (x-400)%128, 0, 255);
- }
- gr_clear();
-
- gr_color(255, 0, 0, 255);
- GRSurface* frame = images[x%frames];
- gr_blit(frame, 0, 0, frame->width, frame->height, x, 0);
-
- gr_color(255, 0, 0, 128);
- gr_fill(400, 150, 600, 350);
-
- gr_color(255, 255, 255, 255);
- gr_text(500, 225, "hello, world!", 0);
- gr_color(255, 255, 0, 128);
- gr_text(300+x, 275, "pack my box with five dozen liquor jugs", 1);
-
- gr_color(0, 0, 255, 128);
- gr_fill(gr_draw->width - 200 - x, 300, gr_draw->width - x, 500);
-
- gr_draw = gr_backend->flip(gr_backend);
- }
- printf("getting end time\n");
- time_t end = time(NULL);
- printf("got end time\n");
- printf("start %ld end %ld\n", (long)start, (long)end);
- if (end > start) {
- printf("%.2f fps\n", ((double)x) / (end-start));
- }
-}
-#endif
-
void gr_flip() {
gr_draw = gr_backend->flip(gr_backend);
}
diff --git a/recovery.cpp b/recovery.cpp
index 25d3546e3..29d7ab889 100644
--- a/recovery.cpp
+++ b/recovery.cpp
@@ -243,7 +243,7 @@ static void redirect_stdio(const char* filename) {
if (log_fp == nullptr) {
PLOG(ERROR) << "fopen \"" << filename << "\" failed";
close(pipefd[0]);
- _exit(1);
+ _exit(EXIT_FAILURE);
}
FILE* pipe_fp = fdopen(pipefd[0], "r");
@@ -251,7 +251,7 @@ static void redirect_stdio(const char* filename) {
PLOG(ERROR) << "fdopen failed";
check_and_fclose(log_fp, filename);
close(pipefd[0]);
- _exit(1);
+ _exit(EXIT_FAILURE);
}
char* line = nullptr;
@@ -273,7 +273,7 @@ static void redirect_stdio(const char* filename) {
free(line);
check_and_fclose(log_fp, filename);
close(pipefd[0]);
- _exit(1);
+ _exit(EXIT_FAILURE);
} else {
// Redirect stdout/stderr to the logger process.
// Close the unused read end.
diff --git a/roots.cpp b/roots.cpp
index 376fcbd1b..4a0a4948a 100644
--- a/roots.cpp
+++ b/roots.cpp
@@ -163,7 +163,7 @@ static int exec_cmd(const char* path, char* const argv[]) {
pid_t child;
if ((child = vfork()) == 0) {
execv(path, argv);
- _exit(-1);
+ _exit(EXIT_FAILURE);
}
waitpid(child, &status, 0);
if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
diff --git a/update_verifier/update_verifier.cpp b/update_verifier/update_verifier.cpp
index 1c9be2d58..a4799cc31 100644
--- a/update_verifier/update_verifier.cpp
+++ b/update_verifier/update_verifier.cpp
@@ -30,6 +30,7 @@
* verifier reaches the end after the verification.
*/
+#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
@@ -52,14 +53,71 @@ using android::hardware::boot::V1_0::BoolResult;
using android::hardware::boot::V1_0::CommandResult;
constexpr auto CARE_MAP_FILE = "/data/ota_package/care_map.txt";
+constexpr auto DM_PATH_PREFIX = "/sys/block/";
+constexpr auto DM_PATH_SUFFIX = "/dm/name";
+constexpr auto DEV_PATH = "/dev/block/";
constexpr int BLOCKSIZE = 4096;
-static bool read_blocks(const std::string& blk_device_prefix, const std::string& range_str) {
- std::string slot_suffix = android::base::GetProperty("ro.boot.slot_suffix", "");
- std::string blk_device = blk_device_prefix + slot_suffix;
- android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(blk_device.c_str(), O_RDONLY)));
+// Find directories in format of "/sys/block/dm-X".
+static int dm_name_filter(const dirent* de) {
+ if (android::base::StartsWith(de->d_name, "dm-")) {
+ return 1;
+ }
+ return 0;
+}
+
+static bool read_blocks(const std::string& blk_device, const std::string& range_str) {
+ // Parse the partition in the end of the block_device string.
+ // Here is one example: "/dev/block/bootdevice/by-name/system"
+ std::string partition;
+ if (android::base::EndsWith(blk_device, "system")) {
+ partition = "system";
+ } else if (android::base::EndsWith(blk_device, "vendor")) {
+ partition = "vendor";
+ } else {
+ LOG(ERROR) << "Failed to parse partition string in " << blk_device;
+ return false;
+ }
+
+ // Iterate the content of "/sys/block/dm-X/dm/name". If it matches "system"
+ // (or "vendor"), then dm-X is a dm-wrapped system/vendor partition.
+ // Afterwards, update_verifier will read every block on the care_map_file of
+ // "/dev/block/dm-X" to ensure the partition's integrity.
+ dirent** namelist;
+ int n = scandir(DM_PATH_PREFIX, &namelist, dm_name_filter, alphasort);
+ if (n == -1) {
+ PLOG(ERROR) << "Failed to scan dir " << DM_PATH_PREFIX;
+ return false;
+ }
+ if (n == 0) {
+ LOG(ERROR) << "dm block device not found for " << partition;
+ return false;
+ }
+
+ std::string dm_block_device;
+ while (n--) {
+ std::string path = DM_PATH_PREFIX + std::string(namelist[n]->d_name) + DM_PATH_SUFFIX;
+ std::string content;
+ if (!android::base::ReadFileToString(path, &content)) {
+ PLOG(WARNING) << "Failed to read " << path;
+ } else if (android::base::Trim(content) == partition) {
+ dm_block_device = DEV_PATH + std::string(namelist[n]->d_name);
+ while (n--) {
+ free(namelist[n]);
+ }
+ break;
+ }
+ free(namelist[n]);
+ }
+ free(namelist);
+
+ if (dm_block_device.empty()) {
+ LOG(ERROR) << "Failed to find dm block device for " << partition;
+ return false;
+ }
+ android::base::unique_fd fd(TEMP_FAILURE_RETRY(open(dm_block_device.c_str(), O_RDONLY)));
if (fd.get() == -1) {
- PLOG(ERROR) << "Error reading partition " << blk_device;
+ PLOG(ERROR) << "Error reading " << dm_block_device << " for partition " << partition;
return false;
}
@@ -100,7 +158,7 @@ static bool read_blocks(const std::string& blk_device_prefix, const std::string&
blk_count += (range_end - range_start);
}
- LOG(INFO) << "Finished reading " << blk_count << " blocks on " << blk_device;
+ LOG(INFO) << "Finished reading " << blk_count << " blocks on " << dm_block_device;
return true;
}
diff --git a/updater/blockimg.cpp b/updater/blockimg.cpp
index 6755d78cb..03ce4136e 100644
--- a/updater/blockimg.cpp
+++ b/updater/blockimg.cpp
@@ -120,7 +120,7 @@ static RangeSet parse_range(const std::string& range_text) {
err:
LOG(ERROR) << "failed to parse range '" << range_text << "'";
- exit(1);
+ exit(EXIT_FAILURE);
}
static bool range_overlaps(const RangeSet& r1, const RangeSet& r2) {
diff --git a/updater/install.cpp b/updater/install.cpp
index 7a8e92f6c..c7ecdb5c7 100644
--- a/updater/install.cpp
+++ b/updater/install.cpp
@@ -247,7 +247,7 @@ static int exec_cmd(const char* path, char* const argv[]) {
pid_t child;
if ((child = vfork()) == 0) {
execv(path, argv);
- _exit(-1);
+ _exit(EXIT_FAILURE);
}
int status;
@@ -1072,7 +1072,7 @@ Value* RunProgramFn(const char* name, State* state, int argc, Expr* argv[]) {
if (child == 0) {
execv(args2[0], args2);
PLOG(ERROR) << "run_program: execv failed";
- _exit(1);
+ _exit(EXIT_FAILURE);
}
int status;