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
This commit is contained in:
Andreas Köhler 2007-04-25 18:25:34 +00:00
parent 39a9165290
commit 27595e43a6

View File

@ -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)