X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/d7306fe6b15ccdc49a066c05e5e86df8e005e859..a8101f663e6cbff953b67b8bef33bc0171818477:/src/callproc.c?ds=sidebyside
diff --git a/src/callproc.c b/src/callproc.c
index b1918b9cd5..de28ffa42e 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -1,6 +1,6 @@
/* Synchronous subprocess invocation for GNU Emacs.
Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1999, 2000, 2001,
- 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+ 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
Free Software Foundation, Inc.
This file is part of GNU Emacs.
@@ -25,10 +25,6 @@ along with GNU Emacs. If not, see . */
#include
#include
-#ifndef USE_CRT_DLL
-extern int errno;
-#endif
-
/* Define SIGCHLD as an alias for SIGCLD. */
#if !defined (SIGCHLD) && defined (SIGCLD)
@@ -43,7 +39,6 @@ extern int errno;
#include
#ifdef HAVE_FCNTL_H
-#define INCLUDED_FCNTL
#include
#endif
@@ -57,11 +52,9 @@ extern int errno;
#endif
#ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
-#define INCLUDED_FCNTL
#include
#include
#include
-#include
#endif /* MSDOS */
#ifndef O_RDONLY
@@ -96,7 +89,7 @@ extern char **environ;
#endif
#ifdef HAVE_SETPGID
-#if !defined (USG) || defined (BSD_PGRPS)
+#if !defined (USG)
#undef setpgrp
#define setpgrp setpgid
#endif
@@ -109,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;
@@ -124,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;
@@ -144,8 +135,7 @@ static int call_process_exited;
EXFUN (Fgetenv_internal, 2);
static Lisp_Object
-call_process_kill (fdpid)
- Lisp_Object fdpid;
+call_process_kill (Lisp_Object fdpid)
{
emacs_close (XFASTINT (Fcar (fdpid)));
EMACS_KILLPG (XFASTINT (Fcdr (fdpid)), SIGKILL);
@@ -154,8 +144,7 @@ call_process_kill (fdpid)
}
Lisp_Object
-call_process_cleanup (arg)
- Lisp_Object arg;
+call_process_cleanup (Lisp_Object arg)
{
Lisp_Object fdpid = Fcdr (arg);
#if defined (MSDOS)
@@ -224,9 +213,7 @@ and returns a numeric exit status or a signal description string.
If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.
usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
- (nargs, args)
- int nargs;
- register Lisp_Object *args;
+ (int nargs, register Lisp_Object *args)
{
Lisp_Object infile, buffer, current_dir, path;
int display_p;
@@ -586,7 +573,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
#ifdef HAVE_SETSID
setsid ();
#endif
-#if defined (USG) && !defined (BSD_PGRPS)
+#if defined (USG)
setpgrp ();
#else
setpgrp (pid, pid);
@@ -623,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;
}
@@ -784,10 +765,8 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
PT_BYTE + process_coding.produced);
carryover = process_coding.carryover_bytes;
if (carryover > 0)
- /* As CARRYOVER should not be that large, we had
- better avoid overhead of bcopy. */
- BCOPY_SHORT (process_coding.carryover, buf,
- process_coding.carryover_bytes);
+ memcpy (buf, process_coding.carryover,
+ process_coding.carryover_bytes);
}
}
@@ -824,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;
@@ -837,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);
@@ -855,8 +836,7 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
}
static Lisp_Object
-delete_temp_file (name)
- Lisp_Object name;
+delete_temp_file (Lisp_Object name)
{
/* Suppress jka-compr handling, etc. */
int count = SPECPDL_INDEX ();
@@ -889,9 +869,7 @@ and returns a numeric exit status or a signal description string.
If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.
usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &rest ARGS) */)
- (nargs, args)
- int nargs;
- register Lisp_Object *args;
+ (int nargs, register Lisp_Object *args)
{
struct gcpro gcpro1;
Lisp_Object filename_string;
@@ -926,7 +904,7 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
pattern = Fexpand_file_name (Vtemp_file_name_pattern, tmpdir);
tempfile = (char *) alloca (SBYTES (pattern) + 1);
- bcopy (SDATA (pattern), tempfile, SBYTES (pattern) + 1);
+ memcpy (tempfile, SDATA (pattern), SBYTES (pattern) + 1);
coding_systems = Qt;
#ifdef HAVE_MKSTEMP
@@ -1004,7 +982,9 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
RETURN_UNGCPRO (unbind_to (count, Fcall_process (nargs, args)));
}
-static int relocate_fd ();
+#ifndef WINDOWSNT
+static int relocate_fd (int fd, int minfd);
+#endif
static char **
add_env (char **env, char **new_env, char *string)
@@ -1059,11 +1039,7 @@ add_env (char **env, char **new_env, char *string)
executable directory by the parent. */
int
-child_setup (in, out, err, new_argv, set_pgrp, current_dir)
- int in, out, err;
- register char **new_argv;
- int set_pgrp;
- Lisp_Object current_dir;
+child_setup (int in, int out, int err, register char **new_argv, int set_pgrp, Lisp_Object current_dir)
{
char **env;
char *pwd_var;
@@ -1074,19 +1050,9 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
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
@@ -1113,8 +1079,8 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
pwd_var = (char *) alloca (i + 6);
#endif
temp = pwd_var + 4;
- bcopy ("PWD=", pwd_var, 4);
- bcopy (SDATA (current_dir), temp, i);
+ memcpy (pwd_var, "PWD=", 4);
+ memcpy (temp, SDATA (current_dir), i);
if (!IS_DIRECTORY_SEP (temp[i - 1])) temp[i++] = DIRECTORY_SEP;
temp[i] = 0;
@@ -1147,7 +1113,7 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
char **p, **q;
register int new_length;
Lisp_Object display = Qnil;
-
+
new_length = 0;
for (tem = Vprocess_environment;
@@ -1183,7 +1149,7 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
but with corrected value. */
if (egetenv ("PWD"))
*new_env++ = pwd_var;
-
+
if (STRINGP (display))
{
int vlen = strlen ("DISPLAY=") + strlen (SDATA (display)) + 1;
@@ -1213,7 +1179,7 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
}
}
-
+
#ifdef WINDOWSNT
prepare_standard_handles (in, out, err, handles);
set_process_dir (SDATA (current_dir));
@@ -1251,12 +1217,14 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
dup2 (out, 1);
dup2 (err, 2);
emacs_close (in);
- emacs_close (out);
- emacs_close (err);
+ if (out != in)
+ emacs_close (out);
+ if (err != in && err != out)
+ emacs_close (err);
#endif /* not MSDOS */
#endif /* not WINDOWSNT */
-#if defined(USG) && !defined(BSD_PGRPS)
+#if defined(USG)
#ifndef SETPGRP_RELEASES_CTTY
setpgrp (); /* No arguments but equivalent in this case */
#endif
@@ -1297,42 +1265,45 @@ child_setup (in, out, err, new_argv, set_pgrp, current_dir)
#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
-relocate_fd (fd, minfd)
- int fd, minfd;
+relocate_fd (int fd, int minfd)
{
if (fd >= 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 (var, varlen, value, valuelen, env)
- 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))
{
@@ -1343,7 +1314,7 @@ getenv_internal_1 (var, varlen, value, valuelen, env)
/* NT environment variables are case insensitive. */
&& ! strnicmp (SDATA (entry), var, varlen)
#else /* not WINDOWSNT */
- && ! bcmp (SDATA (entry), var, varlen)
+ && ! memcmp (SDATA (entry), var, varlen)
#endif /* not WINDOWSNT */
)
{
@@ -1366,12 +1337,8 @@ getenv_internal_1 (var, varlen, value, valuelen, env)
}
static int
-getenv_internal (var, varlen, value, valuelen, frame)
- 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,
@@ -1408,8 +1375,7 @@ This function searches `process-environment' for VARIABLE.
If optional parameter ENV is a list, then search this list instead of
`process-environment', and return t when encountering a negative entry
\(an entry for a variable with no value). */)
- (variable, env)
- Lisp_Object variable, env;
+ (Lisp_Object variable, Lisp_Object env)
{
char *value;
int valuelen;
@@ -1433,8 +1399,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 (var)
- char *var;
+egetenv (const char *var)
{
char *value;
int valuelen;
@@ -1449,7 +1414,7 @@ egetenv (var)
/* This is run before init_cmdargs. */
void
-init_callproc_1 ()
+init_callproc_1 (void)
{
char *data_dir = egetenv ("EMACSDATA");
char *doc_dir = egetenv ("EMACSDOC");
@@ -1471,7 +1436,7 @@ init_callproc_1 ()
/* This is run after init_cmdargs, when Vinstallation_directory is valid. */
void
-init_callproc ()
+init_callproc (void)
{
char *data_dir = egetenv ("EMACSDATA");
@@ -1560,16 +1525,15 @@ init_callproc ()
}
void
-set_initial_environment ()
+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);
@@ -1580,7 +1544,7 @@ set_initial_environment ()
}
void
-syms_of_callproc ()
+syms_of_callproc (void)
{
#ifdef DOS_NT
Qbuffer_file_type = intern ("buffer-file-type");