Skip to content
Snippets Groups Projects
Commit 0241a714 authored by Simon McVittie's avatar Simon McVittie
Browse files

adverb, wrap: Implement --exit-with-parent


-wrap eventually replaces itself with bubblewrap. If the bubblewrap
process is killed, we want the adverb command to be terminated, passing
the termination signal on to its own child process.

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent a3139d69
No related branches found
No related tags found
No related merge requests found
...@@ -46,6 +46,7 @@ ...@@ -46,6 +46,7 @@
static GPtrArray *global_locks = NULL; static GPtrArray *global_locks = NULL;
static GArray *global_pass_fds = NULL; static GArray *global_pass_fds = NULL;
static gboolean opt_create = FALSE; static gboolean opt_create = FALSE;
static gboolean opt_exit_with_parent = FALSE;
static gboolean opt_generate_locales = FALSE; static gboolean opt_generate_locales = FALSE;
static gboolean opt_subreaper = FALSE; static gboolean opt_subreaper = FALSE;
static double opt_terminate_idle_timeout = 0.0; static double opt_terminate_idle_timeout = 0.0;
...@@ -344,6 +345,16 @@ static GOptionEntry options[] = ...@@ -344,6 +345,16 @@ static GOptionEntry options[] =
"Don't create subsequent nonexistent lock files [default].", "Don't create subsequent nonexistent lock files [default].",
NULL }, 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', { "generate-locales", '\0',
G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_generate_locales, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_generate_locales,
"Attempt to generate any missing locales.", NULL }, "Attempt to generate any missing locales.", NULL },
...@@ -525,6 +536,18 @@ main (int argc, ...@@ -525,6 +536,18 @@ main (int argc,
command_and_args = argv + 1; 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) if ((opt_subreaper || opt_terminate_timeout >= 0)
&& prctl (PR_SET_CHILD_SUBREAPER, 1, 0, 0, 0) != 0) && prctl (PR_SET_CHILD_SUBREAPER, 1, 0, 0, 0) != 0)
{ {
......
...@@ -1464,27 +1464,24 @@ main (int argc, ...@@ -1464,27 +1464,24 @@ main (int argc,
opt_terminate_timeout); 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 not using a runtime, the adverb in the container has the if (adverb_in_container == NULL)
* same path as outside */ adverb_in_container = g_build_filename (tools_dir,
if (adverb_in_container == NULL) "pressure-vessel-adverb",
adverb_in_container = g_build_filename (tools_dir, NULL);
"pressure-vessel-adverb",
NULL);
flatpak_bwrap_add_args (bwrap, flatpak_bwrap_add_args (bwrap,
adverb_in_container, adverb_in_container,
"--subreaper", "--exit-with-parent",
NULL); "--subreaper",
NULL);
if (opt_verbose) if (opt_verbose)
flatpak_bwrap_add_arg (bwrap, "--verbose"); flatpak_bwrap_add_arg (bwrap, "--verbose");
flatpak_bwrap_append_bwrap (bwrap, adverb_args); flatpak_bwrap_append_bwrap (bwrap, adverb_args);
flatpak_bwrap_add_arg (bwrap, "--"); flatpak_bwrap_add_arg (bwrap, "--");
}
/* else just run the wrapped command directly */
g_debug ("Adding wrapped command..."); g_debug ("Adding wrapped command...");
flatpak_bwrap_append_args (bwrap, wrapped_command->argv); flatpak_bwrap_append_args (bwrap, wrapped_command->argv);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment