summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2014-12-08 14:44:44 -0500
committerColin Walters <walters@verbum.org>2014-12-08 14:47:37 -0500
commitf7c926c5e9a4cff74e203c6bdd9b13f8cc027eed (patch)
tree080b34a3116a18046c3306e1aacb8c245718ce7e
parente908ebd9b399a22b1c5796315f8345c50d15d167 (diff)
downloadostree-f7c926c5e9a4cff74e203c6bdd9b13f8cc027eed.tar.gz
trivial-httpd: use PR_SET_PDEATHSIG by default
If we're not daemonizing, this is a useful way to ensure we go away if our parent does. https://bugzilla.gnome.org/show_bug.cgi?id=741264
-rw-r--r--src/ostree/ot-builtin-trivial-httpd.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/ostree/ot-builtin-trivial-httpd.c b/src/ostree/ot-builtin-trivial-httpd.c
index 31c541a4..f4e303c6 100644
--- a/src/ostree/ot-builtin-trivial-httpd.c
+++ b/src/ostree/ot-builtin-trivial-httpd.c
@@ -28,6 +28,8 @@
#include "otutil.h"
#include <sys/socket.h>
+#include <sys/prctl.h>
+#include <signal.h>
static char *opt_port_file = NULL;
static gboolean opt_daemonize;
@@ -390,7 +392,7 @@ ostree_builtin_trivial_httpd (int argc, char **argv, GCancellable *cancellable,
#if !SOUP_CHECK_VERSION(2, 48, 0)
soup_server_run_async (server);
#endif
-
+
if (opt_daemonize)
{
pid_t pid = fork();
@@ -411,6 +413,21 @@ ostree_builtin_trivial_httpd (int argc, char **argv, GCancellable *cancellable,
fclose (stdout);
fclose (stdin);
}
+ else
+ {
+ /* Since we're used for testing purposes, let's just do this by
+ * default. This ensures we exit when our parent does.
+ */
+ if (prctl (PR_SET_PDEATHSIG, SIGTERM) != 0)
+ {
+ int errsv = errno;
+ if (errsv != ENOSYS)
+ {
+ ot_util_set_error_from_errno (error, errsv);
+ goto out;
+ }
+ }
+ }
app->running = TRUE;
if (opt_autoexit)