diff options
Diffstat (limited to 'aports-cache.c')
-rw-r--r-- | aports-cache.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/aports-cache.c b/aports-cache.c index 02899e0..2132c70 100644 --- a/aports-cache.c +++ b/aports-cache.c @@ -21,7 +21,7 @@ #endif -static int spawn_shell_pipe(char *const argv[], pid_t *pid) +static int spawn_shell_pipe(char *const argv[], pid_t *pid, int outfd) { int pipefd[2]; posix_spawn_file_actions_t factions; @@ -36,6 +36,11 @@ static int spawn_shell_pipe(char *const argv[], pid_t *pid) goto err1; } + if (outfd >=0 && posix_spawn_file_actions_adddup2(&factions, outfd, STDOUT_FILENO) < 0) { + warn("posix_spawn_file_actions_adddup2"); + goto err2; + } + if (posix_spawn_file_actions_adddup2(&factions, pipefd[0], 0) < 0) { warn("posix_spawn_file_actions_adddup2"); goto err2; @@ -142,7 +147,6 @@ static int cache_refresh_or_check(int dirfd, const char *cachefile, int shellfd) if (dir == NULL) return -1; - debug_printf("dir opened\n"); while(1) { char buf[PATH_MAX]; struct stat apkbuild; @@ -192,11 +196,23 @@ int aports_cache_check(int dirfd, const char *cachefile) int aports_cache_refresh(int dirfd, const char *cachefile, char *const shell_argv[]) { pid_t shell_pid; - int shellfd = spawn_shell_pipe(shell_argv, &shell_pid); + int shellfd, outfd = -1; + + if (cachefile) { + outfd = open(cachefile, O_WRONLY | O_CREAT, 0660); + if (outfd < 0) { + warn("%s", cachefile); + return -1; + } + } + + shellfd = spawn_shell_pipe(shell_argv, &shell_pid, outfd); cache_refresh_or_check(dirfd, cachefile, shellfd); write(shellfd, "exit\n", 5); wait(NULL); + if (outfd >= 0) + close(outfd); return 0; } |