From 2a71afc50779f2b0cd13ea48762af348c396ad2b Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 12 Jan 2017 10:02:23 -0500 Subject: [PATCH] trivial-httpd: Daemonize better I was trying to debug `test-pull-c`, and typing `Ctrl-C` in gdb ended up sending `SIGINT` to trivial-httpd as well, killing it. Daemonize a bit more properly to avoid this. I also followed the standard `/dev/null` guidelines. Closes: #643 Approved by: jlebon --- src/ostree/ostree-trivial-httpd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ostree/ostree-trivial-httpd.c b/src/ostree/ostree-trivial-httpd.c index ef297af6..ddcb2fc0 100644 --- a/src/ostree/ostree-trivial-httpd.c +++ b/src/ostree/ostree-trivial-httpd.c @@ -30,6 +30,7 @@ #include "otutil.h" #include +#include #include #include #include @@ -597,9 +598,12 @@ run (int argc, char **argv, GCancellable *cancellable, GError **error) goto out; } /* Child, continue */ + if (setsid () < 0) + err (1, "setsid"); /* Daemonising: close stdout/stderr so $() et al work on us */ - fclose (stdout); - fclose (stdin); + freopen("/dev/null", "r", stdin); + freopen("/dev/null", "w", stdout); + freopen("/dev/null", "w", stderr); } else {