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/callproc.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/callproc.c')
| -rw-r--r-- | src/callproc.c | 58 |
1 files changed, 3 insertions, 55 deletions
diff --git a/src/callproc.c b/src/callproc.c index db602f538c9..8578556b695 100644 --- a/src/callproc.c +++ b/src/callproc.c | |||
| @@ -1078,10 +1078,6 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r | |||
| 1078 | return unbind_to (count, val); | 1078 | return unbind_to (count, val); |
| 1079 | } | 1079 | } |
| 1080 | 1080 | ||
| 1081 | #ifndef WINDOWSNT | ||
| 1082 | static int relocate_fd (int fd, int minfd); | ||
| 1083 | #endif | ||
| 1084 | |||
| 1085 | static char ** | 1081 | static char ** |
| 1086 | add_env (char **env, char **new_env, char *string) | 1082 | add_env (char **env, char **new_env, char *string) |
| 1087 | { | 1083 | { |
| @@ -1310,37 +1306,14 @@ child_setup (int in, int out, int err, char **new_argv, bool set_pgrp, | |||
| 1310 | return cpid; | 1306 | return cpid; |
| 1311 | 1307 | ||
| 1312 | #else /* not WINDOWSNT */ | 1308 | #else /* not WINDOWSNT */ |
| 1313 | /* Make sure that in, out, and err are not actually already in | ||
| 1314 | descriptors zero, one, or two; this could happen if Emacs is | ||
| 1315 | started with its standard in, out, or error closed, as might | ||
| 1316 | happen under X. */ | ||
| 1317 | { | ||
| 1318 | int oin = in, oout = out; | ||
| 1319 | |||
| 1320 | /* We have to avoid relocating the same descriptor twice! */ | ||
| 1321 | |||
| 1322 | in = relocate_fd (in, 3); | ||
| 1323 | |||
| 1324 | if (out == oin) | ||
| 1325 | out = in; | ||
| 1326 | else | ||
| 1327 | out = relocate_fd (out, 3); | ||
| 1328 | |||
| 1329 | if (err == oin) | ||
| 1330 | err = in; | ||
| 1331 | else if (err == oout) | ||
| 1332 | err = out; | ||
| 1333 | else | ||
| 1334 | err = relocate_fd (err, 3); | ||
| 1335 | } | ||
| 1336 | 1309 | ||
| 1337 | #ifndef MSDOS | 1310 | #ifndef MSDOS |
| 1338 | /* Redirect file descriptors and clear the close-on-exec flag on the | 1311 | /* Redirect file descriptors and clear the close-on-exec flag on the |
| 1339 | redirected ones. IN, OUT, and ERR are close-on-exec so they | 1312 | redirected ones. IN, OUT, and ERR are close-on-exec so they |
| 1340 | need not be closed explicitly. */ | 1313 | need not be closed explicitly. */ |
| 1341 | dup2 (in, 0); | 1314 | dup2 (in, STDIN_FILENO); |
| 1342 | dup2 (out, 1); | 1315 | dup2 (out, STDOUT_FILENO); |
| 1343 | dup2 (err, 2); | 1316 | dup2 (err, STDERR_FILENO); |
| 1344 | 1317 | ||
| 1345 | setpgid (0, 0); | 1318 | setpgid (0, 0); |
| 1346 | tcsetpgrp (0, pid); | 1319 | tcsetpgrp (0, pid); |
| @@ -1359,31 +1332,6 @@ child_setup (int in, int out, int err, char **new_argv, bool set_pgrp, | |||
| 1359 | #endif /* not WINDOWSNT */ | 1332 | #endif /* not WINDOWSNT */ |
| 1360 | } | 1333 | } |
| 1361 | 1334 | ||
| 1362 | #ifndef WINDOWSNT | ||
| 1363 | /* Move the file descriptor FD so that its number is not less than MINFD. | ||
| 1364 | If the file descriptor is moved at all, the original is closed on MSDOS, | ||
| 1365 | but not elsewhere as the caller will close it anyway. */ | ||
| 1366 | static int | ||
| 1367 | relocate_fd (int fd, int minfd) | ||
| 1368 | { | ||
| 1369 | if (fd >= minfd) | ||
| 1370 | return fd; | ||
| 1371 | else | ||
| 1372 | { | ||
| 1373 | int new = fcntl (fd, F_DUPFD_CLOEXEC, minfd); | ||
| 1374 | if (new == -1) | ||
| 1375 | { | ||
| 1376 | emacs_perror ("while setting up child"); | ||
| 1377 | _exit (EXIT_CANCELED); | ||
| 1378 | } | ||
| 1379 | #ifdef MSDOS | ||
| 1380 | emacs_close (fd); | ||
| 1381 | #endif | ||
| 1382 | return new; | ||
| 1383 | } | ||
| 1384 | } | ||
| 1385 | #endif /* not WINDOWSNT */ | ||
| 1386 | |||
| 1387 | static bool | 1335 | static bool |
| 1388 | getenv_internal_1 (const char *var, ptrdiff_t varlen, char **value, | 1336 | getenv_internal_1 (const char *var, ptrdiff_t varlen, char **value, |
| 1389 | ptrdiff_t *valuelen, Lisp_Object env) | 1337 | ptrdiff_t *valuelen, Lisp_Object env) |