Commit a285088c authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

removed SIGCHLD handler which used to call waitpid(-1,...) because this

2005-02-08  Michael Natterer  <mitch@gimp.org>

	* app/main.c: removed SIGCHLD handler which used to call
	waitpid(-1,...) because this breaks all waitpid(pid,...) calls
	in a non-deterministic way. Apparently it is possible to use both
	SIG_DFL *and* SA_RESTART (SA_RESTART being the original reason
	why the call to sigaction() was introduced).

	* app/plug-in/plug-in.c (plug_in_close): don't have a million
	subsequent if(plug_in->pid) blocks. Put everything into one big
	if(plug_in->pid) block instead. Call g_spawn_close_pid() on all
	platforms instead of using the Win32 CloseHandle().
parent 3d69ff11
2005-02-08 Michael Natterer <mitch@gimp.org>
* app/main.c: removed SIGCHLD handler which used to call
waitpid(-1,...) because this breaks all waitpid(pid,...) calls
in a non-deterministic way. Apparently it is possible to use both
SIG_DFL *and* SA_RESTART (SA_RESTART being the original reason
why the call to sigaction() was introduced).
* app/plug-in/plug-in.c (plug_in_close): don't have a million
subsequent if(plug_in->pid) blocks. Put everything into one big
if(plug_in->pid) block instead. Call g_spawn_close_pid() on all
platforms instead of using the Win32 CloseHandle().
2005-02-08 Michael Natterer <mitch@gimp.org>
* app/actions/file-actions.c
......
......@@ -85,7 +85,6 @@ static void gimp_show_version (void) G_GNUC_NORETURN;
#ifndef G_OS_WIN32
static void gimp_sigfatal_handler (gint sig_num) G_GNUC_NORETURN;
static void gimp_sigchld_handler (gint sig_num);
#endif
......@@ -402,8 +401,8 @@ gimp_init_signal_handlers (void)
/* Ignore SIGPIPE because plug_in.c handles broken pipes */
gimp_signal_private (SIGPIPE, SIG_IGN, 0);
/* Collect dead children */
gimp_signal_private (SIGCHLD, gimp_sigchld_handler, SA_RESTART);
/* Restart syscalls on SIGCHLD */
gimp_signal_private (SIGCHLD, SIG_DFL, SA_RESTART);
#endif /* G_OS_WIN32 */
}
......@@ -549,21 +548,4 @@ gimp_sigfatal_handler (gint sig_num)
}
}
/* gimp core signal handler for death-of-child signals */
static void
gimp_sigchld_handler (gint sig_num)
{
gint pid;
gint status;
while (TRUE)
{
pid = waitpid (WAIT_ANY, &status, WNOHANG);
if (pid <= 0)
break;
}
}
#endif /* ! G_OS_WIN32 */
......@@ -521,71 +521,74 @@ plug_in_close (PlugIn *plug_in,
plug_in->open = FALSE;
/* Ask the filter to exit gracefully */
if (kill_it && plug_in->pid)
if (plug_in->pid)
{
gp_quit_write (plug_in->my_write, plug_in);
/* Ask the filter to exit gracefully */
if (kill_it)
{
gp_quit_write (plug_in->my_write, plug_in);
/* give the plug-in some time (10 ms) */
/* give the plug-in some time (10 ms) */
#ifndef G_OS_WIN32
tv.tv_sec = 0;
tv.tv_usec = 10 * 1000;
select (0, NULL, NULL, NULL, &tv);
tv.tv_sec = 0;
tv.tv_usec = 10 * 1000;
select (0, NULL, NULL, NULL, &tv);
#else
Sleep (10);
Sleep (10);
#endif
}
}
/* If necessary, kill the filter. */
/* If necessary, kill the filter. */
#ifndef G_OS_WIN32
if (kill_it && plug_in->pid)
{
if (gimp->be_verbose)
g_print (_("Terminating plug-in: '%s'\n"),
gimp_filename_to_utf8 (plug_in->prog));
status = kill (plug_in->pid, SIGKILL);
}
/* Wait for the process to exit. This will happen
* immediately if it was just killed.
*/
if (plug_in->pid)
waitpid (plug_in->pid, &status, 0);
#else
if (kill_it && plug_in->pid)
{
/* Trying to avoid TerminateProcess (does mostly work).
* Otherwise some of our needed DLLs may get into an unstable state
* (see Win32 API docs).
*/
DWORD dwExitCode = STILL_ACTIVE;
DWORD dwTries = 10;
while ((STILL_ACTIVE == dwExitCode)
&& GetExitCodeProcess ((HANDLE) plug_in->pid, &dwExitCode)
&& (dwTries > 0))
{
Sleep(10);
dwTries--;
}
if (STILL_ACTIVE == dwExitCode)
{
if (kill_it)
{
if (gimp->be_verbose)
g_print (_("Terminating plug-in: '%s'\n"),
gimp_filename_to_utf8 (plug_in->prog));
TerminateProcess ((HANDLE) plug_in->pid, 0);
}
}
status = kill (plug_in->pid, SIGKILL);
}
/* FIXME: Wait for it like on Unix? */
/* Wait for the process to exit. This will happen
* immediately if it was just killed.
*/
waitpid (plug_in->pid, &status, 0);
/* Close handle which is no longer needed */
if (plug_in->pid)
CloseHandle ((HANDLE) plug_in->pid);
#endif
#else /* G_OS_WIN32 */
if (kill_it)
{
/* Trying to avoid TerminateProcess (does mostly work).
* Otherwise some of our needed DLLs may get into an
* unstable state (see Win32 API docs).
*/
DWORD dwExitCode = STILL_ACTIVE;
DWORD dwTries = 10;
while (dwExitCode == dwExitCode &&
GetExitCodeProcess ((HANDLE) plug_in->pid, &dwExitCode) &&
(dwTries > 0))
{
Sleep (10);
dwTries--;
}
if (dwExitCode == STILL_ACTIVE)
{
if (gimp->be_verbose)
g_print (_("Terminating plug-in: '%s'\n"),
gimp_filename_to_utf8 (plug_in->prog));
TerminateProcess ((HANDLE) plug_in->pid, 0);
}
}
#endif /* G_OS_WIN32 */
plug_in->pid = 0;
g_spawn_close_pid (plug_in->pid);
plug_in->pid = 0;
}
/* Remove the input handler. */
if (plug_in->input_id)
......
......@@ -521,71 +521,74 @@ plug_in_close (PlugIn *plug_in,
plug_in->open = FALSE;
/* Ask the filter to exit gracefully */
if (kill_it && plug_in->pid)
if (plug_in->pid)
{
gp_quit_write (plug_in->my_write, plug_in);
/* Ask the filter to exit gracefully */
if (kill_it)
{
gp_quit_write (plug_in->my_write, plug_in);
/* give the plug-in some time (10 ms) */
/* give the plug-in some time (10 ms) */
#ifndef G_OS_WIN32
tv.tv_sec = 0;
tv.tv_usec = 10 * 1000;
select (0, NULL, NULL, NULL, &tv);
tv.tv_sec = 0;
tv.tv_usec = 10 * 1000;
select (0, NULL, NULL, NULL, &tv);
#else
Sleep (10);
Sleep (10);
#endif
}
}
/* If necessary, kill the filter. */
/* If necessary, kill the filter. */
#ifndef G_OS_WIN32
if (kill_it && plug_in->pid)
{
if (gimp->be_verbose)
g_print (_("Terminating plug-in: '%s'\n"),
gimp_filename_to_utf8 (plug_in->prog));
status = kill (plug_in->pid, SIGKILL);
}
/* Wait for the process to exit. This will happen
* immediately if it was just killed.
*/
if (plug_in->pid)
waitpid (plug_in->pid, &status, 0);
#else
if (kill_it && plug_in->pid)
{
/* Trying to avoid TerminateProcess (does mostly work).
* Otherwise some of our needed DLLs may get into an unstable state
* (see Win32 API docs).
*/
DWORD dwExitCode = STILL_ACTIVE;
DWORD dwTries = 10;
while ((STILL_ACTIVE == dwExitCode)
&& GetExitCodeProcess ((HANDLE) plug_in->pid, &dwExitCode)
&& (dwTries > 0))
{
Sleep(10);
dwTries--;
}
if (STILL_ACTIVE == dwExitCode)
{
if (kill_it)
{
if (gimp->be_verbose)
g_print (_("Terminating plug-in: '%s'\n"),
gimp_filename_to_utf8 (plug_in->prog));
TerminateProcess ((HANDLE) plug_in->pid, 0);
}
}
status = kill (plug_in->pid, SIGKILL);
}
/* FIXME: Wait for it like on Unix? */
/* Wait for the process to exit. This will happen
* immediately if it was just killed.
*/
waitpid (plug_in->pid, &status, 0);
/* Close handle which is no longer needed */
if (plug_in->pid)
CloseHandle ((HANDLE) plug_in->pid);
#endif
#else /* G_OS_WIN32 */
if (kill_it)
{
/* Trying to avoid TerminateProcess (does mostly work).
* Otherwise some of our needed DLLs may get into an
* unstable state (see Win32 API docs).
*/
DWORD dwExitCode = STILL_ACTIVE;
DWORD dwTries = 10;
while (dwExitCode == dwExitCode &&
GetExitCodeProcess ((HANDLE) plug_in->pid, &dwExitCode) &&
(dwTries > 0))
{
Sleep (10);
dwTries--;
}
if (dwExitCode == STILL_ACTIVE)
{
if (gimp->be_verbose)
g_print (_("Terminating plug-in: '%s'\n"),
gimp_filename_to_utf8 (plug_in->prog));
TerminateProcess ((HANDLE) plug_in->pid, 0);
}
}
#endif /* G_OS_WIN32 */
plug_in->pid = 0;
g_spawn_close_pid (plug_in->pid);
plug_in->pid = 0;
}
/* Remove the input handler. */
if (plug_in->input_id)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment