diff options
author | Natanael Copa <ncopa@alpinelinux.org> | 2017-06-18 00:32:14 +0200 |
---|---|---|
committer | Natanael Copa <ncopa@alpinelinux.org> | 2017-06-18 00:32:14 +0200 |
commit | 739e9c3926abf269c65c1f9bf50fbe732b3f55d8 (patch) | |
tree | 16fde288faa5560bdafbda8d19f1df76729ae95e /aports-cache.c | |
parent | f7e0065d61c788e2e3a80d6569150c54deb4099f (diff) | |
download | aports-cache-739e9c3926abf269c65c1f9bf50fbe732b3f55d8.tar.bz2 aports-cache-739e9c3926abf269c65c1f9bf50fbe732b3f55d8.tar.xz |
catch exit status of shell
Diffstat (limited to 'aports-cache.c')
-rw-r--r-- | aports-cache.c | 16 |
1 files changed, 12 insertions, 4 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; } |