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)",
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);
}
* 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;
static void
spawn_reaper(void)
{
- while (spawn_reap(NULL, 0) != -EAGAIN) ;
+ while (spawn_reap(-1, NULL, 0) != -EAGAIN) ;
}
/**
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);