summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2017-06-18 00:32:14 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2017-06-18 00:32:14 +0200
commit739e9c3926abf269c65c1f9bf50fbe732b3f55d8 (patch)
tree16fde288faa5560bdafbda8d19f1df76729ae95e
parentf7e0065d61c788e2e3a80d6569150c54deb4099f (diff)
downloadaports-cache-739e9c3926abf269c65c1f9bf50fbe732b3f55d8.tar.bz2
aports-cache-739e9c3926abf269c65c1f9bf50fbe732b3f55d8.tar.xz
catch exit status of shell
-rw-r--r--aports-cache.c16
-rw-r--r--main.c6
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;
}
diff --git a/main.c b/main.c
index 23de13b..5af6663 100644
--- a/main.c
+++ b/main.c
@@ -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;
}