]> code.delx.au - gnu-emacs/blobdiff - src/callproc.c
TODO update
[gnu-emacs] / src / callproc.c
index 2604d295f3edca9b6b711fbfbb07f4e789598f7d..c4177d5044c19d4d955f8a42ab8684eaa4388c80 100644 (file)
@@ -51,6 +51,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "process.h"
 #include "syssignal.h"
 #include "systty.h"
+#include "syswait.h"
 #include "blockinput.h"
 #include "frame.h"
 #include "termhooks.h"
@@ -63,13 +64,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "nsterm.h"
 #endif
 
-#ifdef HAVE_SETPGID
-#if !defined (USG)
-#undef setpgrp
-#define setpgrp setpgid
-#endif
-#endif
-
 /* Pattern used by call-process-region to make temp files.  */
 static Lisp_Object Vtemp_file_name_pattern;
 
@@ -422,28 +416,34 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS)  */)
     path = Fsubstring (path, make_number (2), Qnil);
 
   new_argv = SAFE_ALLOCA ((nargs > 4 ? nargs - 2 : 2) * sizeof *new_argv);
-  if (nargs > 4)
-    {
-      ptrdiff_t i;
-      struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
 
-      GCPRO5 (infile, buffer, current_dir, path, error_file);
-      argument_coding.dst_multibyte = 0;
-      for (i = 4; i < nargs; i++)
-       {
-         argument_coding.src_multibyte = STRING_MULTIBYTE (args[i]);
-         if (CODING_REQUIRE_ENCODING (&argument_coding))
-           /* We must encode this argument.  */
-           args[i] = encode_coding_string (&argument_coding, args[i], 1);
-       }
-      UNGCPRO;
-      for (i = 4; i < nargs; i++)
-       new_argv[i - 3] = SDATA (args[i]);
-      new_argv[i - 3] = 0;
-    }
-  else
-    new_argv[1] = 0;
-  new_argv[0] = SDATA (path);
+  {
+    struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
+
+    GCPRO5 (infile, buffer, current_dir, path, error_file);
+    if (nargs > 4)
+      {
+       ptrdiff_t i;
+
+       argument_coding.dst_multibyte = 0;
+       for (i = 4; i < nargs; i++)
+         {
+           argument_coding.src_multibyte = STRING_MULTIBYTE (args[i]);
+           if (CODING_REQUIRE_ENCODING (&argument_coding))
+             /* We must encode this argument.  */
+             args[i] = encode_coding_string (&argument_coding, args[i], 1);
+         }
+       for (i = 4; i < nargs; i++)
+         new_argv[i - 3] = SDATA (args[i]);
+       new_argv[i - 3] = 0;
+      }
+    else
+      new_argv[1] = 0;
+    if (STRING_MULTIBYTE (path))
+      path = ENCODE_FILE (path);
+    new_argv[0] = SDATA (path);
+    UNGCPRO;
+  }
 
 #ifdef MSDOS /* MW, July 1993 */
 
@@ -582,7 +582,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS)  */)
                       0, current_dir);
 #else  /* not WINDOWSNT */
 
-    BLOCK_INPUT;
+    block_input ();
 
     /* vfork, and prevent local vars from being clobbered by the vfork.  */
     {
@@ -617,24 +617,21 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS)  */)
       {
        if (fd[0] >= 0)
          emacs_close (fd[0]);
+
 #ifdef HAVE_SETSID
        setsid ();
-#endif
-#if defined (USG)
-       setpgrp ();
 #else
-       setpgrp (pid, pid);
-#endif /* USG */
+       setpgid (0, 0);
+#endif
 
-       /* GConf causes us to ignore SIGPIPE, make sure it is restored
-          in the child.  */
+       /* Emacs ignores SIGPIPE, but the child should not.  */
        signal (SIGPIPE, SIG_DFL);
 
        child_setup (filefd, fd1, fd_error, (char **) new_argv,
                     0, current_dir);
       }
 
-    UNBLOCK_INPUT;
+    unblock_input ();
 
 #endif /* not WINDOWSNT */
 
@@ -968,17 +965,18 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
   {
     USE_SAFE_ALLOCA;
     Lisp_Object pattern = Fexpand_file_name (Vtemp_file_name_pattern, tmpdir);
-    char *tempfile = SAFE_ALLOCA (SBYTES (pattern) + 1);
-    memcpy (tempfile, SDATA (pattern), SBYTES (pattern) + 1);
+    Lisp_Object encoded_tem = ENCODE_FILE (pattern);
+    char *tempfile = SAFE_ALLOCA (SBYTES (encoded_tem) + 1);
+    memcpy (tempfile, SDATA (encoded_tem), SBYTES (encoded_tem) + 1);
     coding_systems = Qt;
 
 #ifdef HAVE_MKSTEMP
     {
       int fd;
 
-      BLOCK_INPUT;
+      block_input ();
       fd = mkstemp (tempfile);
-      UNBLOCK_INPUT;
+      unblock_input ();
       if (fd == -1)
        report_file_error ("Failed to open temporary file",
                           Fcons (build_string (tempfile), Qnil));
@@ -986,7 +984,15 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
        close (fd);
     }
 #else
+    errno = 0;
     mktemp (tempfile);
+    if (!*tempfile)
+      {
+       if (!errno)
+         errno = EEXIST;
+       report_file_error ("Failed to open temporary file using pattern",
+                          Fcons (pattern, Qnil));
+      }
 #endif
 
     filename_string = build_string (tempfile);
@@ -1295,13 +1301,9 @@ child_setup (int in, int out, int err, char **new_argv, bool set_pgrp,
   if (err != in && err != out)
     emacs_close (err);
 
-#if defined (USG)
-#ifndef SETPGRP_RELEASES_CTTY
-  setpgrp ();                  /* No arguments but equivalent in this case */
+#if defined HAVE_SETPGID || ! (defined USG && defined SETPGRP_RELEASES_CTTY)
+  setpgid (pid, pid);
 #endif
-#else /* not USG */
-  setpgrp (pid, pid);
-#endif /* not USG */
 
   /* setpgrp_of_tty is incorrect here; it uses input_fd.  */
   tcsetpgrp (0, pid);