mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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:
parent
39a9165290
commit
27595e43a6
@ -1220,7 +1220,9 @@ gnc_spawn_process_async (GList *argl, const gboolean search_path)
|
|||||||
NULL, argv, NULL, flags, NULL, NULL, &proc->pid,
|
NULL, argv, NULL, flags, NULL, NULL, &proc->pid,
|
||||||
&proc->fd_stdin, &proc->fd_stdout, &proc->fd_stderr, &error);
|
&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)",
|
g_warning ("Could not spawn %s: %s", *argv ? *argv : "(null)",
|
||||||
error->message ? error->message : "(null)");
|
error->message ? error->message : "(null)");
|
||||||
g_free (proc);
|
g_free (proc);
|
||||||
@ -1228,8 +1230,6 @@ gnc_spawn_process_async (GList *argl, const gboolean search_path)
|
|||||||
}
|
}
|
||||||
g_strfreev (argv);
|
g_strfreev (argv);
|
||||||
|
|
||||||
g_child_watch_add (proc->pid, on_child_exit, proc);
|
|
||||||
|
|
||||||
return proc;
|
return proc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1261,25 +1261,29 @@ gnc_detach_process (Process *proc, const gboolean kill_it)
|
|||||||
errno = 0;
|
errno = 0;
|
||||||
close (proc->fd_stdin);
|
close (proc->fd_stdin);
|
||||||
if (errno) {
|
if (errno) {
|
||||||
g_warning ("Close of childs stdin (%d) failed: %s", proc->fd_stdin,
|
g_message ("Close of childs stdin (%d) failed: %s", proc->fd_stdin,
|
||||||
g_strerror (errno));
|
g_strerror (errno));
|
||||||
errno = 0;
|
errno = 0;
|
||||||
}
|
}
|
||||||
close (proc->fd_stdout);
|
close (proc->fd_stdout);
|
||||||
if (errno) {
|
if (errno) {
|
||||||
g_warning ("Close of childs stdout (%d) failed: %s", proc->fd_stdout,
|
g_message ("Close of childs stdout (%d) failed: %s", proc->fd_stdout,
|
||||||
g_strerror(errno));
|
g_strerror(errno));
|
||||||
errno = 0;
|
errno = 0;
|
||||||
}
|
}
|
||||||
close (proc->fd_stderr);
|
close (proc->fd_stderr);
|
||||||
if (errno) {
|
if (errno) {
|
||||||
g_warning ("Close of childs stderr (%d) failed: %s", proc->fd_stderr,
|
g_message ("Close of childs stderr (%d) failed: %s", proc->fd_stderr,
|
||||||
g_strerror(errno));
|
g_strerror(errno));
|
||||||
errno = 0;
|
errno = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kill_it)
|
if (kill_it) {
|
||||||
gnc_gpid_kill (proc->pid);
|
/* 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 */
|
/* free if the process is both dead and detached */
|
||||||
if (!proc->dead)
|
if (!proc->dead)
|
||||||
|
Loading…
Reference in New Issue
Block a user