r15997 - gnucash/trunk/src/app-utils - Fix gnc_spawn_process_async and gnc_detach_process.
Andreas Köhler
andi5 at cvs.gnucash.org
Wed Apr 25 14:25:34 EDT 2007
Author: andi5
Date: 2007-04-25 14:25:34 -0400 (Wed, 25 Apr 2007)
New Revision: 15997
Trac: http://svn.gnucash.org/trac/changeset/15997
Modified:
gnucash/trunk/src/app-utils/guile-util.c
Log:
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
Modified: gnucash/trunk/src/app-utils/guile-util.c
===================================================================
--- gnucash/trunk/src/app-utils/guile-util.c 2007-04-25 18:22:05 UTC (rev 15996)
+++ gnucash/trunk/src/app-utils/guile-util.c 2007-04-25 18:25:34 UTC (rev 15997)
@@ -1220,7 +1220,9 @@
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 @@
}
g_strfreev (argv);
- g_child_watch_add (proc->pid, on_child_exit, proc);
-
return proc;
}
@@ -1261,25 +1261,29 @@
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)
More information about the gnucash-changes
mailing list