X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/5842a27bbfb7efa6872824e501bc7ec98b631553..84c9ce0579c1f16670d15c486dc3ceeb3c103af1:/src/callproc.c diff --git a/src/callproc.c b/src/callproc.c index 674243f50d..8c1384df6a 100644 --- a/src/callproc.c +++ b/src/callproc.c @@ -102,8 +102,6 @@ Lisp_Object Vconfigure_info_directory, Vshared_game_score_directory; /* Pattern used by call-process-region to make temp files. */ static Lisp_Object Vtemp_file_name_pattern; -extern Lisp_Object Vtemporary_file_directory; - Lisp_Object Vshell_file_name; Lisp_Object Vprocess_environment, Vinitial_environment; @@ -117,7 +115,7 @@ Lisp_Object Qbuffer_file_type; int synch_process_alive; /* Nonzero => this is a string explaining death of synchronous subprocess. */ -char *synch_process_death; +const char *synch_process_death; /* Nonzero => this is the signal number that terminated the subprocess. */ int synch_process_termsig; @@ -612,12 +610,6 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) { if (fd[0] >= 0) emacs_close (fd[0]); -#ifndef subprocesses - /* If Emacs has been built with asynchronous subprocess support, - we don't need to do this, I think because it will then have - the facilities for handling SIGCHLD. */ - wait_without_blocking (); -#endif /* subprocesses */ return Qnil; } @@ -811,8 +803,10 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) make_number (total_read)); } +#ifndef MSDOS /* Wait for it to terminate, unless it already has. */ wait_for_termination (pid); +#endif immediate_quit = 0; @@ -824,7 +818,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */) if (synch_process_termsig) { - char *signame; + const char *signame; synchronize_system_messages_locale (); signame = strsignal (synch_process_termsig); @@ -988,7 +982,9 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r RETURN_UNGCPRO (unbind_to (count, Fcall_process (nargs, args))); } +#ifndef WINDOWSNT static int relocate_fd (int fd, int minfd); +#endif static char ** add_env (char **env, char **new_env, char *string) @@ -1054,19 +1050,9 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L int pid = getpid (); -#ifdef SET_EMACS_PRIORITY - { - extern EMACS_INT emacs_priority; - - if (emacs_priority < 0) - nice (- emacs_priority); - } -#endif - -#ifdef subprocesses /* Close Emacs's descriptors that this process should not have. */ close_process_descs (); -#endif + /* DOS_NT isn't in a vfork, so if we are in the middle of load-file, we will lose if we call close_load_descs here. */ #ifndef DOS_NT @@ -1127,7 +1113,7 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L char **p, **q; register int new_length; Lisp_Object display = Qnil; - + new_length = 0; for (tem = Vprocess_environment; @@ -1163,7 +1149,7 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L but with corrected value. */ if (egetenv ("PWD")) *new_env++ = pwd_var; - + if (STRINGP (display)) { int vlen = strlen ("DISPLAY=") + strlen (SDATA (display)) + 1; @@ -1193,7 +1179,7 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L } } - + #ifdef WINDOWSNT prepare_standard_handles (in, out, err, handles); set_process_dir (SDATA (current_dir)); @@ -1245,8 +1231,6 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L #else setpgrp (pid, pid); #endif /* USG */ - /* setpgrp_of_tty is incorrect here; it uses input_fd. */ - EMACS_SET_TTY_PGRP (0, &pid); #ifdef MSDOS pid = run_msdos_command (new_argv, pwd_var + 4, in, out, err, env); @@ -1265,6 +1249,9 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L report_file_error ("Spawning child process", Qnil); return cpid; #else /* not WINDOWSNT */ + /* setpgrp_of_tty is incorrect here; it uses input_fd. */ + EMACS_SET_TTY_PGRP (0, &pid); + /* execvp does not accept an environment arg so the only way to pass this environment is to set environ. Our caller is responsible for restoring the ambient value of environ. */ @@ -1279,6 +1266,7 @@ child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, L #endif /* not MSDOS */ } +#ifndef WINDOWSNT /* Move the file descriptor FD so that its number is not less than MINFD. If the file descriptor is moved at all, the original is freed. */ static int @@ -1288,27 +1276,35 @@ relocate_fd (int fd, int minfd) return fd; else { - int new = dup (fd); + int new; +#ifdef F_DUPFD + new = fcntl (fd, F_DUPFD, minfd); +#else + new = dup (fd); + if (new != -1) + /* Note that we hold the original FD open while we recurse, + to guarantee we'll get a new FD if we need it. */ + new = relocate_fd (new, minfd); +#endif if (new == -1) { - char *message1 = "Error while setting up child: "; - char *errmessage = strerror (errno); - char *message2 = "\n"; + const char *message1 = "Error while setting up child: "; + const char *errmessage = strerror (errno); + const char *message2 = "\n"; emacs_write (2, message1, strlen (message1)); emacs_write (2, errmessage, strlen (errmessage)); emacs_write (2, message2, strlen (message2)); _exit (1); } - /* Note that we hold the original FD open while we recurse, - to guarantee we'll get a new FD if we need it. */ - new = relocate_fd (new, minfd); emacs_close (fd); return new; } } +#endif /* not WINDOWSNT */ static int -getenv_internal_1 (char *var, int varlen, char **value, int *valuelen, Lisp_Object env) +getenv_internal_1 (const char *var, int varlen, char **value, int *valuelen, + Lisp_Object env) { for (; CONSP (env); env = XCDR (env)) { @@ -1342,7 +1338,8 @@ getenv_internal_1 (char *var, int varlen, char **value, int *valuelen, Lisp_Obje } static int -getenv_internal (char *var, int varlen, char **value, int *valuelen, Lisp_Object frame) +getenv_internal (const char *var, int varlen, char **value, int *valuelen, + Lisp_Object frame) { /* Try to find VAR in Vprocess_environment first. */ if (getenv_internal_1 (var, varlen, value, valuelen, @@ -1403,7 +1400,7 @@ If optional parameter ENV is a list, then search this list instead of /* A version of getenv that consults the Lisp environment lists, easily callable from C. */ char * -egetenv (char *var) +egetenv (const char *var) { char *value; int valuelen; @@ -1532,13 +1529,12 @@ void set_initial_environment (void) { register char **envp; -#ifndef CANNOT_DUMP - if (initialized) - { +#ifdef CANNOT_DUMP + Vprocess_environment = Qnil; #else - { - Vprocess_environment = Qnil; + if (initialized) #endif + { for (envp = environ; *envp; envp++) Vprocess_environment = Fcons (build_string (*envp), Vprocess_environment);