diff --git a/src/adverb.c b/src/adverb.c index 76a2e848af5bd5b4410a470b32e7bf841127111e..13047fae51a889820f1765bfcf1dd9ce045d698f 100644 --- a/src/adverb.c +++ b/src/adverb.c @@ -46,6 +46,7 @@ static GPtrArray *global_locks = NULL; static GArray *global_pass_fds = NULL; static gboolean opt_create = FALSE; +static gboolean opt_exit_with_parent = FALSE; static gboolean opt_generate_locales = FALSE; static gboolean opt_subreaper = FALSE; static double opt_terminate_idle_timeout = 0.0; @@ -344,6 +345,16 @@ static GOptionEntry options[] = "Don't create subsequent nonexistent lock files [default].", NULL }, + { "exit-with-parent", '\0', + G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_exit_with_parent, + "Terminate child process and self with SIGTERM when parent process " + "exits.", + NULL }, + { "no-exit-with-parent", '\0', + G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &opt_exit_with_parent, + "Don't do anything special when parent process exits [default].", + NULL }, + { "generate-locales", '\0', G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_generate_locales, "Attempt to generate any missing locales.", NULL }, @@ -525,6 +536,18 @@ main (int argc, command_and_args = argv + 1; + if (opt_exit_with_parent) + { + g_debug ("Setting up to exit when parent does"); + + if (prctl (PR_SET_PDEATHSIG, SIGTERM, 0, 0, 0) != 0) + { + glnx_throw_errno_prefix (error, + "Unable to set parent death signal"); + goto out; + } + } + if ((opt_subreaper || opt_terminate_timeout >= 0) && prctl (PR_SET_CHILD_SUBREAPER, 1, 0, 0, 0) != 0) { diff --git a/src/wrap.c b/src/wrap.c index 764dfc261ba8129224a73a516c1ad1d410540fbf..d5a201dd9835a697379fcfae4ea65e3fdd5abe31 100644 --- a/src/wrap.c +++ b/src/wrap.c @@ -1464,27 +1464,24 @@ main (int argc, opt_terminate_timeout); } - if (adverb_args->argv->len > 0) - { - /* If not using a runtime, the adverb in the container has the - * same path as outside */ - if (adverb_in_container == NULL) - adverb_in_container = g_build_filename (tools_dir, - "pressure-vessel-adverb", - NULL); + /* If not using a runtime, the adverb in the container has the + * same path as outside */ + if (adverb_in_container == NULL) + adverb_in_container = g_build_filename (tools_dir, + "pressure-vessel-adverb", + NULL); - flatpak_bwrap_add_args (bwrap, - adverb_in_container, - "--subreaper", - NULL); + flatpak_bwrap_add_args (bwrap, + adverb_in_container, + "--exit-with-parent", + "--subreaper", + NULL); - if (opt_verbose) - flatpak_bwrap_add_arg (bwrap, "--verbose"); + if (opt_verbose) + flatpak_bwrap_add_arg (bwrap, "--verbose"); - flatpak_bwrap_append_bwrap (bwrap, adverb_args); - flatpak_bwrap_add_arg (bwrap, "--"); - } - /* else just run the wrapped command directly */ + flatpak_bwrap_append_bwrap (bwrap, adverb_args); + flatpak_bwrap_add_arg (bwrap, "--"); g_debug ("Adding wrapped command..."); flatpak_bwrap_append_args (bwrap, wrapped_command->argv);