1 From dee0200fa5dc4de064f288281ddd13199ba7fcde Mon Sep 17 00:00:00 2001
2 From: Nick Schermer <nick@xfce.org>
3 Date: Fri, 26 Apr 2013 19:46:29 +0200
4 Subject: Use the async spawn function of glib.
7 xfce4-session/xfsm-startup.c | 45 +++++++++++++++-----------------------------
8 1 file changed, 15 insertions(+), 30 deletions(-)
10 diff --git a/xfce4-session/xfsm-startup.c b/xfce4-session/xfsm-startup.c
11 index 911eec6..e43c53c 100644
12 --- a/xfce4-session/xfsm-startup.c
13 +++ b/xfce4-session/xfsm-startup.c
14 @@ -864,6 +864,7 @@ xfsm_startup_start_properties (XfsmProperties *properties,
16 const gchar *current_directory;
18 + GError *error = NULL;
20 /* release any possible old resources related to a previous startup */
21 xfsm_properties_set_default_child_watch (properties);
22 @@ -878,44 +879,28 @@ xfsm_startup_start_properties (XfsmProperties *properties,
24 current_directory = xfsm_properties_get_string (properties, SmCurrentDirectory);
26 - /* fork a new process for the application */
28 - /* vfork() doesn't allow you to do anything but call exec*() or _exit(),
29 - * so if we need to set the working directory, we can't use vfork() */
30 - if (current_directory == NULL)
36 - /* handle the child process */
38 + if (!g_spawn_async (current_directory,
40 + G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
44 - /* execute the application here */
45 - if (current_directory)
47 - if (chdir (current_directory))
48 - g_warning ("Unable to chdir to \"%s\": %s", current_directory, strerror (errno));
50 - execvp (argv[0], argv);
56 + g_warning ("Unable to launch \"%s\": %s",
57 + *argv, error->message);
58 + g_error_free (error);
61 - /* check if we failed to fork */
62 - if (G_UNLIKELY (pid < 0))
64 - /* tell the user that we failed to fork */
65 - perror ("Failed to fork new process");
69 + xfsm_verbose ("Launched command \"%s\" with PID %dn", *argv, (gint) pid);
73 properties->pid = pid;
75 /* set a watch to make sure the child doesn't quit before registering */
76 - child_watch_data = g_new (XfsmStartupData, 1);
77 + child_watch_data = g_new0 (XfsmStartupData, 1);
78 child_watch_data->manager = g_object_ref (manager);
79 child_watch_data->properties = properties;
80 g_child_watch_add_full (G_PRIORITY_LOW, properties->pid,