From 5d8d866fcaf50dbdf076a14b08fef0dece1fcbb9 Mon Sep 17 00:00:00 2001 From: Michael Spang Date: Tue, 8 Sep 2009 18:50:33 -0400 Subject: [PATCH] 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. --- src/dmaster.c | 6 +++--- src/dslave.c | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/dmaster.c b/src/dmaster.c index 45331c8..2e99c57 100644 --- a/src/dmaster.c +++ b/src/dmaster.c @@ -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); } } diff --git a/src/dslave.c b/src/dslave.c index dd373cf..4ae7624 100644 --- a/src/dslave.c +++ b/src/dslave.c @@ -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); }