Fix deadlock bug when daemonizing

Closing stdin et. al breaks the assuption in spawnvem() that a newly
opened pipe is not one of the standard file descriptors. This lead
to stdout being closed in the child and so we got no output.
This commit is contained in:
Michael Spang 2009-09-08 18:50:33 -04:00
parent 80ac98531f
commit 5d8d866fca
2 changed files with 6 additions and 3 deletions

View File

@ -102,9 +102,9 @@ static void setup_daemon(void) {
setup_pidfile();
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
freopen("/dev/null", "r", stdin);
freopen("/dev/null", "w", stdout);
freopen("/dev/null", "w", stderr);
}
}

View File

@ -100,6 +100,9 @@ static void handle_op_message(uint32_t in_type, struct strbuf *in, struct strbuf
if (spawnvem(op->path, argv, envp, in, out, 0))
fatal("child %s failed", op->path);
if (!out->len)
fatal("no response from op");
free_env(envp);
}