diff --git a/src/config.c b/src/config.c index cf7574dd..890a8baa 100644 --- a/src/config.c +++ b/src/config.c @@ -1178,6 +1178,7 @@ dobackup(const char *oldver) const char *root = hts_settings_get_root(); char errtxt[128]; const char **arg; + pid_t pid; int code; tvhinfo("config", "backup: migrating config from %s (running %s)", @@ -1211,10 +1212,10 @@ dobackup(const char *oldver) root, oldver); tvhinfo("config", "backup: running, output file %s", outfile); - if (spawnv(argv[0], (void *)argv, NULL, 1, 1)) { + if (spawnv(argv[0], (void *)argv, &pid, 1, 1)) { code = -ENOENT; } else { - while ((code = spawn_reap(errtxt, sizeof(errtxt))) == -EAGAIN) + while ((code = spawn_reap(pid, errtxt, sizeof(errtxt))) == -EAGAIN) usleep(20000); } diff --git a/src/spawn.c b/src/spawn.c index 6651f0b6..7c2b4710 100644 --- a/src/spawn.c +++ b/src/spawn.c @@ -230,13 +230,17 @@ find_exec ( const char *name, char *out, size_t len ) * Reap one child */ int -spawn_reap(char *stxt, size_t stxtlen) +spawn_reap(pid_t wpid, char *stxt, size_t stxtlen) { pid_t pid; int status, res; spawn_t *s; - pid = waitpid(-1, &status, WNOHANG); + pid = waitpid(wpid, &status, WNOHANG); + if(pid < 0 && ERRNO_AGAIN(errno)) + return -EAGAIN; + if(pid < 0) + return -errno; if(pid < 1) return -EAGAIN; @@ -279,7 +283,7 @@ spawn_reap(char *stxt, size_t stxtlen) static void spawn_reaper(void) { - while (spawn_reap(NULL, 0) != -EAGAIN) ; + while (spawn_reap(-1, NULL, 0) != -EAGAIN) ; } /** diff --git a/src/spawn.h b/src/spawn.h index 1554a749..124220ca 100644 --- a/src/spawn.h +++ b/src/spawn.h @@ -34,7 +34,7 @@ int spawn_and_give_stdout(const char *prog, char *argv[], char *envp[], int spawnv(const char *prog, char *argv[], pid_t *pid, int redir_stdout, int redir_stderr); -int spawn_reap(char *stxt, size_t stxtlen); +int spawn_reap(pid_t pid, char *stxt, size_t stxtlen); int spawn_kill(pid_t pid, int sig);