summaryrefslogtreecommitdiffstats
path: root/eglib
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2007-01-21 02:27:49 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2007-01-21 02:27:49 +0000
commit3240a5476f0c18bc0a30b0e0c5d995b55320ae7e (patch)
tree116a6b3fce32b8a0424b75e27ab52d91048fbeda /eglib
parent1c36a2a3227e07660d678b6844cf393aac005119 (diff)
First step of g_spawn_async implementation
Diffstat (limited to 'eglib')
-rw-r--r--eglib/gmain.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/eglib/gmain.c b/eglib/gmain.c
index 8da81b21..fc493878 100644
--- a/eglib/gmain.c
+++ b/eglib/gmain.c
@@ -671,6 +671,17 @@ static void init_child_pipe(void)
g_io_channel_unref(io);
}
+static void exec_child(const gchar *working_directory,
+ gchar **argv, gchar **envp,
+ GSpawnFlags flags)
+{
+ if (chdir(working_directory) < 0)
+ _exit(EXIT_FAILURE);
+
+ if (execv(argv[0], argv) < 0)
+ _exit(EXIT_FAILURE);
+}
+
gboolean g_spawn_async(const gchar *working_directory,
gchar **argv, gchar **envp,
GSpawnFlags flags,
@@ -679,9 +690,25 @@ gboolean g_spawn_async(const gchar *working_directory,
GPid *child_pid,
GError **error)
{
+ GPid pid;
+
if (child_watch_pipe[0] < 0)
init_child_pipe();
+ switch (pid = fork()) {
+ case -1:
+ return FALSE;
+ case 0:
+ if (child_setup)
+ child_setup(user_data);
+ exec_child(working_directory, argv, envp, flags);
+ break;
+ default:
+ if (child_pid)
+ *child_pid = pid;
+ return TRUE;
+ }
+
return FALSE;
}