Make apk_install more portable
This commit is contained in:
parent
bdea796121
commit
109891d668
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user