diff options
| author | Paul Eggert | 2016-04-04 09:36:30 -0700 |
|---|---|---|
| committer | Paul Eggert | 2016-04-04 09:44:19 -0700 |
| commit | 6bccb19c9bef1189c8e853ff7cc16b889a3a57e3 (patch) | |
| tree | 9555d6605362ec0c452b343d549d2af3c983415d /src/sysdep.c | |
| parent | a11756ad0e2ee719266c0081150c20996cce8e0d (diff) | |
| download | emacs-6bccb19c9bef1189c8e853ff7cc16b889a3a57e3.tar.gz emacs-6bccb19c9bef1189c8e853ff7cc16b889a3a57e3.zip | |
Port redirect-debugging-output to non-GNU/Linux
Problem reported by Kylie McClain for musl in:
http://lists.gnu.org/archive/html/emacs-devel/2016-03/msg01592.html
* etc/DEBUG, etc/NEWS: Mention this.
* src/callproc.c (child_setup) [!MSDOS]:
* src/dispnew.c (init_display):
* src/emacs.c (main, Fdaemon_initialized):
* src/minibuf.c (read_minibuf_noninteractive):
* src/regex.c (xmalloc, xrealloc):
Prefer symbolic names like STDERR_FILENO to magic numbers like 2,
to make file-descriptor manipulation easier to follow.
* src/emacs.c (relocate_fd) [!WINDOWSNT]: Remove; no longer needed
now that we make sure stdin, stdout and stderr are open. All uses
removed.
(main): Make sure standard FDs are OK. Prefer symbolic names like
EXIT_FAILURE to magic numbers like 1. Use bool for boolean.
* src/lisp.h (init_standard_fds): New decl.
* src/print.c (WITH_REDIRECT_DEBUGGING_OUTPUT) [GNU_LINUX]:
Remove; no longer needed.
(Fredirect_debugging_output): Define on all platforms, not just
GNU/Linux. Redirect file descriptor, not stream, so that the code
works even if stderr is not an lvalue. Report an error if the
file arg is neither a string nor nil.
(syms_of_print): Always define redirect-debugging-output.
* src/sysdep.c (force_open, init_standard_fds): New functions.
Diffstat (limited to 'src/sysdep.c')
| -rw-r--r-- | src/sysdep.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/sysdep.c b/src/sysdep.c index 6154c1325d8..67c9bd90df7 100644 --- a/src/sysdep.c +++ b/src/sysdep.c | |||
| @@ -130,6 +130,35 @@ static const int baud_convert[] = | |||
| 130 | 1800, 2400, 4800, 9600, 19200, 38400 | 130 | 1800, 2400, 4800, 9600, 19200, 38400 |
| 131 | }; | 131 | }; |
| 132 | 132 | ||
| 133 | /* If FD is not already open, arrange for it to be open with FLAGS. */ | ||
| 134 | static void | ||
| 135 | force_open (int fd, int flags) | ||
| 136 | { | ||
| 137 | if (dup2 (fd, fd) < 0 && errno == EBADF) | ||
| 138 | { | ||
| 139 | int n = open (NULL_DEVICE, flags); | ||
| 140 | if (n < 0 || (fd != n && (dup2 (n, fd) < 0 || emacs_close (n) != 0))) | ||
| 141 | { | ||
| 142 | emacs_perror (NULL_DEVICE); | ||
| 143 | exit (EXIT_FAILURE); | ||
| 144 | } | ||
| 145 | } | ||
| 146 | } | ||
| 147 | |||
| 148 | /* Make sure stdin, stdout, and stderr are open to something, so that | ||
| 149 | their file descriptors are not hijacked by later system calls. */ | ||
| 150 | void | ||
| 151 | init_standard_fds (void) | ||
| 152 | { | ||
| 153 | /* Open stdin for *writing*, and stdout and stderr for *reading*. | ||
| 154 | That way, any attempt to do normal I/O will result in an error, | ||
| 155 | just as if the files were closed, and the file descriptors will | ||
| 156 | not be reused by later opens. */ | ||
| 157 | force_open (STDIN_FILENO, O_WRONLY); | ||
| 158 | force_open (STDOUT_FILENO, O_RDONLY); | ||
| 159 | force_open (STDERR_FILENO, O_RDONLY); | ||
| 160 | } | ||
| 161 | |||
| 133 | /* Return the current working directory. The result should be freed | 162 | /* Return the current working directory. The result should be freed |
| 134 | with 'free'. Return NULL on errors. */ | 163 | with 'free'. Return NULL on errors. */ |
| 135 | char * | 164 | char * |