aboutsummaryrefslogtreecommitdiffstats
path: root/src/w32proc.c
diff options
context:
space:
mode:
authorPaul Eggert2012-12-03 13:42:12 -0800
committerPaul Eggert2012-12-03 13:42:12 -0800
commitbb5f74ee84398a56435baa2ef15e12d8a35e5e03 (patch)
tree4bb59aacd4d69b873154ce576e51fe8efe345150 /src/w32proc.c
parentbc9dbce6ee527ded152682c98f5f82e42c33dde9 (diff)
downloademacs-bb5f74ee84398a56435baa2ef15e12d8a35e5e03.tar.gz
emacs-bb5f74ee84398a56435baa2ef15e12d8a35e5e03.zip
Don't let call-process be a zombie factory.
Fixing this bug required some cleanup of the signal-handling code. As a side effect, this change also fixes a longstanding rare race condition whereby Emacs could mistakenly kill unrelated processes, and it fixes a bug where a second C-g does not kill a recalcitrant synchronous process in GNU/Linux and similar platforms. The patch should also fix the last vestiges of Bug#9488, a bug which has mostly been fixed on the trunk by other changes. * callproc.c, process.h (synch_process_alive, synch_process_death) (synch_process_termsig, sync_process_retcode): Remove. All uses removed, to simplify analysis and so that less consing is done inside critical sections. * callproc.c (call_process_exited): Remove. All uses replaced with !synch_process_pid. * callproc.c (synch_process_pid, synch_process_fd): New static vars. These take the role of what used to be in unwind-protect arg. All uses changed. (block_child_signal, unblock_child_signal): New functions, to avoid races that could kill innocent-victim processes. (call_process_kill, call_process_cleanup, Fcall_process): Use them. (call_process_kill): Record killed processes as deleted, so that zombies do not clutter up the system. Do this inside a critical section, to avoid a race that would allow the clutter. (call_process_cleanup): Fix code so that the second C-g works again on common platforms such as GNU/Linux. (Fcall_process): Create the child process in a critical section, to fix a race condition. If creating an asynchronous process, record it as deleted so that zombies do not clutter up the system. Do unwind-protect for WINDOWSNT too, as that's simpler in the light of these changes. Omit unnecessary call to emacs_close before failure, as the unwind-protect code does that. * callproc.c (call_process_cleanup): * w32proc.c (waitpid): Simplify now that synch_process_alive is gone. * process.c (record_deleted_pid): New function, containing code refactored out of Fdelete_process. (Fdelete_process): Use it. (process_status_retrieved): Remove. All callers changed to use child_status_change. (record_child_status_change): Remove, folding its contents into ... (handle_child_signal): ... this signal handler. Now, this function is purely a handler for SIGCHLD, and is not called after a synchronous waitpid returns; the synchronous code is moved to wait_for_termination. There is no need to worry about reaping more than one child now. * sysdep.c (get_child_status, child_status_changed): New functions. (wait_for_termination): Now takes int * status and bool interruptible arguments, too. Do not record child status change; that's now the caller's responsibility. All callers changed. Reimplement in terms of get_child_status. (wait_for_termination_1, interruptible_wait_for_termination): Remove. All callers changed to use wait_for_termination. * syswait.h: Include <stdbool.h>, for bool. (record_child_status_change, interruptible_wait_for_termination): Remove decls. (record_deleted_pid, child_status_changed): New decls. (wait_for_termination): Adjust to API changes noted above. Fixes: debbugs:12980
Diffstat (limited to 'src/w32proc.c')
-rw-r--r--src/w32proc.c28
1 files changed, 1 insertions, 27 deletions
diff --git a/src/w32proc.c b/src/w32proc.c
index 9b111b40e36..87af8682390 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -1274,33 +1274,7 @@ waitpid (pid_t pid, int *status, int options)
1274#endif 1274#endif
1275 1275
1276 if (status) 1276 if (status)
1277 { 1277 *status = retval;
1278 *status = retval;
1279 }
1280 else if (synch_process_alive)
1281 {
1282 synch_process_alive = 0;
1283
1284 /* Report the status of the synchronous process. */
1285 if (WIFEXITED (retval))
1286 synch_process_retcode = WEXITSTATUS (retval);
1287 else if (WIFSIGNALED (retval))
1288 {
1289 int code = WTERMSIG (retval);
1290 const char *signame;
1291
1292 synchronize_system_messages_locale ();
1293 signame = strsignal (code);
1294
1295 if (signame == 0)
1296 signame = "unknown";
1297
1298 synch_process_death = signame;
1299 }
1300
1301 reap_subprocess (cp);
1302 }
1303
1304 reap_subprocess (cp); 1278 reap_subprocess (cp);
1305 1279
1306 return pid; 1280 return pid;