annotate src/callproc.c @ 406:b8cc9ab3f761 r21-2-33

Import from CVS: tag r21-2-33
author cvs
date Mon, 13 Aug 2007 11:17:09 +0200
parents 74fd4e045ea6
children 501cfd01ee6d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Synchronous subprocess invocation for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 /* Synched up with: Mule 2.0, FSF 19.30. */
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 203
diff changeset
22 /* Partly sync'ed with 19.36.4 */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #include "commands.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #include "insdel.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 #include "lstream.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #include "process.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 #include "sysdep.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #include "window.h"
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 251
diff changeset
34 #ifdef FILE_CODING
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 251
diff changeset
35 #include "file-coding.h"
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
36 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 #include "systime.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #include "sysproc.h"
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 80
diff changeset
40 #include "sysfile.h" /* Always include after sysproc.h */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #include "syssignal.h" /* Always include before systty.h */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #include "systty.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 80
diff changeset
44 #ifdef WINDOWSNT
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 80
diff changeset
45 #define _P_NOWAIT 1 /* from process.h */
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
46 #include "nt.h"
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 80
diff changeset
47 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 #ifdef DOS_NT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 /* When we are starting external processes we need to know whether they
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 take binary input (no conversion) or text input (\n is converted to
284
558f606b08ae Import from CVS: tag r21-0b40
cvs
parents: 276
diff changeset
52 \r\n). Similarly for output: if newlines are written as \r\n then it's
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 text process output, otherwise it's binary. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 Lisp_Object Vbinary_process_input;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 Lisp_Object Vbinary_process_output;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 #endif /* DOS_NT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 Lisp_Object Vshell_file_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 /* The environment to pass to all subprocesses when they are started.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 This is in the semi-bogus format of ("VAR=VAL" "VAR2=VAL2" ... )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 Lisp_Object Vprocess_environment;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 /* True iff we are about to fork off a synchronous process or if we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 are waiting for it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 volatile int synch_process_alive;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 /* Nonzero => this is a string explaining death of synchronous subprocess. */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
70 const char *synch_process_death;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 /* If synch_process_death is zero,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 this is exit code of synchronous subprocess. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 int synch_process_retcode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 /* Clean up when exiting Fcall_process_internal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 On MSDOS, delete the temporary file on any kind of termination.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 On Unix, kill the process and any children on termination by signal. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 /* Nonzero if this is termination due to exit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 static int call_process_exited;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
83 Lisp_Object Vlisp_EXEC_SUFFIXES;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 call_process_kill (Lisp_Object fdpid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 Lisp_Object fd = Fcar (fdpid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 Lisp_Object pid = Fcdr (fdpid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 if (!NILP (fd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 close (XINT (fd));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 if (!NILP (pid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 EMACS_KILLPG (XINT (pid), SIGKILL);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
96
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 synch_process_alive = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 call_process_cleanup (Lisp_Object fdpid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
104 int fd = XINT (Fcar (fdpid));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 int pid = XINT (Fcdr (fdpid));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 if (!call_process_exited &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 EMACS_KILLPG (pid, SIGINT) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 record_unwind_protect (call_process_kill, fdpid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 /* #### "c-G" -- need non-consing Single-key-description */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 message ("Waiting for process to die...(type C-g again to kill it instantly)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
116 #ifdef WINDOWSNT
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
117 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
118 HANDLE pHandle = OpenProcess (PROCESS_ALL_ACCESS, 0, pid);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
119 if (pHandle == NULL)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
120 warn_when_safe (Qprocess, Qwarning,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
121 "cannot open process (PID %d) for cleanup", pid);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
122 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
123 wait_for_termination (pHandle);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
124 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
125 #else
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 213
diff changeset
126 wait_for_termination (pid);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
127 #endif
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 213
diff changeset
128
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 /* "Discard" the unwind protect. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 XCAR (fdpid) = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 XCDR (fdpid) = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 unbind_to (speccount, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 message ("Waiting for process to die... done");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 synch_process_alive = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 close (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 static Lisp_Object fork_error;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 #if 0 /* UNUSED */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 report_fork_error (char *string, Lisp_Object data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 {
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 120
diff changeset
146 Lisp_Object errstring = lisp_strerror (errno);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 fork_error = Fcons (build_string (string), Fcons (errstring, data));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 /* terminate this branch of the fork, without closing stdin/out/etc. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 _exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 #endif /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
406
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 398
diff changeset
155 DEFUN ("old-call-process-internal", Fold_call_process_internal, 1, MANY, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 Call PROGRAM synchronously in separate process, with coding-system specified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 Arguments are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 The program's input comes from file INFILE (nil means `/dev/null').
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 Insert output in BUFFER before point; t means current buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 nil for BUFFER means discard it; 0 means discard and don't wait.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 REAL-BUFFER says what to do with standard output, as above,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 while STDERR-FILE says what to do with standard error in the child.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 STDERR-FILE may be nil (discard standard error output),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 t (mix it with ordinary output), or a file name string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 Remaining arguments are strings passed as command arguments to PROGRAM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 If BUFFER is 0, `call-process' returns immediately with value nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 Otherwise it waits for PROGRAM to terminate and returns a numeric exit status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 or a signal description string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 If you quit, the process is killed with SIGINT, or SIGKILL if you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 quit again.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
176 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
177 (int nargs, Lisp_Object *args))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 Lisp_Object infile, buffer, current_dir, display, path;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 int fd[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 int filefd;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
183 #ifdef WINDOWSNT
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
184 HANDLE pHandle;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
185 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 int pid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 char buf[16384];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 char *bufptr = buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 int bufsize = 16384;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 int speccount = specpdl_depth ();
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 203
diff changeset
191 struct gcpro gcpro1, gcpro2;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
192 char **new_argv = alloca_array (char *, max (2, nargs - 2));
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
193
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 /* File to use for stderr in the child.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 t means use same as standard output. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 Lisp_Object error_file;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
197
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 CHECK_STRING (args[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 error_file = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
202 #if defined (NO_SUBPROCESSES)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 /* Without asynchronous processes we cannot have BUFFER == 0. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 if (nargs >= 3 && !INTP (args[2]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 error ("Operating system cannot handle asynchronous subprocesses");
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
206 #endif /* NO_SUBPROCESSES */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 /* Do this before building new_argv because GC in Lisp code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 * called by various filename-hacking routines might relocate strings */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
210 locate_file (Vexec_path, args[0], Vlisp_EXEC_SUFFIXES, &path, X_OK);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 /* Make sure that the child will be able to chdir to the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 buffer's current directory, or its unhandled equivalent. We
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 can't just have the child check for an error when it does the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 chdir, since it's in a vfork. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 {
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
217 struct gcpro ngcpro1, ngcpro2;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
218 /* Do this test before building new_argv because GC in Lisp code
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 * called by various filename-hacking routines might relocate strings */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 /* Make sure that the child will be able to chdir to the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 buffer's current directory. We can't just have the child check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 for an error when it does the chdir, since it's in a vfork. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
224 NGCPRO2 (current_dir, path); /* Caller gcprotects args[] */
367
a4f53d9b3154 Import from CVS: tag r21-1-13
cvs
parents: 365
diff changeset
225 current_dir = current_buffer->directory;
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 110
diff changeset
226 current_dir = Funhandled_file_name_directory (current_dir);
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 110
diff changeset
227 current_dir = expand_and_dir_to_file (current_dir, Qnil);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 #if 0
276
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
229 /* This is in FSF, but it breaks everything in the presence of
6330739388db Import from CVS: tag r21-0b36
cvs
parents: 274
diff changeset
230 ange-ftp-visited files, so away with it. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 if (NILP (Ffile_accessible_directory_p (current_dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 report_file_error ("Setting current directory",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 Fcons (current_buffer->directory, Qnil));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 #endif /* 0 */
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
235 NUNGCPRO;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 203
diff changeset
238 GCPRO1 (current_dir);
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 203
diff changeset
239
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 if (nargs >= 2 && ! NILP (args[1]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 {
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
242 struct gcpro ngcpro1;
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
243 NGCPRO1 (current_buffer->directory);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
244 infile = Fexpand_file_name (args[1], current_buffer->directory);
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
245 NUNGCPRO;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 CHECK_STRING (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 infile = build_string (NULL_DEVICE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 203
diff changeset
251 UNGCPRO;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 203
diff changeset
252
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 203
diff changeset
253 GCPRO2 (infile, current_dir); /* Fexpand_file_name might trash it */
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 110
diff changeset
254
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 if (nargs >= 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 buffer = args[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 /* If BUFFER is a list, its meaning is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (BUFFER-FOR-STDOUT FILE-FOR-STDERR). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 if (CONSP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 if (CONSP (XCDR (buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 Lisp_Object file_for_stderr = XCAR (XCDR (buffer));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 if (NILP (file_for_stderr) || EQ (Qt, file_for_stderr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 error_file = file_for_stderr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 error_file = Fexpand_file_name (file_for_stderr, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 buffer = XCAR (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 if (!(EQ (buffer, Qnil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 || EQ (buffer, Qt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 || ZEROP (buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
280 Lisp_Object spec_buffer = buffer;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 buffer = Fget_buffer (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 /* Mention the buffer name for a better error message. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 if (NILP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 CHECK_BUFFER (spec_buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 CHECK_BUFFER (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
288 else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 buffer = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 110
diff changeset
291 UNGCPRO;
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 110
diff changeset
292
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 display = ((nargs >= 4) ? args[3] : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
295 /* From here we assume we won't GC (unless an error is signaled). */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 REGISTER int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 for (i = 4; i < nargs; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 CHECK_STRING (args[i]);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
301 new_argv[i - 3] = (char *) XSTRING_DATA (args[i]);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
304 new_argv[max(nargs - 3,1)] = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
306 if (NILP (path))
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
307 report_file_error ("Searching for program", Fcons (args[0], Qnil));
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
308 new_argv[0] = (char *) XSTRING_DATA (path);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
309
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 215
diff changeset
310 filefd = open ((char *) XSTRING_DATA (infile), O_RDONLY | OPEN_BINARY, 0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 if (filefd < 0)
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
312 report_file_error ("Opening process input file", Fcons (infile, Qnil));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 if (INTP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 {
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 215
diff changeset
316 fd[1] = open (NULL_DEVICE, O_WRONLY | OPEN_BINARY, 0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 fd[0] = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 pipe (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 /* Replaced by close_process_descs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 set_exclusive_use (fd[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 }
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
327
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 {
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
329 /* child_setup must clobber environ in systems with true vfork.
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
330 Protect it from permanent change. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
331 REGISTER char **save_environ = environ;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
332 REGISTER int fd1 = fd[1];
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
333 int fd_error = fd1;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
334 char **env;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 env = environ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 /* Record that we're about to create a synchronous process. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 synch_process_alive = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 /* These vars record information from process termination.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 Clear them now before process can possibly terminate,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 to avoid timing error if process terminates soon. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 synch_process_death = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 synch_process_retcode = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 if (NILP (error_file))
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 215
diff changeset
348 fd_error = open (NULL_DEVICE, O_WRONLY | OPEN_BINARY);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 else if (STRINGP (error_file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
351 fd_error = open ((const char *) XSTRING_DATA (error_file),
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 #ifdef DOS_NT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT,
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
354 S_IREAD | S_IWRITE
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 #else /* not DOS_NT */
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 215
diff changeset
356 O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY,
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
357 CREAT_MODE
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 #endif /* not DOS_NT */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
359 );
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 if (fd_error < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 close (filefd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 close (fd[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 if (fd1 >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 close (fd1);
151
59463afc5666 Import from CVS: tag r20-3b2
cvs
parents: 120
diff changeset
368 report_file_error ("Cannot open", Fcons(error_file, Qnil));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 fork_error = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 #ifdef WINDOWSNT
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
373 pid = child_setup (filefd, fd1, fd_error, new_argv,
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
374 (char *) XSTRING_DATA (current_dir));
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
375 if (!INTP (buffer))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
376 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
377 /* OpenProcess() as soon after child_setup as possible. It's too
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
378 late once the process terminated. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
379 pHandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
380 #if 0
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
381 if (pHandle == NULL)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
382 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
383 /* #### seems to cause crash in unbind_to(...) below. APA */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
384 warn_when_safe (Qprocess, Qwarning,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
385 "cannot open process to wait for");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
386 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
387 #endif
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
388 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
389 /* Close STDERR into the parent process. We no longer need it. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
390 if (fd_error >= 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
391 close (fd_error);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 #else /* not WINDOWSNT */
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 159
diff changeset
393 pid = fork ();
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 if (pid == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 if (fd[0] >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 close (fd[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 /* This is necessary because some shells may attempt to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 access the current controlling terminal and will hang
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 if they are run in the background, as will be the case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 when XEmacs is started in the background. Martin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 Buchholz observed this problem running a subprocess
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 that used zsh to call gzip to uncompress an info
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 disconnect_controlling_terminal ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 child_setup (filefd, fd1, fd_error, new_argv,
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
408 (char *) XSTRING_DATA (current_dir));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 }
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 213
diff changeset
410 if (fd_error >= 0)
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 213
diff changeset
411 close (fd_error);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 #endif /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 environ = save_environ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 /* Close most of our fd's, but not fd[0]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 since we will use that to read input from. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 close (filefd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 if (fd1 >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 close (fd1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 if (!NILP (fork_error))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 signal_error (Qfile_error, fork_error);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
427 #ifndef WINDOWSNT
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 if (pid < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 if (fd[0] >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 close (fd[0]);
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 159
diff changeset
432 report_file_error ("Doing fork", Qnil);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
434 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 if (INTP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 if (fd[0] >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 close (fd[0]);
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
440 #if defined (NO_SUBPROCESSES)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 /* If Emacs has been built with asynchronous subprocess support,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 we don't need to do this, I think because it will then have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 the facilities for handling SIGCHLD. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 wait_without_blocking ();
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
445 #endif /* NO_SUBPROCESSES */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 int nread;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 int first = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 int total_read = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 Lisp_Object instream;
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
454 struct gcpro ngcpro1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 /* Enable sending signal if user quits below. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 call_process_exited = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 record_unwind_protect (call_process_cleanup,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 Fcons (make_int (fd[0]), make_int (pid)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 /* FSFmacs calls Fset_buffer() here. We don't have to because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 we can insert into buffers other than the current one. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 if (EQ (buffer, Qt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 XSETBUFFER (buffer, current_buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 instream = make_filedesc_input_stream (fd[0], 0, -1, LSTR_ALLOW_QUIT);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 251
diff changeset
467 #ifdef FILE_CODING
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
468 instream =
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
469 make_decoding_input_stream
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
470 (XLSTREAM (instream),
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 116
diff changeset
471 Fget_coding_system (Vcoding_system_for_read));
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
472 Lstream_set_character_mode (XLSTREAM (instream));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents: 251
diff changeset
473 #endif
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
474 NGCPRO1 (instream);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 /* Repeatedly read until we've filled as much as possible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 of the buffer size we have. But don't read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 less than 1024--save that for the next bufferfull. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 nread = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 while (nread < bufsize - 1024)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
485 ssize_t this_read
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 = Lstream_read (XLSTREAM (instream), bufptr + nread,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 bufsize - nread);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 if (this_read < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 goto give_up;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 if (this_read == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 goto give_up_1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 nread += this_read;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 give_up_1:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 /* Now NREAD is the total amount of data in the buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 if (nread == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
504 #if 0
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 209
diff changeset
505 #ifdef DOS_NT
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 209
diff changeset
506 /* Until we pull out of MULE things like
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 209
diff changeset
507 make_decoding_input_stream(), we do the following which is
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 209
diff changeset
508 less elegant. --marcpa */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
509 /* We did. -- kkm */
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 209
diff changeset
510 {
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 213
diff changeset
511 int lf_count = 0;
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 209
diff changeset
512 if (NILP (Vbinary_process_output)) {
215
1f0dabaa0855 Import from CVS: tag r20-4b6
cvs
parents: 213
diff changeset
513 nread = crlf_to_lf(nread, bufptr, &lf_count);
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 209
diff changeset
514 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 209
diff changeset
515 }
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 209
diff changeset
516 #endif
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
517 #endif
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 209
diff changeset
518
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 total_read += nread;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
520
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 if (!NILP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 buffer_insert_raw_string (XBUFFER (buffer), (Bufbyte *) bufptr,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 nread);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 /* Make the buffer bigger as we continue to read more data,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 but not past 64k. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 if (bufsize < 64 * 1024 && total_read > 32 * bufsize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 bufsize *= 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 bufptr = (char *) alloca (bufsize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 if (!NILP (display) && INTERACTIVE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 first = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 redisplay ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 give_up:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 Lstream_close (XLSTREAM (instream));
169
15872534500d Import from CVS: tag r20-3b11
cvs
parents: 167
diff changeset
541 NUNGCPRO;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 /* Wait for it to terminate, unless it already has. */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
545 #ifdef WINDOWSNT
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
546 wait_for_termination (pHandle);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
547 #else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 wait_for_termination (pid);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
549 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 /* Don't kill any children that the subprocess may have left behind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 when exiting. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 call_process_exited = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 unbind_to (speccount, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 if (synch_process_death)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 return build_string (synch_process_death);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 return make_int (synch_process_retcode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
564 /* Move the file descriptor FD so that its number is not less than MIN. *
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
565 The original file descriptor remains open. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
566 static int
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
567 relocate_fd (int fd, int min)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
568 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
569 if (fd >= min)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
570 return fd;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
571 else
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
572 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
573 int newfd = dup (fd);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
574 if (newfd == -1)
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
575 {
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
576 stderr_out ("Error while setting up child: %s\n",
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
577 strerror (errno));
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
578 _exit (1);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
579 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
580 return relocate_fd (newfd, min);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
581 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
582 }
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
583
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 /* This is the last thing run in a newly forked inferior
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 either synchronous or asynchronous.
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
586 Copy descriptors IN, OUT and ERR
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
587 as descriptors STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 Initialize inferior's priority, pgrp, connected dir and environment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 then exec another program based on new_argv.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 This function may change environ for the superior process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 Therefore, the superior process must save and restore the value
167
85ec50267440 Import from CVS: tag r20-3b10
cvs
parents: 159
diff changeset
593 of environ around the fork and the call to this function.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 ENV is the environment for the subprocess.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 XEmacs: We've removed the SET_PGRP argument because it's already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 done by the callers of child_setup.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 CURRENT_DIR is an elisp string giving the path of the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 directory the subprocess should have. Since we can't really signal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 a decent error from within the child, this should be verified as an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 executable directory by the parent. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 80
diff changeset
605 #ifdef WINDOWSNT
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 80
diff changeset
606 int
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 80
diff changeset
607 #else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 void
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 80
diff changeset
609 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 child_setup (int in, int out, int err, char **new_argv,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
611 const char *current_dir)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 char **env;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 char *pwd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 int cpid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 HANDLE handles[4];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 #endif /* WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 #ifdef SET_EMACS_PRIORITY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 if (emacs_priority != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 nice (- emacs_priority);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 259
diff changeset
625 #if !defined (NO_SUBPROCESSES) && !defined (WINDOWSNT)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 /* Close Emacs's descriptors that this process should not have. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 close_process_descs ();
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
628 #endif /* not NO_SUBPROCESSES */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 close_load_descs ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 /* Note that use of alloca is always safe here. It's obvious for systems
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 that do not have true vfork or that have true (stack) alloca.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 If using vfork and C_ALLOCA it is safe because that changes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 the superior's static variables as if the superior had done alloca
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 and will be cleaned up in the usual way. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 REGISTER int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 i = strlen (current_dir);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
640 pwd = alloca_array (char, i + 6);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 memcpy (pwd, "PWD=", 4);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 memcpy (pwd + 4, current_dir, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 i += 4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 if (!IS_DIRECTORY_SEP (pwd[i - 1]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 pwd[i++] = DIRECTORY_SEP;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 pwd[i] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 /* We can't signal an Elisp error here; we're in a vfork. Since
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 the callers check the current directory before forking, this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 should only return an error if the directory's permissions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 are changed between the check and this chdir, but we should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 at least check. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 if (chdir (pwd + 4) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 /* Don't report the chdir error, or ange-ftp.el doesn't work. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 /* (FSFmacs does _exit (errno) here.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 pwd = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 /* Strip trailing "/". Cretinous *[]&@$#^%@#$% Un*x */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 /* leave "//" (from FSF) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 while (i > 6 && IS_DIRECTORY_SEP (pwd[i - 1]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 pwd[--i] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 /* Set `env' to a vector of the strings in Vprocess_environment. */
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 384
diff changeset
669 /* + 2 to include PWD and terminating 0. */
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 384
diff changeset
670 env = alloca_array (char *, XINT (Flength (Vprocess_environment)) + 2);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 {
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 384
diff changeset
672 REGISTER Lisp_Object tail;
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 384
diff changeset
673 char **new_env = env;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 /* If we have a PWD envvar and we know the real current directory,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 pass one down, but with corrected value. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 if (pwd && getenv ("PWD"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 *new_env++ = pwd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 /* Copy the Vprocess_environment strings into new_env. */
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 384
diff changeset
681 for (tail = Vprocess_environment;
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 384
diff changeset
682 CONSP (tail) && STRINGP (XCAR (tail));
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 384
diff changeset
683 tail = XCDR (tail))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 char **ep = env;
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 384
diff changeset
686 char *envvar_external;
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 384
diff changeset
687
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
688 TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (tail),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
689 C_STRING_ALLOCA, envvar_external,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
690 Qfile_name);
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 384
diff changeset
691
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 384
diff changeset
692 /* See if envvar_external duplicates any string already in the env.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 If so, don't put it in.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 When an env var has multiple definitions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 we keep the definition that comes first in process-environment. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 for (; ep != new_env; ep++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 {
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 384
diff changeset
698 char *p = *ep, *q = envvar_external;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 if (*q == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 /* The string is malformed; might as well drop it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 goto duplicate;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 if (*q != *p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 if (*q == '=')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 goto duplicate;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 p++, q++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 }
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 384
diff changeset
711 if (pwd && !strncmp ("PWD=", envvar_external, 4))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 *new_env++ = pwd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 pwd = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 else
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 384
diff changeset
717 *new_env++ = envvar_external;
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 384
diff changeset
718
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 duplicate: ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 *new_env = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 }
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 384
diff changeset
723
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 prepare_standard_handles (in, out, err, handles);
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 203
diff changeset
726 set_process_dir (current_dir);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 #else /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 /* Make sure that in, out, and err are not actually already in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 descriptors zero, one, or two; this could happen if Emacs is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 started with its standard in, out, or error closed, as might
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 happen under X. */
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
732 in = relocate_fd (in, 3);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
733 out = relocate_fd (out, 3);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
734 err = relocate_fd (err, 3);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
736 /* Set the standard input/output channels of the new process. */
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
737 close (STDIN_FILENO);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
738 close (STDOUT_FILENO);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
739 close (STDERR_FILENO);
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 384
diff changeset
740
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
741 dup2 (in, STDIN_FILENO);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
742 dup2 (out, STDOUT_FILENO);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
743 dup2 (err, STDERR_FILENO);
386
4af0ddfb7c5b Import from CVS: tag r21-2-8
cvs
parents: 384
diff changeset
744
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 close (in);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 close (out);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 close (err);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 /* I can't think of any reason why child processes need any more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 than the standard 3 file descriptors. It would be cleaner to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 close just the ones that need to be, but the following brute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 force approach is certainly effective, and not too slow. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 int fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 for (fd=3; fd<=64; fd++)
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 375
diff changeset
756 close (fd);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 #endif /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 #ifdef vipc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 something missing here;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 #endif /* vipc */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 /* Spawn the child. (See ntproc.c:Spawnve). */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
766 cpid = spawnve (_P_NOWAIT, new_argv[0], (const char* const*)new_argv,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
767 (const char* const*)env);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 if (cpid == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 /* An error occurred while trying to spawn the process. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 report_file_error ("Spawning child process", Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 reset_standard_handles (in, out, err, handles);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 return cpid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 #else /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 /* execvp does not accept an environment arg so the only way
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 to pass this environment is to set environ. Our caller
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 is responsible for restoring the ambient value of environ. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 environ = env;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 execvp (new_argv[0], new_argv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779
375
a300bb07d72d Import from CVS: tag r21-2b3
cvs
parents: 371
diff changeset
780 stdout_out ("Can't exec program %s\n", new_argv[0]);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 _exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 #endif /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
786 getenv_internal (const Bufbyte *var,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 Bytecount varlen,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 Bufbyte **value,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 Bytecount *valuelen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 Lisp_Object scan;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 Lisp_Object entry = XCAR (scan);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 179
diff changeset
796
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 if (STRINGP (entry)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
798 && XSTRING_LENGTH (entry) > varlen
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
799 && XSTRING_BYTE (entry, varlen) == '='
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 /* NT environment variables are case insensitive. */
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
802 && ! memicmp (XSTRING_DATA (entry), var, varlen)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 #else /* not WINDOWSNT */
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
804 && ! memcmp (XSTRING_DATA (entry), var, varlen)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 #endif /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 {
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
808 *value = XSTRING_DATA (entry) + (varlen + 1);
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
809 *valuelen = XSTRING_LENGTH (entry) - (varlen + 1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
817 DEFUN ("getenv", Fgetenv, 1, 2, "sEnvironment variable: \np", /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 Return the value of environment variable VAR, as a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 VAR is a string, the name of the variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 When invoked interactively, prints the value in the echo area.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
821 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
822 (var, interactivep))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 Bufbyte *value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 Bytecount valuelen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 Lisp_Object v = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 CHECK_STRING (var);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 GCPRO1 (v);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
831 if (getenv_internal (XSTRING_DATA (var), XSTRING_LENGTH (var),
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 &value, &valuelen))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 v = make_string (value, valuelen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 if (!NILP (interactivep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 if (NILP (v))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
837 message ("%s not defined in environment", XSTRING_DATA (var));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 else
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
839 /* #### Should use Fprin1_to_string or Fprin1 to handle string
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
840 containing quotes correctly. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 message ("\"%s\"", value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 RETURN_UNGCPRO (v);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 /* A version of getenv that consults process_environment, easily
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 callable from C. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 char *
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
849 egetenv (const char *var)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 Bufbyte *value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 Bytecount valuelen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
854 if (getenv_internal ((const Bufbyte *) var, strlen (var), &value, &valuelen))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 return (char *) value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 init_callproc (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 {
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
867 /* jwz: always initialize Vprocess_environment, so that egetenv()
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
868 works in temacs. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 char **envp;
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
870 Vprocess_environment = Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 for (envp = environ; envp && *envp; envp++)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
872 Vprocess_environment =
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
873 Fcons (build_ext_string (*envp, Qfile_name), Vprocess_environment);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
876 {
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
877 /* Initialize shell-file-name from environment variables or best guess. */
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 203
diff changeset
878 #ifdef WINDOWSNT
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
879 const char *shell = egetenv ("COMSPEC");
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
880 if (!shell) shell = "\\WINNT\\system32\\cmd.exe";
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
881 #else /* not WINDOWSNT */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
882 const char *shell = egetenv ("SHELL");
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
883 if (!shell) shell = "/bin/sh";
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
884 #endif
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 284
diff changeset
885
384
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
886 Vshell_file_name = build_string (shell);
bbff43aa5eb7 Import from CVS: tag r21-2-7
cvs
parents: 380
diff changeset
887 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 set_process_environment (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 REGISTER char **envp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 Vprocess_environment = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 #ifndef CANNOT_DUMP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 if (initialized)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 for (envp = environ; *envp; envp++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 Vprocess_environment = Fcons (build_string (*envp),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 Vprocess_environment);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 #endif /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 syms_of_callproc (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 {
406
b8cc9ab3f761 Import from CVS: tag r21-2-33
cvs
parents: 398
diff changeset
909 DEFSUBR (Fold_call_process_internal);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
910 DEFSUBR (Fgetenv);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 vars_of_callproc (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 #ifdef DOS_NT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 DEFVAR_LISP ("binary-process-input", &Vbinary_process_input /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 *If non-nil then new subprocesses are assumed to take binary input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 Vbinary_process_input = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 DEFVAR_LISP ("binary-process-output", &Vbinary_process_output /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 *If non-nil then new subprocesses are assumed to produce binary output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 Vbinary_process_output = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 #endif /* DOS_NT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 DEFVAR_LISP ("shell-file-name", &Vshell_file_name /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 *File name to load inferior shells from.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 Initialized from the SHELL environment variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 DEFVAR_LISP ("process-environment", &Vprocess_environment /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 List of environment variables for subprocesses to inherit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 Each element should be a string of the form ENVVARNAME=VALUE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 The environment which Emacs inherits is placed in this variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 when Emacs starts.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 */ );
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
940
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
941 Vlisp_EXEC_SUFFIXES = build_string (EXEC_SUFFIXES);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 386
diff changeset
942 staticpro (&Vlisp_EXEC_SUFFIXES);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 }