aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2013-07-16 00:05:41 -0700
committerPaul Eggert2013-07-16 00:05:41 -0700
commitc7ddc792b747fdf4fde822df0cf9c7b712be4219 (patch)
treede532bf42e3675fa093996b13ddb490cb8ec2f6c /src
parente6c005c5f8e39252fd11821b6452843bead2df6a (diff)
downloademacs-c7ddc792b747fdf4fde822df0cf9c7b712be4219.tar.gz
emacs-c7ddc792b747fdf4fde822df0cf9c7b712be4219.zip
Fix porting bug to older POSIXish platforms.
* 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
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog6
-rw-r--r--src/alloc.c2
-rw-r--r--src/callproc.c2
-rw-r--r--src/emacs.c2
-rw-r--r--src/lisp.h1
-rw-r--r--src/nsterm.m2
-rw-r--r--src/process.c6
-rw-r--r--src/sysdep.c14
8 files changed, 28 insertions, 7 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index bc71a482a5d..4d819413b42 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,11 @@
12013-07-16 Paul Eggert <eggert@cs.ucla.edu> 12013-07-16 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 Fix porting bug to older POSIXish platforms (Bug#14862).
4 * sysdep.c (emacs_pipe): New function, that implements
5 pipe2 (fd, O_CLOEXEC) even on hosts that lack O_CLOEXEC.
6 This should port better to CentOS 5 and to Mac OS X 10.6.
7 All calls to pipe2 changed.
8
3 Prefer list1 (X) to Fcons (X, Qnil) when building lists. 9 Prefer list1 (X) to Fcons (X, Qnil) when building lists.
4 This makes the code easier to read and the executable a bit smaller. 10 This makes the code easier to read and the executable a bit smaller.
5 Do not replace all calls to Fcons that happen to create lists, 11 Do not replace all calls to Fcons that happen to create lists,
diff --git a/src/alloc.c b/src/alloc.c
index b71cdb98d78..b52e3de0494 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -4741,7 +4741,7 @@ valid_pointer_p (void *p)
4741 Unfortunately, we cannot use NULL_DEVICE here, as emacs_write may 4741 Unfortunately, we cannot use NULL_DEVICE here, as emacs_write may
4742 not validate p in that case. */ 4742 not validate p in that case. */
4743 4743
4744 if (pipe2 (fd, O_CLOEXEC) == 0) 4744 if (emacs_pipe (fd) == 0)
4745 { 4745 {
4746 bool valid = emacs_write (fd[1], (char *) p, 16) == 16; 4746 bool valid = emacs_write (fd[1], (char *) p, 16) == 16;
4747 emacs_close (fd[1]); 4747 emacs_close (fd[1]);
diff --git a/src/callproc.c b/src/callproc.c
index 86d82466801..facaac60f2a 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -524,7 +524,7 @@ usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) *
524 { 524 {
525#ifndef MSDOS 525#ifndef MSDOS
526 int fd[2]; 526 int fd[2];
527 if (pipe2 (fd, O_CLOEXEC) != 0) 527 if (emacs_pipe (fd) != 0)
528 { 528 {
529 int pipe_errno = errno; 529 int pipe_errno = errno;
530 emacs_close (filefd); 530 emacs_close (filefd);
diff --git a/src/emacs.c b/src/emacs.c
index 7ad9739530b..cf3a3c68932 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -985,7 +985,7 @@ main (int argc, char **argv)
985 use a pipe for synchronization. The parent waits for the child 985 use a pipe for synchronization. The parent waits for the child
986 to close its end of the pipe (using `daemon-initialized') 986 to close its end of the pipe (using `daemon-initialized')
987 before exiting. */ 987 before exiting. */
988 if (pipe2 (daemon_pipe, O_CLOEXEC) != 0) 988 if (emacs_pipe (daemon_pipe) != 0)
989 { 989 {
990 fprintf (stderr, "Cannot pipe!\n"); 990 fprintf (stderr, "Cannot pipe!\n");
991 exit (1); 991 exit (1);
diff --git a/src/lisp.h b/src/lisp.h
index a54b2e07057..6a551bb499d 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4094,6 +4094,7 @@ extern void init_random (void);
4094extern void emacs_backtrace (int); 4094extern void emacs_backtrace (int);
4095extern _Noreturn void emacs_abort (void) NO_INLINE; 4095extern _Noreturn void emacs_abort (void) NO_INLINE;
4096extern int emacs_open (const char *, int, int); 4096extern int emacs_open (const char *, int, int);
4097extern int emacs_pipe (int[2]);
4097extern int emacs_close (int); 4098extern int emacs_close (int);
4098extern ptrdiff_t emacs_read (int, char *, ptrdiff_t); 4099extern ptrdiff_t emacs_read (int, char *, ptrdiff_t);
4099extern ptrdiff_t emacs_write (int, const char *, ptrdiff_t); 4100extern ptrdiff_t emacs_write (int, const char *, ptrdiff_t);
diff --git a/src/nsterm.m b/src/nsterm.m
index 5cbddd2a990..340ef3b00a2 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -4142,7 +4142,7 @@ ns_term_init (Lisp_Object display_name)
4142 4142
4143 if (selfds[0] == -1) 4143 if (selfds[0] == -1)
4144 { 4144 {
4145 if (pipe2 (selfds, O_CLOEXEC) != 0) 4145 if (emacs_pipe (selfds) != 0)
4146 { 4146 {
4147 fprintf (stderr, "Failed to create pipe: %s\n", 4147 fprintf (stderr, "Failed to create pipe: %s\n",
4148 emacs_strerror (errno)); 4148 emacs_strerror (errno));
diff --git a/src/process.c b/src/process.c
index 94ffc37ffe7..125a9389341 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1651,11 +1651,11 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1651 else 1651 else
1652#endif /* HAVE_PTYS */ 1652#endif /* HAVE_PTYS */
1653 { 1653 {
1654 if (pipe2 (sv, O_CLOEXEC) != 0) 1654 if (emacs_pipe (sv) != 0)
1655 report_file_error ("Creating pipe", Qnil); 1655 report_file_error ("Creating pipe", Qnil);
1656 inchannel = sv[0]; 1656 inchannel = sv[0];
1657 forkout = sv[1]; 1657 forkout = sv[1];
1658 if (pipe2 (sv, O_CLOEXEC) != 0) 1658 if (emacs_pipe (sv) != 0)
1659 { 1659 {
1660 int pipe_errno = errno; 1660 int pipe_errno = errno;
1661 emacs_close (inchannel); 1661 emacs_close (inchannel);
@@ -1667,7 +1667,7 @@ create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1667 } 1667 }
1668 1668
1669#ifndef WINDOWSNT 1669#ifndef WINDOWSNT
1670 if (pipe2 (wait_child_setup, O_CLOEXEC) != 0) 1670 if (emacs_pipe (wait_child_setup) != 0)
1671 report_file_error ("Creating pipe", Qnil); 1671 report_file_error ("Creating pipe", Qnil);
1672#endif 1672#endif
1673 1673
diff --git a/src/sysdep.c b/src/sysdep.c
index f614d8bc557..82f490e9538 100644
--- a/src/sysdep.c
+++ b/src/sysdep.c
@@ -2201,6 +2201,20 @@ emacs_fopen (char const *file, char const *mode)
2201 return fd < 0 ? 0 : fdopen (fd, mode); 2201 return fd < 0 ? 0 : fdopen (fd, mode);
2202} 2202}
2203 2203
2204/* Create a pipe for Emacs use. */
2205
2206int
2207emacs_pipe (int fd[2])
2208{
2209 int result = pipe2 (fd, O_CLOEXEC);
2210 if (! O_CLOEXEC && result == 0)
2211 {
2212 fcntl (fd[0], F_SETFD, FD_CLOEXEC);
2213 fcntl (fd[1], F_SETFD, FD_CLOEXEC);
2214 }
2215 return result;
2216}
2217
2204/* Approximate posix_close and POSIX_CLOSE_RESTART well enough for Emacs. 2218/* Approximate posix_close and POSIX_CLOSE_RESTART well enough for Emacs.
2205 For the background behind this mess, please see Austin Group defect 529 2219 For the background behind this mess, please see Austin Group defect 529
2206 <http://austingroupbugs.net/view.php?id=529>. */ 2220 <http://austingroupbugs.net/view.php?id=529>. */