]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix porting bug to older POSIXish platforms.
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 16 Jul 2013 07:05:41 +0000 (00:05 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 16 Jul 2013 07:05:41 +0000 (00:05 -0700)
* sysdep.c (emacs_pipe): New function, that implements
pipe2 (fd, O_CLOEXEC) even on hosts that lack O_CLOEXEC.
This should port better to CentOS 5 and to Mac OS X 10.6.
All calls to pipe2 changed.

Fixes: debbugs:14862
src/ChangeLog
src/alloc.c
src/callproc.c
src/emacs.c
src/lisp.h
src/nsterm.m
src/process.c
src/sysdep.c

index bc71a482a5de23a13a07e67d5d0d630f30d3183a..4d819413b42a5534aa42ef7af1e5060fa6d1c065 100644 (file)
@@ -1,5 +1,11 @@
 2013-07-16  Paul Eggert  <eggert@cs.ucla.edu>
 
+       Fix porting bug to older POSIXish platforms (Bug#14862).
+       * sysdep.c (emacs_pipe): New function, that implements
+       pipe2 (fd, O_CLOEXEC) even on hosts that lack O_CLOEXEC.
+       This should port better to CentOS 5 and to Mac OS X 10.6.
+       All calls to pipe2 changed.
+
        Prefer list1 (X) to Fcons (X, Qnil) when building lists.
        This makes the code easier to read and the executable a bit smaller.
        Do not replace all calls to Fcons that happen to create lists,
index b71cdb98d78b71a15c4fe84e66385bbb4c2b1d4a..b52e3de04942084abc410a361c236095a2ecd17e 100644 (file)
@@ -4741,7 +4741,7 @@ valid_pointer_p (void *p)
      Unfortunately, we cannot use NULL_DEVICE here, as emacs_write may
      not validate p in that case.  */
 
-  if (pipe2 (fd, O_CLOEXEC) == 0)
+  if (emacs_pipe (fd) == 0)
     {
       bool valid = emacs_write (fd[1], (char *) p, 16) == 16;
       emacs_close (fd[1]);
index 86d824668016dcb2968ad54e88b7c031503897b1..facaac60f2ad3f5b600147a36facbc776f574f4d 100644 (file)
@@ -524,7 +524,7 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS)  *
     {
 #ifndef MSDOS
       int fd[2];
-      if (pipe2 (fd, O_CLOEXEC) != 0)
+      if (emacs_pipe (fd) != 0)
        {
          int pipe_errno = errno;
          emacs_close (filefd);
index 7ad9739530b6d1ec33d701d61215ba0a381e7a7f..cf3a3c68932cb61eab1bfc18a1737ff41a93f91c 100644 (file)
@@ -985,7 +985,7 @@ main (int argc, char **argv)
         use a pipe for synchronization.  The parent waits for the child
         to close its end of the pipe (using `daemon-initialized')
         before exiting.  */
-      if (pipe2 (daemon_pipe, O_CLOEXEC) != 0)
+      if (emacs_pipe (daemon_pipe) != 0)
        {
          fprintf (stderr, "Cannot pipe!\n");
          exit (1);
index a54b2e0705744efb4a0771a2c2a42be2627953ef..6a551bb499d70ff1dba64f5aea6cc81c93eb67a3 100644 (file)
@@ -4094,6 +4094,7 @@ extern void init_random (void);
 extern void emacs_backtrace (int);
 extern _Noreturn void emacs_abort (void) NO_INLINE;
 extern int emacs_open (const char *, int, int);
+extern int emacs_pipe (int[2]);
 extern int emacs_close (int);
 extern ptrdiff_t emacs_read (int, char *, ptrdiff_t);
 extern ptrdiff_t emacs_write (int, const char *, ptrdiff_t);
index 5cbddd2a990ef9e95ccd3f0c7cfe2d3dc98327d4..340ef3b00a235bc6a04ebae994a0f6c1b34c2aed 100644 (file)
@@ -4142,7 +4142,7 @@ ns_term_init (Lisp_Object display_name)
 
   if (selfds[0] == -1)
     {
-      if (pipe2 (selfds, O_CLOEXEC) != 0)
+      if (emacs_pipe (selfds) != 0)
         {
           fprintf (stderr, "Failed to create pipe: %s\n",
                    emacs_strerror (errno));
index 94ffc37ffe74362f7c92ed25290c39cec71410d5..125a9389341bd6e88952a0e06294778fdd470326 100644 (file)
@@ -1651,11 +1651,11 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
   else
 #endif /* HAVE_PTYS */
     {
-      if (pipe2 (sv, O_CLOEXEC) != 0)
+      if (emacs_pipe (sv) != 0)
        report_file_error ("Creating pipe", Qnil);
       inchannel = sv[0];
       forkout = sv[1];
-      if (pipe2 (sv, O_CLOEXEC) != 0)
+      if (emacs_pipe (sv) != 0)
        {
          int pipe_errno = errno;
          emacs_close (inchannel);
@@ -1667,7 +1667,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
     }
 
 #ifndef WINDOWSNT
-  if (pipe2 (wait_child_setup, O_CLOEXEC) != 0)
+  if (emacs_pipe (wait_child_setup) != 0)
     report_file_error ("Creating pipe", Qnil);
 #endif
 
index f614d8bc5573b1592a9e5170f874ac814681b1f3..82f490e9538525e2bab8f534ca5e6383fe1026f5 100644 (file)
@@ -2201,6 +2201,20 @@ emacs_fopen (char const *file, char const *mode)
   return fd < 0 ? 0 : fdopen (fd, mode);
 }
 
+/* Create a pipe for Emacs use.  */
+
+int
+emacs_pipe (int fd[2])
+{
+  int result = pipe2 (fd, O_CLOEXEC);
+  if (! O_CLOEXEC && result == 0)
+    {
+      fcntl (fd[0], F_SETFD, FD_CLOEXEC);
+      fcntl (fd[1], F_SETFD, FD_CLOEXEC);
+    }
+  return result;
+}
+
 /* Approximate posix_close and POSIX_CLOSE_RESTART well enough for Emacs.
    For the background behind this mess, please see Austin Group defect 529
    <http://austingroupbugs.net/view.php?id=529>.  */