emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r113969: * callproc.c: Fix race that killed backgrou


From: Paul Eggert
Subject: [Emacs-diffs] trunk r113969: * callproc.c: Fix race that killed background processes.
Date: Wed, 21 Aug 2013 21:27:33 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 113969
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/15144
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Wed 2013-08-21 14:27:30 -0700
message:
  * callproc.c: Fix race that killed background processes.
  
  (call_process): New arg TEMPFILE_INDEX.  Callers changed.
  Record deleted process-id in critical section, not afterwards.
  Don't mistakenly kill process created by a call-process invocation
  that discards output and does not wait.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/callproc.c                 callproc.c-20091113204419-o5vbwnq5f7feedwu-248
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-08-21 07:02:45 +0000
+++ b/src/ChangeLog     2013-08-21 21:27:30 +0000
@@ -1,3 +1,11 @@
+2013-08-21  Paul Eggert  <address@hidden>
+
+       * callproc.c: Fix race that killed background processes (Bug#15144).
+       (call_process): New arg TEMPFILE_INDEX.  Callers changed.
+       Record deleted process-id in critical section, not afterwards.
+       Don't mistakenly kill process created by a call-process invocation
+       that discards output and does not wait.
+
 2013-08-21  Dmitry Antipov  <address@hidden>
 
        Fix compilation with GC_MARK_STACK == GC_USE_GCPROS_AS_BEFORE

=== modified file 'src/callproc.c'
--- a/src/callproc.c    2013-08-12 07:12:07 +0000
+++ b/src/callproc.c    2013-08-21 21:27:30 +0000
@@ -102,7 +102,7 @@
     CALLPROC_FDS
   };
 
-static Lisp_Object call_process (ptrdiff_t, Lisp_Object *, int);
+static Lisp_Object call_process (ptrdiff_t, Lisp_Object *, int, ptrdiff_t);
 
 /* Block SIGCHLD.  */
 
@@ -248,14 +248,20 @@
     report_file_error ("Opening process input file", infile);
   record_unwind_protect_int (close_file_unwind, filefd);
   UNGCPRO;
-  return unbind_to (count, call_process (nargs, args, filefd));
+  return unbind_to (count, call_process (nargs, args, filefd, -1));
 }
 
 /* Like Fcall_process (NARGS, ARGS), except use FILEFD as the input file.
+
+   If TEMPFILE_INDEX is nonnegative, it is the specpdl index of an
+   unwinder that is intended to remove the input temporary file; in
+   this case NARGS must be at least 2 and ARGS[1] is the file's name.
+
    At entry, the specpdl stack top entry must be close_file_unwind (FILEFD).  
*/
 
 static Lisp_Object
-call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd)
+call_process (ptrdiff_t nargs, Lisp_Object *args, int filefd,
+             ptrdiff_t tempfile_index)
 {
   Lisp_Object buffer, current_dir, path;
   bool display_p;
@@ -661,7 +667,22 @@
   child_errno = errno;
 
   if (pid > 0)
-    synch_process_pid = pid;
+    {
+      synch_process_pid = pid;
+
+      if (INTEGERP (buffer))
+       {
+         if (tempfile_index < 0)
+           record_deleted_pid (pid, Qnil);
+         else
+           {
+             eassert (1 < nargs);
+             record_deleted_pid (pid, args[1]);
+             clear_unwind_protect (tempfile_index);
+           }
+         synch_process_pid = 0;
+       }
+    }
 
   unblock_child_signal ();
   unblock_input ();
@@ -1030,7 +1051,7 @@
 usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY 
&rest ARGS)  */)
   (ptrdiff_t nargs, Lisp_Object *args)
 {
-  struct gcpro gcpro1, gcpro2;
+  struct gcpro gcpro1;
   Lisp_Object infile, val;
   ptrdiff_t count = SPECPDL_INDEX ();
   Lisp_Object start = args[0];
@@ -1061,8 +1082,7 @@
       record_unwind_protect_int (close_file_unwind, fd);
     }
 
-  val = infile;
-  GCPRO2 (infile, val);
+  GCPRO1 (infile);
 
   if (nargs > 3 && !NILP (args[3]))
     Fdelete_region (start, end);
@@ -1079,16 +1099,7 @@
     }
   args[1] = infile;
 
-  val = call_process (nargs, args, fd);
-
-  if (!empty_input && 4 < nargs
-      && (INTEGERP (CONSP (args[4]) ? XCAR (args[4]) : args[4])))
-    {
-      record_deleted_pid (synch_process_pid, infile);
-      synch_process_pid = 0;
-      clear_unwind_protect (count);
-    }
-
+  val = call_process (nargs, args, fd, empty_input ? -1 : count);
   RETURN_UNGCPRO (unbind_to (count, val));
 }
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]