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,
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]);
{
#ifndef MSDOS
int fd[2];
- if (pipe2 (fd, O_CLOEXEC) != 0)
+ if (emacs_pipe (fd) != 0)
{
int pipe_errno = errno;
emacs_close (filefd);
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);
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);
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));
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);
}
#ifndef WINDOWSNT
- if (pipe2 (wait_child_setup, O_CLOEXEC) != 0)
+ if (emacs_pipe (wait_child_setup) != 0)
report_file_error ("Creating pipe", Qnil);
#endif
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>. */