diff options
-rw-r--r-- | aports-cache.c | 16 | ||||
-rw-r--r-- | main.c | 6 |
2 files changed, 15 insertions, 7 deletions
diff --git a/aports-cache.c b/aports-cache.c index 2132c70..8abfc96 100644 --- a/aports-cache.c +++ b/aports-cache.c @@ -197,6 +197,7 @@ int aports_cache_refresh(int dirfd, const char *cachefile, char *const shell_arg { pid_t shell_pid; int shellfd, outfd = -1; + int status; if (cachefile) { outfd = open(cachefile, O_WRONLY | O_CREAT, 0660); @@ -207,12 +208,19 @@ int aports_cache_refresh(int dirfd, const char *cachefile, char *const shell_arg } shellfd = spawn_shell_pipe(shell_argv, &shell_pid, outfd); + debug_printf("shell pid: %d\n", shell_pid); - cache_refresh_or_check(dirfd, cachefile, shellfd); - write(shellfd, "exit\n", 5); - wait(NULL); if (outfd >= 0) close(outfd); - return 0; + + cache_refresh_or_check(dirfd, cachefile, shellfd); + write(shellfd, "exit 0\n", 7); + + if (waitpid(shell_pid, &status, 0) < 0) { + warn("waitpid"); + return -1; + } + + return WIFEXITED(status) ? WEXITSTATUS(status) : -1; } @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) const char *cachefile = ".aports.cache.yaml"; char dirpath_buf[PATH_MAX]; char *dirpath = dirpath_buf; - int dirfd; + int dirfd, rc; char *shell_argv[] = {"/bin/sh", NULL}; @@ -83,9 +83,9 @@ int main(int argc, char *argv[]) if (verbose) printf("updating cache for %s\n", dirpath); - aports_cache_refresh(dirfd, cachefile, shell_argv); + rc = aports_cache_refresh(dirfd, cachefile, shell_argv); close(dirfd); - return 0; + return rc; } |