diff --git a/native/jni/daemon/bootstages.cpp b/native/jni/daemon/bootstages.cpp index 6b6d874f0..d40b319cd 100644 --- a/native/jni/daemon/bootstages.cpp +++ b/native/jni/daemon/bootstages.cpp @@ -561,17 +561,19 @@ static void install_apk(const char *apk) { setfilecon(apk, "u:object_r:" SEPOL_FILE_DOMAIN ":s0"); while (1) { sleep(5); - LOGD("apk_install: attempting to install APK"); - int apk_res = -1, pid; - pid = exec_command(true, &apk_res, nullptr, "/system/bin/pm", "install", "-r", apk, nullptr); + LOGD("apk_install: attempting to install APK\n"); + int fd = -1, pid; + pid = exec_command(true, &fd, nullptr, "/system/bin/sh", + "/system/bin/pm", "install", "-r", apk, nullptr); + FILE *res = fdopen(fd, "r"); if (pid != -1) { - int err = 0; - while (fdgets(buf, PATH_MAX, apk_res) > 0) { + bool err = false; + while (fgets(buf, PATH_MAX, res)) { LOGD("apk_install: %s", buf); err |= strstr(buf, "Error:") != nullptr; } waitpid(pid, nullptr, 0); - close(apk_res); + fclose(res); // Keep trying until pm is started if (err) continue; diff --git a/native/jni/utils/include/utils.h b/native/jni/utils/include/utils.h index 7cc967f8d..5dae25dfd 100644 --- a/native/jni/utils/include/utils.h +++ b/native/jni/utils/include/utils.h @@ -92,7 +92,6 @@ int xpoll(struct pollfd *fds, nfds_t nfds, int timeout); unsigned get_shell_uid(); unsigned get_system_uid(); unsigned get_radio_uid(); -ssize_t fdgets(char *buf, size_t size, int fd); int exec_command_sync(const char *argv0, ...); int fork_dont_care(); void gen_rand_str(char *buf, int len); diff --git a/native/jni/utils/misc.cpp b/native/jni/utils/misc.cpp index f06fdd542..2d5f7a35a 100644 --- a/native/jni/utils/misc.cpp +++ b/native/jni/utils/misc.cpp @@ -39,25 +39,6 @@ unsigned get_radio_uid() { return ppwd->pw_uid; } -/* Read a whole line from file descriptor */ -ssize_t fdgets(char *buf, const size_t size, int fd) { - ssize_t len = 0; - buf[0] = '\0'; - while (len < size - 1) { - int ret = read(fd, buf + len, 1); - if (ret < 0) - return -1; - if (ret == 0) - break; - if (buf[len] == '\0' || buf[len++] == '\n') { - buf[len] = '\0'; - break; - } - } - buf[size - 1] = '\0'; - return len; -} - int fork_dont_care() { int pid = xfork(); if (pid) {