1
0
Fork 0

startup: Optionally run (and exit with) a command

Treat the first non-option as a command, and any others as its CLI
arguments. Run the command with those arguments; communicate its exit
status (if nonzero); and exit with it. Document this added functionality
in the manpage and usage description.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1981
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1982>
This commit is contained in:
Mark 2021-10-05 21:34:16 -05:00
parent 64ff1f20f8
commit 8e1a125f70
2 changed files with 50 additions and 1 deletions

View file

@ -19,7 +19,7 @@
MUTTER \- Clutter based compositing GTK2 Window Manager
.SH SYNOPSIS
.B mutter
[\-\-display=\fIDISPLAY\fP] [\-\-replace] [\-\-sm\-client\-id=\fIID\fP] [\-\-sm\-disable] [\-\-sm\-save\-file=\fIFILENAME\fP] [\-\-version] [\-\-help]
[\-\-display=\fIDISPLAY\fP] [\-\-replace] [\-\-sm\-client\-id=\fIID\fP] [\-\-sm\-disable] [\-\-sm\-save\-file=\fIFILENAME\fP] [\-\-version] [\-\-help] [[\-\-] command [argument...]]
.SH DESCRIPTION
This manual page documents briefly
.B mutter\fP.

View file

@ -39,7 +39,33 @@ print_version (const gchar *option_name,
exit (0);
}
static void
command_exited_cb (GPid command_pid,
int status,
gpointer user_data)
{
MetaContext *context = user_data;
g_spawn_close_pid (command_pid);
if (status)
{
GError *error;
error = g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
"The command exited with a nonzero status: %d\n",
status);
meta_context_terminate_with_error (context, error);
}
else
{
meta_context_terminate (context);
}
}
static const char *plugin = "libdefault";
static char **argv_ignored = NULL;
GOptionEntry mutter_options[] = {
{
@ -54,6 +80,12 @@ GOptionEntry mutter_options[] = {
N_("Mutter plugin to use"),
"PLUGIN",
},
{
G_OPTION_REMAINING,
.arg = G_OPTION_ARG_STRING_ARRAY,
&argv_ignored,
.arg_description = "[[--] COMMAND [ARGUMENT…]]"
},
{ NULL }
};
@ -120,6 +152,23 @@ main (int argc, char **argv)
}
meta_context_notify_ready (context);
if (argv_ignored)
{
GPid command_pid;
g_auto (GStrv) command_argv = NULL;
command_argv = g_steal_pointer (&argv_ignored);
if (!g_spawn_async (NULL, command_argv, NULL,
G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
NULL, NULL, &command_pid, &error))
{
g_printerr ("Failed to run the command: %s", error->message);
return EXIT_FAILURE;
}
g_child_watch_add (command_pid, command_exited_cb, context);
}
if (!meta_context_run_main_loop (context, &error))
{