/** * gis_page_util_run_reformatter: * * Launches the reformatter, and arranges for the assistant to be hidden for * the duration of its runtime. @callback will be called when the reformatter * exits. * * There is no corresponding _finish() function because (at present) neither * caller actually cares about the result. */ void gis_page_util_run_reformatter (GisPage *page, GAsyncReadyCallback callback, gpointer user_data) { g_autoptr(GTask) task = g_task_new (page, NULL, callback, user_data); g_autoptr(GSubprocessLauncher) launcher = NULL; g_autoptr(GSubprocess) subprocess = NULL; const gchar *locale = setlocale (LC_MESSAGES, NULL); const gchar *command = "/usr/lib/eos-installer/gnome-image-installer"; g_autoptr(GError) error = NULL; launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE); g_subprocess_launcher_setenv (launcher, "LANG", locale, TRUE); subprocess = g_subprocess_launcher_spawn (launcher, &error, command, NULL); if (error) { on_reformatter_exited (task, g_steal_pointer (&error)); return; } gis_driver_hide_window (page->driver); g_subprocess_wait_check_async (subprocess, NULL, reformatter_exited_cb, g_steal_pointer (&task)); }
static TestClient * test_client_new (const char *id, MetaWindowClientType type, GError **error) { TestClient *client = g_new0 (TestClient, 1); GSubprocessLauncher *launcher; GSubprocess *subprocess; launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDIN_PIPE | G_SUBPROCESS_FLAGS_STDOUT_PIPE); g_assert (meta_is_wayland_compositor ()); MetaWaylandCompositor *compositor = meta_wayland_compositor_get_default (); g_subprocess_launcher_setenv (launcher, "WAYLAND_DISPLAY", meta_wayland_get_wayland_display_name (compositor), TRUE); g_subprocess_launcher_setenv (launcher, "DISPLAY", meta_wayland_get_xwayland_display_name (compositor), TRUE); subprocess = g_subprocess_launcher_spawn (launcher, error, test_client_path, "--client-id", id, type == META_WINDOW_CLIENT_TYPE_WAYLAND ? "--wayland" : NULL, NULL); g_object_unref (launcher); if (!subprocess) return NULL; client->type = type; client->id = g_strdup (id); client->cancellable = g_cancellable_new (); client->subprocess = subprocess; client->in = g_data_output_stream_new (g_subprocess_get_stdin_pipe (subprocess)); client->out = g_data_input_stream_new (g_subprocess_get_stdout_pipe (subprocess)); client->loop = g_main_loop_new (NULL, FALSE); if (client->type == META_WINDOW_CLIENT_TYPE_X11) client->waiter = async_waiter_new (); return client; }
static gboolean spawn_session (State *state, gboolean run_script, GCancellable *cancellable) { GSubprocessLauncher *launcher = NULL; GSubprocess *subprocess = NULL; GError *error = NULL; gboolean is_running = FALSE; const char *vt; g_debug ("Running X session"); launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_NONE); g_subprocess_launcher_setenv (launcher, "DISPLAY", state->display_name, TRUE); g_subprocess_launcher_setenv (launcher, "XAUTHORITY", state->auth_file, TRUE); g_subprocess_launcher_setenv (launcher, "DBUS_SESSION_BUS_ADDRESS", state->bus_address, TRUE); vt = g_getenv ("XDG_VTNR"); if (vt != NULL) { g_subprocess_launcher_setenv (launcher, "WINDOWPATH", vt, TRUE); } if (run_script) { subprocess = g_subprocess_launcher_spawn (launcher, &error, GDMCONFDIR "/Xsession", state->session_command, NULL); } else { int ret; char **argv; ret = g_shell_parse_argv (state->session_command, NULL, &argv, &error); if (!ret) { g_debug ("could not parse session arguments: %s", error->message); goto out; } subprocess = g_subprocess_launcher_spawnv (launcher, (const char * const *) argv, &error); g_strfreev (argv); } if (subprocess == NULL) { g_debug ("could not start session: %s", error->message); goto out; } state->session_subprocess = g_object_ref (subprocess); g_subprocess_wait_async (state->session_subprocess, cancellable, (GAsyncReadyCallback) on_session_finished, state); is_running = TRUE; out: g_clear_object (&subprocess); return is_running; }
gboolean meta_xwayland_start (MetaXWaylandManager *manager, struct wl_display *wl_display) { int xwayland_client_fd[2]; int displayfd[2]; gboolean started = FALSE; g_autoptr(GSubprocessLauncher) launcher = NULL; GSubprocessFlags flags; GSubprocess *proc; GError *error = NULL; if (!choose_xdisplay (manager)) goto out; /* We want xwayland to be a wayland client so we make a socketpair to setup a * wayland protocol connection. */ if (socketpair (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, xwayland_client_fd) < 0) { g_warning ("xwayland_client_fd socketpair failed\n"); goto out; } if (socketpair (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, displayfd) < 0) { g_warning ("displayfd socketpair failed\n"); goto out; } /* xwayland, please. */ flags = G_SUBPROCESS_FLAGS_NONE; if (getenv ("XWAYLAND_STFU")) { flags |= G_SUBPROCESS_FLAGS_STDOUT_SILENCE; flags |= G_SUBPROCESS_FLAGS_STDERR_SILENCE; } launcher = g_subprocess_launcher_new (flags); g_subprocess_launcher_take_fd (launcher, xwayland_client_fd[1], 3); g_subprocess_launcher_take_fd (launcher, manager->abstract_fd, 4); g_subprocess_launcher_take_fd (launcher, manager->unix_fd, 5); g_subprocess_launcher_take_fd (launcher, displayfd[1], 6); g_subprocess_launcher_setenv (launcher, "WAYLAND_SOCKET", "3", TRUE); proc = g_subprocess_launcher_spawn (launcher, &error, XWAYLAND_PATH, manager->display_name, "-rootless", "-noreset", "-listen", "4", "-listen", "5", "-displayfd", "6", NULL); if (!proc) { g_error ("Failed to spawn Xwayland: %s", error->message); goto out; } g_subprocess_wait_async (proc, NULL, xserver_died, NULL); g_unix_fd_add (displayfd[0], G_IO_IN, on_displayfd_ready, manager); manager->client = wl_client_create (wl_display, xwayland_client_fd[0]); /* We need to run a mainloop until we know xwayland has a binding * for our xserver interface at which point we can assume it's * ready to start accepting connections. */ manager->init_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (manager->init_loop); started = TRUE; out: if (!started) { unlink (manager->lock_file); g_clear_pointer (&manager->lock_file, g_free); } return started; }
static gboolean launch_and_wait_variables_handler(gchar *handler_name, GHashTable *variables, GError **error) { g_autoptr(GSubprocessLauncher) handlelaunch = NULL; g_autoptr(GSubprocess) handleproc = NULL; GError *ierror = NULL; GHashTableIter iter; gchar *key = NULL; gchar *value = NULL; g_autoptr(GDataInputStream) datainstream = NULL; GInputStream *instream; gchar* outline; g_return_val_if_fail(handler_name, FALSE); g_return_val_if_fail(variables, FALSE); g_return_val_if_fail(error == NULL || *error == NULL, FALSE); handlelaunch = g_subprocess_launcher_new(G_SUBPROCESS_FLAGS_STDOUT_PIPE | G_SUBPROCESS_FLAGS_STDERR_MERGE); /* we copy the variables from the hashtable and add them to the subprocess environment */ g_hash_table_iter_init(&iter, variables); while (g_hash_table_iter_next(&iter, (gpointer*) &key, (gpointer*) &value)) { g_subprocess_launcher_setenv(handlelaunch, g_strdup(key), g_strdup(value), 1); } handleproc = g_subprocess_launcher_spawn( handlelaunch, &ierror, handler_name, NULL, NULL); if (!handleproc) { g_propagate_error(error, ierror); return FALSE; } instream = g_subprocess_get_stdout_pipe(handleproc); datainstream = g_data_input_stream_new(instream); do { outline = g_data_input_stream_read_line(datainstream, NULL, NULL, NULL); if (!outline) continue; if (g_str_has_prefix(outline, "RAUC_")) { gchar **split = g_strsplit(outline, "=", 2); if (g_strv_length(split) != 2) continue; g_hash_table_insert(variables, g_strdup(split[0]), g_strdup(split[1])); g_strfreev(split); } } while (outline); if (!g_subprocess_wait_check(handleproc, NULL, &ierror)) { g_propagate_error(error, ierror); return FALSE; } return TRUE; }