From d125028230c2ea56b2015c8ae457449d75c583bc Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Sun, 21 Jan 2007 14:36:37 +0000 Subject: Further fixes to g_spawn_async --- eglib/gmain.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'eglib/gmain.c') diff --git a/eglib/gmain.c b/eglib/gmain.c index c3c2ec9b..8132d635 100644 --- a/eglib/gmain.c +++ b/eglib/gmain.c @@ -682,10 +682,22 @@ static void exec_child(const gchar *working_directory, if (working_directory && chdir(working_directory) < 0) _exit(EXIT_FAILURE); + if (!(flags & G_SPAWN_LEAVE_DESCRIPTORS_OPEN)) { + int open_max, fd, ret; + + ret = 0; + open_max = sysconf(_SC_OPEN_MAX); + for (fd = 0; fd < open_max && ret == 0; fd++) + ret = fcntl(fd, F_SETFD, FD_CLOEXEC); + } + null = open("/dev/null", O_RDWR); - dup2(null, STDIN_FILENO); - dup2(null, STDOUT_FILENO); - dup2(null, STDERR_FILENO); + if (!(flags & G_SPAWN_CHILD_INHERITS_STDIN)) + dup2(null, STDIN_FILENO); + if (flags & G_SPAWN_STDOUT_TO_DEV_NULL) + dup2(null, STDOUT_FILENO); + if (flags & G_SPAWN_STDERR_TO_DEV_NULL) + dup2(null, STDERR_FILENO); if (null > 2) close(null); -- cgit