From 27595e43a645bb08ccd17f2df570d11b868b97ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=B6hler?= Date: Wed, 25 Apr 2007 18:25:34 +0000 Subject: [PATCH] Fix gnc_spawn_process_async and gnc_detach_process. * Do not use g_child_watch_add if the spawn failed * Give the child process a chance to die before we kill it * Rather use g_message if file descriptors cannot be closed git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@15997 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/app-utils/guile-util.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/app-utils/guile-util.c b/src/app-utils/guile-util.c index 128cc0fc4b..476e14ad2d 100644 --- a/src/app-utils/guile-util.c +++ b/src/app-utils/guile-util.c @@ -1220,7 +1220,9 @@ gnc_spawn_process_async (GList *argl, const gboolean search_path) NULL, argv, NULL, flags, NULL, NULL, &proc->pid, &proc->fd_stdin, &proc->fd_stdout, &proc->fd_stderr, &error); - if (!retval) { + if (retval) { + g_child_watch_add (proc->pid, on_child_exit, proc); + } else { g_warning ("Could not spawn %s: %s", *argv ? *argv : "(null)", error->message ? error->message : "(null)"); g_free (proc); @@ -1228,8 +1230,6 @@ gnc_spawn_process_async (GList *argl, const gboolean search_path) } g_strfreev (argv); - g_child_watch_add (proc->pid, on_child_exit, proc); - return proc; } @@ -1261,25 +1261,29 @@ gnc_detach_process (Process *proc, const gboolean kill_it) errno = 0; close (proc->fd_stdin); if (errno) { - g_warning ("Close of childs stdin (%d) failed: %s", proc->fd_stdin, - g_strerror (errno)); + g_message ("Close of childs stdin (%d) failed: %s", proc->fd_stdin, + g_strerror (errno)); errno = 0; } close (proc->fd_stdout); if (errno) { - g_warning ("Close of childs stdout (%d) failed: %s", proc->fd_stdout, - g_strerror(errno)); + g_message ("Close of childs stdout (%d) failed: %s", proc->fd_stdout, + g_strerror(errno)); errno = 0; } close (proc->fd_stderr); if (errno) { - g_warning ("Close of childs stderr (%d) failed: %s", proc->fd_stderr, - g_strerror(errno)); + g_message ("Close of childs stderr (%d) failed: %s", proc->fd_stderr, + g_strerror(errno)); errno = 0; } - if (kill_it) - gnc_gpid_kill (proc->pid); + if (kill_it) { + /* give it a chance to die */ + g_main_context_iteration (NULL, FALSE); + if (!proc->dead) + gnc_gpid_kill (proc->pid); + } /* free if the process is both dead and detached */ if (!proc->dead)