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

launch: Implement --terminate option


This terminates the server instead of running a command.

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent dc52bfff
Branches
Tags
No related merge requests found
...@@ -19,6 +19,11 @@ pressure-vessel-launch - client to launch processes in a container ...@@ -19,6 +19,11 @@ pressure-vessel-launch - client to launch processes in a container
[**--**] [**--**]
*COMMAND* [*ARGUMENTS...*] *COMMAND* [*ARGUMENTS...*]
**pressure-vessel-launch**
[**--verbose**]
{**--bus-name** *NAME*|**--dbus-address** *ADDRESS*|**--socket** *SOCKET*}
**--terminate**
# DESCRIPTION # DESCRIPTION
**pressure-vessel-launch** connects to an `AF_UNIX` socket established **pressure-vessel-launch** connects to an `AF_UNIX` socket established
...@@ -70,6 +75,9 @@ as a subprocess of **pressure-vessel-launcher**. ...@@ -70,6 +75,9 @@ as a subprocess of **pressure-vessel-launcher**.
(standard input, standard output and standard error) are always (standard input, standard output and standard error) are always
forwarded. forwarded.
**--terminate**
: Instead of running a *COMMAND*, terminate the Launcher server.
**--verbose** **--verbose**
: Be more verbose. : Be more verbose.
...@@ -86,7 +94,8 @@ on standard error. ...@@ -86,7 +94,8 @@ on standard error.
The exit status is similar to **env**(1): The exit status is similar to **env**(1):
0 0
: The *COMMAND* exited successfully with status 0. : The *COMMAND* exited successfully with status 0,
or **--terminate** succeeded.
125 125
: Invalid arguments were given, or **pressure-vessel-launch** failed : Invalid arguments were given, or **pressure-vessel-launch** failed
......
...@@ -292,6 +292,7 @@ static gchar *opt_dbus_address = NULL; ...@@ -292,6 +292,7 @@ static gchar *opt_dbus_address = NULL;
static gchar *opt_directory = NULL; static gchar *opt_directory = NULL;
static gchar *opt_socket = NULL; static gchar *opt_socket = NULL;
static gchar **opt_envs = NULL; static gchar **opt_envs = NULL;
static gboolean opt_terminate = FALSE;
static gboolean opt_verbose = FALSE; static gboolean opt_verbose = FALSE;
static gboolean opt_version = FALSE; static gboolean opt_version = FALSE;
...@@ -323,6 +324,9 @@ static const GOptionEntry options[] = ...@@ -323,6 +324,9 @@ static const GOptionEntry options[] =
G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &opt_socket, G_OPTION_FLAG_NONE, G_OPTION_ARG_STRING, &opt_socket,
"Connect to a Launcher server listening on this AF_UNIX socket.", "Connect to a Launcher server listening on this AF_UNIX socket.",
"ABSPATH|@ABSTRACT" }, "ABSPATH|@ABSTRACT" },
{ "terminate", '\0',
G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_terminate,
"Terminate the Launcher server.", NULL },
{ "verbose", '\0', { "verbose", '\0',
G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_verbose, G_OPTION_FLAG_NONE, G_OPTION_ARG_NONE, &opt_verbose,
"Be more verbose.", NULL }, "Be more verbose.", NULL },
...@@ -408,17 +412,20 @@ main (int argc, ...@@ -408,17 +412,20 @@ main (int argc,
goto out; goto out;
} }
/* We have to block the signals we want to forward before we start any if (!opt_terminate)
* other thread, and in particular the GDBus worker thread, because
* the signal mask is per-thread. We need all threads to have the same
* mask, otherwise a thread that doesn't have the mask will receive
* process-directed signals, causing the whole process to exit. */
signal_source = forward_signals ();
if (signal_source == 0)
{ {
launch_exit_status = LAUNCH_EX_FAILED; /* We have to block the signals we want to forward before we start any
goto out; * other thread, and in particular the GDBus worker thread, because
* the signal mask is per-thread. We need all threads to have the same
* mask, otherwise a thread that doesn't have the mask will receive
* process-directed signals, causing the whole process to exit. */
signal_source = forward_signals ();
if (signal_source == 0)
{
launch_exit_status = LAUNCH_EX_FAILED;
goto out;
}
} }
pv_avoid_gvfs (); pv_avoid_gvfs ();
...@@ -435,7 +442,15 @@ main (int argc, ...@@ -435,7 +442,15 @@ main (int argc,
argc--; argc--;
} }
if (argc < 2) if (opt_terminate)
{
if (argc != 1)
{
glnx_throw (error, "--terminate cannot be combined with a COMMAND");
goto out;
}
}
else if (argc < 2)
{ {
glnx_throw (error, "Usage: %s [OPTIONS] COMMAND [ARG...]", glnx_throw (error, "Usage: %s [OPTIONS] COMMAND [ARG...]",
g_get_prgname ()); g_get_prgname ());
...@@ -534,6 +549,25 @@ main (int argc, ...@@ -534,6 +549,25 @@ main (int argc,
g_assert (bus_or_peer_connection != NULL); g_assert (bus_or_peer_connection != NULL);
if (opt_terminate)
{
reply = g_dbus_connection_call_sync (bus_or_peer_connection,
service_bus_name,
service_obj_path,
service_iface,
"Terminate",
g_variant_new ("()"),
G_VARIANT_TYPE ("()"),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL, error);
if (local_error != NULL)
g_dbus_error_strip_remote_error (local_error);
goto out;
}
g_dbus_connection_signal_subscribe (bus_or_peer_connection, g_dbus_connection_signal_subscribe (bus_or_peer_connection,
service_bus_name, /* NULL if p2p */ service_bus_name, /* NULL if p2p */
service_iface, service_iface,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment