diff options
-rw-r--r-- | bootloader.cpp | 29 | ||||
-rw-r--r-- | etc/init.rc | 1 |
2 files changed, 8 insertions, 22 deletions
diff --git a/bootloader.cpp b/bootloader.cpp index 1c2097983..600d238f5 100644 --- a/bootloader.cpp +++ b/bootloader.cpp @@ -21,12 +21,9 @@ #include "roots.h" #include <errno.h> -#include <fcntl.h> -#include <inttypes.h> #include <stdio.h> #include <string.h> #include <sys/stat.h> -#include <sys/types.h> #include <unistd.h> static int get_bootloader_message_mtd(struct bootloader_message *out, const Volume* v); @@ -188,30 +185,18 @@ static int get_bootloader_message_block(struct bootloader_message *out, static int set_bootloader_message_block(const struct bootloader_message *in, const Volume* v) { wait_for_device(v->blk_device); - int fd = open(v->blk_device, O_WRONLY | O_SYNC); - if (fd == -1) { + FILE* f = fopen(v->blk_device, "wb"); + if (f == NULL) { LOGE("Can't open %s\n(%s)\n", v->blk_device, strerror(errno)); return -1; } - size_t written = 0; - const uint8_t* start = reinterpret_cast<const uint8_t*>(in); - size_t total = sizeof(*in); - while (written < total) { - ssize_t wrote = TEMP_FAILURE_RETRY(write(fd, start + written, total - written)); - if (wrote == -1) { - LOGE("failed to write %" PRId64 " bytes: %s\n", - static_cast<off64_t>(written), strerror(errno)); - return -1; - } - written += wrote; - } - - if (fsync(fd) == -1) { - LOGE("failed to fsync \"%s\": %s\n", v->blk_device, strerror(errno)); + int count = fwrite(in, sizeof(*in), 1, f); + if (count != 1) { + LOGE("Failed writing %s\n(%s)\n", v->blk_device, strerror(errno)); return -1; } - if (close(fd) == -1) { - LOGE("failed to close %s: %s\n", v->blk_device, strerror(errno)); + if (fclose(f) != 0) { + LOGE("Failed closing %s\n(%s)\n", v->blk_device, strerror(errno)); return -1; } return 0; diff --git a/etc/init.rc b/etc/init.rc index b7759259d..427727768 100644 --- a/etc/init.rc +++ b/etc/init.rc @@ -2,6 +2,7 @@ import /init.recovery.${ro.hardware}.rc on early-init start ueventd + start healthd on init export PATH /sbin:/system/bin |