296
|
1 /* Synchronous subprocess invocation for GNU Emacs.
|
11235
|
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
|
296
|
3
|
|
4 This file is part of GNU Emacs.
|
|
5
|
|
6 GNU Emacs is free software; you can redistribute it and/or modify
|
|
7 it under the terms of the GNU General Public License as published by
|
5516
|
8 the Free Software Foundation; either version 2, or (at your option)
|
296
|
9 any later version.
|
|
10
|
|
11 GNU Emacs is distributed in the hope that it will be useful,
|
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 GNU General Public License for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with GNU Emacs; see the file COPYING. If not, write to
|
14186
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
296
|
20
|
|
21
|
|
22 #include <signal.h>
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
23 #include <errno.h>
|
296
|
24
|
4696
|
25 #include <config.h>
|
7900
|
26 #include <stdio.h>
|
296
|
27
|
2286
|
28 extern int errno;
|
5516
|
29 extern char *strerror ();
|
2286
|
30
|
296
|
31 /* Define SIGCHLD as an alias for SIGCLD. */
|
|
32
|
|
33 #if !defined (SIGCHLD) && defined (SIGCLD)
|
|
34 #define SIGCHLD SIGCLD
|
|
35 #endif /* SIGCLD */
|
|
36
|
|
37 #include <sys/types.h>
|
3932
|
38
|
296
|
39 #include <sys/file.h>
|
|
40 #ifdef USG5
|
6818
|
41 #define INCLUDED_FCNTL
|
296
|
42 #include <fcntl.h>
|
|
43 #endif
|
|
44
|
9786
|
45 #ifdef WINDOWSNT
|
|
46 #define NOMINMAX
|
|
47 #include <windows.h>
|
|
48 #include <stdlib.h> /* for proper declaration of environ */
|
|
49 #include <fcntl.h>
|
16593
|
50 #include "w32.h"
|
9786
|
51 #define _P_NOWAIT 1 /* from process.h */
|
|
52 #endif
|
|
53
|
5501
|
54 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
|
6818
|
55 #define INCLUDED_FCNTL
|
5501
|
56 #include <fcntl.h>
|
|
57 #include <sys/stat.h>
|
|
58 #include <sys/param.h>
|
|
59 #include <errno.h>
|
|
60 #endif /* MSDOS */
|
|
61
|
296
|
62 #ifndef O_RDONLY
|
|
63 #define O_RDONLY 0
|
|
64 #endif
|
|
65
|
|
66 #ifndef O_WRONLY
|
|
67 #define O_WRONLY 1
|
|
68 #endif
|
|
69
|
|
70 #include "lisp.h"
|
|
71 #include "commands.h"
|
|
72 #include "buffer.h"
|
17025
|
73 #include "charset.h"
|
23885
|
74 #include "ccl.h"
|
17025
|
75 #include "coding.h"
|
4701
|
76 #include <paths.h>
|
296
|
77 #include "process.h"
|
1504
|
78 #include "syssignal.h"
|
5348
|
79 #include "systty.h"
|
296
|
80
|
21786
|
81 #ifdef MSDOS
|
|
82 #include "msdos.h"
|
|
83 #endif
|
|
84
|
296
|
85 #ifdef VMS
|
|
86 extern noshare char **environ;
|
|
87 #else
|
|
88 extern char **environ;
|
|
89 #endif
|
|
90
|
|
91 #define max(a, b) ((a) > (b) ? (a) : (b))
|
|
92
|
6031
|
93 Lisp_Object Vexec_path, Vexec_directory, Vdata_directory, Vdoc_directory;
|
3064
|
94 Lisp_Object Vconfigure_info_directory;
|
16627
|
95 Lisp_Object Vtemp_file_name_pattern;
|
296
|
96
|
|
97 Lisp_Object Vshell_file_name;
|
|
98
|
|
99 Lisp_Object Vprocess_environment;
|
|
100
|
9786
|
101 #ifdef DOS_NT
|
7397
|
102 Lisp_Object Qbuffer_file_type;
|
9786
|
103 #endif /* DOS_NT */
|
7397
|
104
|
296
|
105 /* True iff we are about to fork off a synchronous process or if we
|
|
106 are waiting for it. */
|
|
107 int synch_process_alive;
|
|
108
|
|
109 /* Nonzero => this is a string explaining death of synchronous subprocess. */
|
|
110 char *synch_process_death;
|
|
111
|
|
112 /* If synch_process_death is zero,
|
|
113 this is exit code of synchronous subprocess. */
|
|
114 int synch_process_retcode;
|
5154
|
115
|
|
116 extern Lisp_Object Vdoc_file_name;
|
19838
|
117
|
21053
|
118 extern Lisp_Object Vfile_name_coding_system, Vdefault_file_name_coding_system;
|
296
|
119
|
6275
|
120 /* Clean up when exiting Fcall_process.
|
|
121 On MSDOS, delete the temporary file on any kind of termination.
|
|
122 On Unix, kill the process and any children on termination by signal. */
|
|
123
|
|
124 /* Nonzero if this is termination due to exit. */
|
|
125 static int call_process_exited;
|
|
126
|
296
|
127 #ifndef VMS /* VMS version is in vmsproc.c. */
|
|
128
|
1504
|
129 static Lisp_Object
|
|
130 call_process_kill (fdpid)
|
|
131 Lisp_Object fdpid;
|
|
132 {
|
|
133 close (XFASTINT (Fcar (fdpid)));
|
|
134 EMACS_KILLPG (XFASTINT (Fcdr (fdpid)), SIGKILL);
|
|
135 synch_process_alive = 0;
|
|
136 return Qnil;
|
|
137 }
|
|
138
|
296
|
139 Lisp_Object
|
|
140 call_process_cleanup (fdpid)
|
|
141 Lisp_Object fdpid;
|
|
142 {
|
5501
|
143 #ifdef MSDOS
|
|
144 /* for MSDOS fdpid is really (fd . tempfile) */
|
6495
c88f34090aea
(call_process_cleanup, getenv_internal): Use assignment, not initialization.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
145 register Lisp_Object file;
|
c88f34090aea
(call_process_cleanup, getenv_internal): Use assignment, not initialization.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
146 file = Fcdr (fdpid);
|
5501
|
147 close (XFASTINT (Fcar (fdpid)));
|
|
148 if (strcmp (XSTRING (file)-> data, NULL_DEVICE) != 0)
|
|
149 unlink (XSTRING (file)->data);
|
|
150 #else /* not MSDOS */
|
1504
|
151 register int pid = XFASTINT (Fcdr (fdpid));
|
|
152
|
6466
|
153
|
6275
|
154 if (call_process_exited)
|
6466
|
155 {
|
|
156 close (XFASTINT (Fcar (fdpid)));
|
|
157 return Qnil;
|
|
158 }
|
6275
|
159
|
1504
|
160 if (EMACS_KILLPG (pid, SIGINT) == 0)
|
|
161 {
|
|
162 int count = specpdl_ptr - specpdl;
|
|
163 record_unwind_protect (call_process_kill, fdpid);
|
|
164 message1 ("Waiting for process to die...(type C-g again to kill it instantly)");
|
|
165 immediate_quit = 1;
|
|
166 QUIT;
|
|
167 wait_for_termination (pid);
|
|
168 immediate_quit = 0;
|
|
169 specpdl_ptr = specpdl + count; /* Discard the unwind protect. */
|
|
170 message1 ("Waiting for process to die...done");
|
|
171 }
|
296
|
172 synch_process_alive = 0;
|
1504
|
173 close (XFASTINT (Fcar (fdpid)));
|
5501
|
174 #endif /* not MSDOS */
|
296
|
175 return Qnil;
|
|
176 }
|
|
177
|
|
178 DEFUN ("call-process", Fcall_process, Scall_process, 1, MANY, 0,
|
|
179 "Call PROGRAM synchronously in separate process.\n\
|
23885
|
180 The remaining arguments are optional.\n\
|
296
|
181 The program's input comes from file INFILE (nil means `/dev/null').\n\
|
|
182 Insert output in BUFFER before point; t means current buffer;\n\
|
|
183 nil for BUFFER means discard it; 0 means discard and don't wait.\n\
|
10839
|
184 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,\n\
|
|
185 REAL-BUFFER says what to do with standard output, as above,\n\
|
|
186 while STDERR-FILE says what to do with standard error in the child.\n\
|
|
187 STDERR-FILE may be nil (discard standard error output),\n\
|
|
188 t (mix it with ordinary output), or a file name string.\n\
|
|
189 \n\
|
296
|
190 Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted.\n\
|
|
191 Remaining arguments are strings passed as command arguments to PROGRAM.\n\
|
10839
|
192 \n\
|
|
193 If BUFFER is 0, `call-process' returns immediately with value nil.\n\
|
|
194 Otherwise it waits for PROGRAM to terminate\n\
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
195 and returns a numeric exit status or a signal description string.\n\
|
1504
|
196 If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
|
296
|
197 (nargs, args)
|
|
198 int nargs;
|
|
199 register Lisp_Object *args;
|
|
200 {
|
1678
|
201 Lisp_Object infile, buffer, current_dir, display, path;
|
296
|
202 int fd[2];
|
|
203 int filefd;
|
|
204 register int pid;
|
11619
|
205 char buf[16384];
|
|
206 char *bufptr = buf;
|
|
207 int bufsize = 16384;
|
296
|
208 int count = specpdl_ptr - specpdl;
|
20525
|
209
|
296
|
210 register unsigned char **new_argv
|
|
211 = (unsigned char **) alloca ((max (2, nargs - 2)) * sizeof (char *));
|
|
212 struct buffer *old = current_buffer;
|
10839
|
213 /* File to use for stderr in the child.
|
|
214 t means use same as standard output. */
|
|
215 Lisp_Object error_file;
|
5501
|
216 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
|
|
217 char *outf, *tempfile;
|
|
218 int outfilefd;
|
|
219 #endif
|
296
|
220 #if 0
|
|
221 int mask;
|
|
222 #endif
|
17025
|
223 struct coding_system process_coding; /* coding-system of process output */
|
|
224 struct coding_system argument_coding; /* coding-system of arguments */
|
|
225
|
296
|
226 CHECK_STRING (args[0], 0);
|
|
227
|
10839
|
228 error_file = Qt;
|
|
229
|
5501
|
230 #ifndef subprocesses
|
|
231 /* Without asynchronous processes we cannot have BUFFER == 0. */
|
22550
|
232 if (nargs >= 3
|
22639
8177901b437a
(Fcall_process) [! subprocesses]: Balance parentheses in an if clause.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
233 && (INTEGERP (CONSP (args[2]) ? XCAR (args[2]) : args[2])))
|
5501
|
234 error ("Operating system cannot handle asynchronous subprocesses");
|
|
235 #endif /* subprocesses */
|
|
236
|
17025
|
237 /* Decide the coding-system for giving arguments and reading process
|
|
238 output. */
|
|
239 {
|
|
240 Lisp_Object val, *args2;
|
18539
|
241 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
|
17025
|
242 Lisp_Object coding_systems = Qt;
|
|
243 int i;
|
|
244
|
|
245 /* If arguments are supplied, we may have to encode them. */
|
|
246 if (nargs >= 5)
|
|
247 {
|
20595
|
248 int must_encode = 0;
|
|
249
|
20789
140b6fdd53d0
(Fcall_process): Test only args past args[4] for multibyteness.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
250 for (i = 4; i < nargs; i++)
|
22940
|
251 CHECK_STRING (args[i], i);
|
|
252
|
|
253 for (i = 4; i < nargs; i++)
|
20595
|
254 if (STRING_MULTIBYTE (args[i]))
|
|
255 must_encode = 1;
|
|
256
|
18651
|
257 if (!NILP (Vcoding_system_for_write))
|
|
258 val = Vcoding_system_for_write;
|
20595
|
259 else if (! must_encode)
|
18651
|
260 val = Qnil;
|
|
261 else
|
17025
|
262 {
|
|
263 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
|
|
264 args2[0] = Qcall_process;
|
|
265 for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
|
18539
|
266 coding_systems = Ffind_operation_coding_system (nargs + 1, args2);
|
18182
|
267 if (CONSP (coding_systems))
|
|
268 val = XCONS (coding_systems)->cdr;
|
|
269 else if (CONSP (Vdefault_process_coding_system))
|
|
270 val = XCONS (Vdefault_process_coding_system)->cdr;
|
18651
|
271 else
|
|
272 val = Qnil;
|
17025
|
273 }
|
|
274 setup_coding_system (Fcheck_coding_system (val), &argument_coding);
|
|
275 }
|
|
276
|
|
277 /* If BUFFER is nil, we must read process output once and then
|
|
278 discard it, so setup coding system but with nil. If BUFFER is
|
|
279 an integer, we can discard it without reading. */
|
22550
|
280 if (nargs < 3 || NILP (args[2])
|
|
281 || (CONSP (args[2]) && NILP (XCAR (args[2]))))
|
17025
|
282 setup_coding_system (Qnil, &process_coding);
|
22550
|
283 else if (!INTEGERP (CONSP (args[2]) ? XCAR (args[2]) : args[2]))
|
17025
|
284 {
|
18651
|
285 val = Qnil;
|
|
286 if (!NILP (Vcoding_system_for_read))
|
|
287 val = Vcoding_system_for_read;
|
|
288 else if (NILP (current_buffer->enable_multibyte_characters))
|
20724
|
289 val = Qraw_text;
|
18651
|
290 else
|
17025
|
291 {
|
21997
8320a731c121
(Fcall_process): Fix test for when to call Ffind_operation_coding_system.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
292 if (EQ (coding_systems, Qt))
|
17025
|
293 {
|
|
294 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
|
|
295 args2[0] = Qcall_process;
|
|
296 for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
|
18539
|
297 coding_systems
|
|
298 = Ffind_operation_coding_system (nargs + 1, args2);
|
17025
|
299 }
|
18182
|
300 if (CONSP (coding_systems))
|
|
301 val = XCONS (coding_systems)->car;
|
|
302 else if (CONSP (Vdefault_process_coding_system))
|
|
303 val = XCONS (Vdefault_process_coding_system)->car;
|
18651
|
304 else
|
|
305 val = Qnil;
|
17025
|
306 }
|
|
307 setup_coding_system (Fcheck_coding_system (val), &process_coding);
|
|
308 }
|
|
309 }
|
|
310
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
311 if (nargs >= 2 && ! NILP (args[1]))
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
312 {
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
313 infile = Fexpand_file_name (args[1], current_buffer->directory);
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
314 CHECK_STRING (infile, 1);
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
315 }
|
296
|
316 else
|
2432
|
317 infile = build_string (NULL_DEVICE);
|
648
|
318
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
319 if (nargs >= 3)
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
320 {
|
10839
|
321 buffer = args[2];
|
|
322
|
|
323 /* If BUFFER is a list, its meaning is
|
|
324 (BUFFER-FOR-STDOUT FILE-FOR-STDERR). */
|
|
325 if (CONSP (buffer))
|
|
326 {
|
|
327 if (CONSP (XCONS (buffer)->cdr))
|
15440
|
328 {
|
15473
|
329 Lisp_Object stderr_file;
|
15440
|
330 stderr_file = XCONS (XCONS (buffer)->cdr)->car;
|
|
331
|
|
332 if (NILP (stderr_file) || EQ (Qt, stderr_file))
|
|
333 error_file = stderr_file;
|
|
334 else
|
|
335 error_file = Fexpand_file_name (stderr_file, Qnil);
|
|
336 }
|
|
337
|
10839
|
338 buffer = XCONS (buffer)->car;
|
|
339 }
|
296
|
340
|
10839
|
341 if (!(EQ (buffer, Qnil)
|
|
342 || EQ (buffer, Qt)
|
22550
|
343 || INTEGERP (buffer)))
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
344 {
|
10839
|
345 Lisp_Object spec_buffer;
|
|
346 spec_buffer = buffer;
|
20823
|
347 buffer = Fget_buffer_create (buffer);
|
10839
|
348 /* Mention the buffer name for a better error message. */
|
|
349 if (NILP (buffer))
|
|
350 CHECK_BUFFER (spec_buffer, 2);
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
351 CHECK_BUFFER (buffer, 2);
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
352 }
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
353 }
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
354 else
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
355 buffer = Qnil;
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
356
|
1678
|
357 /* Make sure that the child will be able to chdir to the current
|
|
358 buffer's current directory, or its unhandled equivalent. We
|
|
359 can't just have the child check for an error when it does the
|
|
360 chdir, since it's in a vfork.
|
|
361
|
|
362 We have to GCPRO around this because Fexpand_file_name,
|
|
363 Funhandled_file_name_directory, and Ffile_accessible_directory_p
|
|
364 might call a file name handling function. The argument list is
|
|
365 protected by the caller, so all we really have to worry about is
|
|
366 buffer. */
|
|
367 {
|
|
368 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
369
|
|
370 current_dir = current_buffer->directory;
|
|
371
|
|
372 GCPRO3 (infile, buffer, current_dir);
|
|
373
|
6391
|
374 current_dir
|
|
375 = expand_and_dir_to_file (Funhandled_file_name_directory (current_dir),
|
|
376 Qnil);
|
1678
|
377 if (NILP (Ffile_accessible_directory_p (current_dir)))
|
|
378 report_file_error ("Setting current directory",
|
|
379 Fcons (current_buffer->directory, Qnil));
|
|
380
|
|
381 UNGCPRO;
|
|
382 }
|
|
383
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
384 display = nargs >= 4 ? args[3] : Qnil;
|
296
|
385
|
6391
|
386 filefd = open (XSTRING (infile)->data, O_RDONLY, 0);
|
|
387 if (filefd < 0)
|
|
388 {
|
|
389 report_file_error ("Opening process input file", Fcons (infile, Qnil));
|
|
390 }
|
|
391 /* Search for program; barf if not found. */
|
|
392 {
|
|
393 struct gcpro gcpro1;
|
|
394
|
|
395 GCPRO1 (current_dir);
|
|
396 openp (Vexec_path, args[0], EXEC_SUFFIXES, &path, 1);
|
|
397 UNGCPRO;
|
|
398 }
|
|
399 if (NILP (path))
|
|
400 {
|
|
401 close (filefd);
|
|
402 report_file_error ("Searching for program", Fcons (args[0], Qnil));
|
|
403 }
|
|
404 new_argv[0] = XSTRING (path)->data;
|
20230
|
405 if (nargs > 4)
|
|
406 {
|
|
407 register int i;
|
|
408
|
|
409 if (! CODING_REQUIRE_ENCODING (&argument_coding))
|
|
410 {
|
|
411 for (i = 4; i < nargs; i++)
|
|
412 new_argv[i - 3] = XSTRING (args[i])->data;
|
|
413 }
|
|
414 else
|
|
415 {
|
|
416 /* We must encode the arguments. */
|
|
417 struct gcpro gcpro1, gcpro2, gcpro3;
|
17025
|
418
|
20230
|
419 GCPRO3 (infile, buffer, current_dir);
|
|
420 for (i = 4; i < nargs; i++)
|
|
421 {
|
|
422 int size = encoding_buffer_size (&argument_coding,
|
21244
|
423 STRING_BYTES (XSTRING (args[i])));
|
20230
|
424 unsigned char *dummy1 = (unsigned char *) alloca (size);
|
20724
|
425 int dummy;
|
20230
|
426
|
|
427 /* The Irix 4.0 compiler barfs if we eliminate dummy. */
|
|
428 new_argv[i - 3] = dummy1;
|
23885
|
429 argument_coding.mode |= CODING_MODE_LAST_BLOCK;
|
20724
|
430 encode_coding (&argument_coding,
|
|
431 XSTRING (args[i])->data,
|
|
432 new_argv[i - 3],
|
21244
|
433 STRING_BYTES (XSTRING (args[i])),
|
20724
|
434 size);
|
|
435 new_argv[i - 3][argument_coding.produced] = 0;
|
23885
|
436 /* We have to initialize CCL program status again. */
|
|
437 if (argument_coding.type == coding_type_ccl)
|
|
438 setup_ccl_program (&(argument_coding.spec.ccl.encoder), Qnil);
|
20230
|
439 }
|
|
440 UNGCPRO;
|
|
441 }
|
20448
|
442 new_argv[nargs - 3] = 0;
|
20230
|
443 }
|
20448
|
444 else
|
|
445 new_argv[1] = 0;
|
296
|
446
|
5501
|
447 #ifdef MSDOS /* MW, July 1993 */
|
23462
|
448 if ((outf = egetenv ("TMPDIR")))
|
5501
|
449 strcpy (tempfile = alloca (strlen (outf) + 20), outf);
|
|
450 else
|
|
451 {
|
|
452 tempfile = alloca (20);
|
|
453 *tempfile = '\0';
|
|
454 }
|
|
455 dostounix_filename (tempfile);
|
|
456 if (*tempfile == '\0' || tempfile[strlen (tempfile) - 1] != '/')
|
|
457 strcat (tempfile, "/");
|
|
458 strcat (tempfile, "detmp.XXX");
|
|
459 mktemp (tempfile);
|
|
460
|
|
461 outfilefd = creat (tempfile, S_IREAD | S_IWRITE);
|
|
462 if (outfilefd < 0)
|
|
463 {
|
|
464 close (filefd);
|
15610
|
465 report_file_error ("Opening process output file",
|
|
466 Fcons (build_string (tempfile), Qnil));
|
5501
|
467 }
|
15610
|
468 fd[0] = filefd;
|
13719
|
469 fd[1] = outfilefd;
|
15610
|
470 #endif /* MSDOS */
|
5501
|
471
|
9138
|
472 if (INTEGERP (buffer))
|
2432
|
473 fd[1] = open (NULL_DEVICE, O_WRONLY), fd[0] = -1;
|
296
|
474 else
|
|
475 {
|
5501
|
476 #ifndef MSDOS
|
296
|
477 pipe (fd);
|
5501
|
478 #endif
|
296
|
479 #if 0
|
|
480 /* Replaced by close_process_descs */
|
|
481 set_exclusive_use (fd[0]);
|
|
482 #endif
|
|
483 }
|
|
484
|
|
485 {
|
|
486 /* child_setup must clobber environ in systems with true vfork.
|
|
487 Protect it from permanent change. */
|
|
488 register char **save_environ = environ;
|
|
489 register int fd1 = fd[1];
|
10839
|
490 int fd_error = fd1;
|
296
|
491
|
|
492 #if 0 /* Some systems don't have sigblock. */
|
638
|
493 mask = sigblock (sigmask (SIGCHLD));
|
296
|
494 #endif
|
|
495
|
|
496 /* Record that we're about to create a synchronous process. */
|
|
497 synch_process_alive = 1;
|
|
498
|
4977
|
499 /* These vars record information from process termination.
|
|
500 Clear them now before process can possibly terminate,
|
|
501 to avoid timing error if process terminates soon. */
|
|
502 synch_process_death = 0;
|
|
503 synch_process_retcode = 0;
|
|
504
|
10839
|
505 if (NILP (error_file))
|
|
506 fd_error = open (NULL_DEVICE, O_WRONLY);
|
|
507 else if (STRINGP (error_file))
|
|
508 {
|
|
509 #ifdef DOS_NT
|
|
510 fd_error = open (XSTRING (error_file)->data,
|
|
511 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT,
|
|
512 S_IREAD | S_IWRITE);
|
|
513 #else /* not DOS_NT */
|
|
514 fd_error = creat (XSTRING (error_file)->data, 0666);
|
|
515 #endif /* not DOS_NT */
|
|
516 }
|
|
517
|
|
518 if (fd_error < 0)
|
|
519 {
|
|
520 close (filefd);
|
15610
|
521 if (fd[0] != filefd)
|
|
522 close (fd[0]);
|
10839
|
523 if (fd1 >= 0)
|
|
524 close (fd1);
|
15610
|
525 #ifdef MSDOS
|
|
526 unlink (tempfile);
|
|
527 #endif
|
|
528 report_file_error ("Cannot redirect stderr",
|
|
529 Fcons ((NILP (error_file)
|
|
530 ? build_string (NULL_DEVICE) : error_file),
|
|
531 Qnil));
|
10839
|
532 }
|
19838
|
533
|
21053
|
534 current_dir = ENCODE_FILE (current_dir);
|
19838
|
535
|
13719
|
536 #ifdef MSDOS /* MW, July 1993 */
|
21694
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
537 /* Note that on MSDOS `child_setup' actually returns the child process
|
13719
|
538 exit status, not its PID, so we assign it to `synch_process_retcode'
|
|
539 below. */
|
21694
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
540 pid = child_setup (filefd, outfilefd, fd_error, (char **) new_argv,
|
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
541 0, current_dir);
|
13719
|
542
|
|
543 /* Record that the synchronous process exited and note its
|
|
544 termination status. */
|
|
545 synch_process_alive = 0;
|
|
546 synch_process_retcode = pid;
|
|
547 if (synch_process_retcode < 0) /* means it couldn't be exec'ed */
|
19580
|
548 synch_process_death = strerror (errno);
|
13719
|
549
|
|
550 close (outfilefd);
|
|
551 if (fd_error != outfilefd)
|
|
552 close (fd_error);
|
|
553 fd1 = -1; /* No harm in closing that one! */
|
17025
|
554 /* Since CRLF is converted to LF within `decode_coding', we can
|
|
555 always open a file with binary mode. */
|
|
556 fd[0] = open (tempfile, O_BINARY);
|
13719
|
557 if (fd[0] < 0)
|
|
558 {
|
|
559 unlink (tempfile);
|
|
560 close (filefd);
|
|
561 report_file_error ("Cannot re-open temporary file", Qnil);
|
|
562 }
|
|
563 #else /* not MSDOS */
|
9786
|
564 #ifdef WINDOWSNT
|
20525
|
565 pid = child_setup (filefd, fd1, fd_error, (char **) new_argv,
|
|
566 0, current_dir);
|
9786
|
567 #else /* not WINDOWSNT */
|
296
|
568 pid = vfork ();
|
|
569
|
|
570 if (pid == 0)
|
|
571 {
|
|
572 if (fd[0] >= 0)
|
|
573 close (fd[0]);
|
18235
|
574 #ifdef HAVE_SETSID
|
|
575 setsid ();
|
|
576 #endif
|
|
577 #if defined (USG) && !defined (BSD_PGRPS)
|
296
|
578 setpgrp ();
|
|
579 #else
|
|
580 setpgrp (pid, pid);
|
|
581 #endif /* USG */
|
20525
|
582 child_setup (filefd, fd1, fd_error, (char **) new_argv,
|
|
583 0, current_dir);
|
296
|
584 }
|
13719
|
585 #endif /* not WINDOWSNT */
|
15225
|
586
|
|
587 /* The MSDOS case did this already. */
|
|
588 if (fd_error >= 0)
|
|
589 close (fd_error);
|
5501
|
590 #endif /* not MSDOS */
|
296
|
591
|
|
592 environ = save_environ;
|
|
593
|
6466
|
594 /* Close most of our fd's, but not fd[0]
|
|
595 since we will use that to read input from. */
|
296
|
596 close (filefd);
|
15236
|
597 if (fd1 >= 0 && fd1 != fd_error)
|
5501
|
598 close (fd1);
|
296
|
599 }
|
|
600
|
|
601 if (pid < 0)
|
|
602 {
|
6466
|
603 if (fd[0] >= 0)
|
|
604 close (fd[0]);
|
296
|
605 report_file_error ("Doing vfork", Qnil);
|
|
606 }
|
|
607
|
9138
|
608 if (INTEGERP (buffer))
|
296
|
609 {
|
6466
|
610 if (fd[0] >= 0)
|
|
611 close (fd[0]);
|
296
|
612 #ifndef subprocesses
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
613 /* If Emacs has been built with asynchronous subprocess support,
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
614 we don't need to do this, I think because it will then have
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
615 the facilities for handling SIGCHLD. */
|
296
|
616 wait_without_blocking ();
|
|
617 #endif /* subprocesses */
|
|
618 return Qnil;
|
|
619 }
|
|
620
|
6466
|
621 /* Enable sending signal if user quits below. */
|
6275
|
622 call_process_exited = 0;
|
|
623
|
5501
|
624 #ifdef MSDOS
|
|
625 /* MSDOS needs different cleanup information. */
|
|
626 record_unwind_protect (call_process_cleanup,
|
|
627 Fcons (make_number (fd[0]), build_string (tempfile)));
|
|
628 #else
|
296
|
629 record_unwind_protect (call_process_cleanup,
|
|
630 Fcons (make_number (fd[0]), make_number (pid)));
|
5501
|
631 #endif /* not MSDOS */
|
296
|
632
|
|
633
|
9138
|
634 if (BUFFERP (buffer))
|
296
|
635 Fset_buffer (buffer);
|
|
636
|
|
637 immediate_quit = 1;
|
|
638 QUIT;
|
|
639
|
|
640 {
|
|
641 register int nread;
|
5251
|
642 int first = 1;
|
11619
|
643 int total_read = 0;
|
20724
|
644 int carryover = 0;
|
21966
|
645 int display_on_the_fly = !NILP (display) && INTERACTIVE;
|
22320
|
646 struct coding_system saved_coding;
|
|
647
|
|
648 saved_coding = process_coding;
|
296
|
649
|
11780
|
650 while (1)
|
296
|
651 {
|
11780
|
652 /* Repeatedly read until we've filled as much as possible
|
|
653 of the buffer size we have. But don't read
|
14036
|
654 less than 1024--save that for the next bufferful. */
|
20724
|
655 nread = carryover;
|
11780
|
656 while (nread < bufsize - 1024)
|
8853
|
657 {
|
20724
|
658 int this_read = read (fd[0], bufptr + nread, bufsize - nread);
|
11780
|
659
|
|
660 if (this_read < 0)
|
|
661 goto give_up;
|
|
662
|
|
663 if (this_read == 0)
|
21966
|
664 {
|
|
665 process_coding.mode |= CODING_MODE_LAST_BLOCK;
|
|
666 break;
|
|
667 }
|
11780
|
668
|
|
669 nread += this_read;
|
21966
|
670 total_read += this_read;
|
11780
|
671
|
21966
|
672 if (display_on_the_fly)
|
|
673 break;
|
|
674 }
|
11780
|
675
|
|
676 /* Now NREAD is the total amount of data in the buffer. */
|
296
|
677 immediate_quit = 0;
|
11619
|
678
|
942
|
679 if (!NILP (buffer))
|
17025
|
680 {
|
|
681 if (process_coding.type == coding_type_no_conversion)
|
|
682 insert (bufptr, nread);
|
|
683 else
|
|
684 { /* We have to decode the input. */
|
20724
|
685 int size = decoding_buffer_size (&process_coding, nread);
|
23079
|
686 char *decoding_buf = (char *) malloc (size);
|
17025
|
687
|
20724
|
688 decode_coding (&process_coding, bufptr, decoding_buf,
|
|
689 nread, size);
|
21966
|
690 if (display_on_the_fly
|
|
691 && saved_coding.type == coding_type_undecided
|
|
692 && process_coding.type != coding_type_undecided)
|
|
693 {
|
|
694 /* We have detected some coding system. But,
|
|
695 there's a possibility that the detection was
|
|
696 done by insufficient data. So, we give up
|
|
697 displaying on the fly. */
|
23079
|
698 free (decoding_buf);
|
21966
|
699 display_on_the_fly = 0;
|
|
700 process_coding = saved_coding;
|
|
701 carryover = nread;
|
|
702 continue;
|
|
703 }
|
20724
|
704 if (process_coding.produced > 0)
|
|
705 insert (decoding_buf, process_coding.produced);
|
23079
|
706 free (decoding_buf);
|
21036
|
707 carryover = nread - process_coding.consumed;
|
20724
|
708 if (carryover > 0)
|
|
709 {
|
|
710 /* As CARRYOVER should not be that large, we had
|
|
711 better avoid overhead of bcopy. */
|
|
712 char *p = bufptr + process_coding.consumed;
|
|
713 char *pend = p + carryover;
|
|
714 char *dst = bufptr;
|
|
715
|
|
716 while (p < pend) *dst++ = *p++;
|
|
717 }
|
17025
|
718 }
|
|
719 }
|
20724
|
720 if (process_coding.mode & CODING_MODE_LAST_BLOCK)
|
|
721 {
|
|
722 if (carryover > 0)
|
|
723 insert (bufptr, carryover);
|
|
724 break;
|
|
725 }
|
11619
|
726
|
|
727 /* Make the buffer bigger as we continue to read more data,
|
|
728 but not past 64k. */
|
|
729 if (bufsize < 64 * 1024 && total_read > 32 * bufsize)
|
|
730 {
|
|
731 bufsize *= 2;
|
|
732 bufptr = (char *) alloca (bufsize);
|
|
733 }
|
|
734
|
942
|
735 if (!NILP (display) && INTERACTIVE)
|
5251
|
736 {
|
|
737 if (first)
|
|
738 prepare_menu_bars ();
|
|
739 first = 0;
|
|
740 redisplay_preserve_echo_area ();
|
|
741 }
|
296
|
742 immediate_quit = 1;
|
|
743 QUIT;
|
|
744 }
|
11780
|
745 give_up: ;
|
296
|
746
|
20436
|
747 Vlast_coding_system_used = process_coding.symbol;
|
|
748
|
21572
|
749 /* If the caller required, let the buffer inherit the
|
|
750 coding-system used to decode the process output. */
|
|
751 if (inherit_process_coding_system)
|
|
752 call1 (intern ("after-insert-file-set-buffer-file-coding-system"),
|
|
753 make_number (total_read));
|
|
754 }
|
|
755
|
296
|
756 /* Wait for it to terminate, unless it already has. */
|
|
757 wait_for_termination (pid);
|
|
758
|
|
759 immediate_quit = 0;
|
|
760
|
|
761 set_buffer_internal (old);
|
|
762
|
6275
|
763 /* Don't kill any children that the subprocess may have left behind
|
|
764 when exiting. */
|
|
765 call_process_exited = 1;
|
|
766
|
296
|
767 unbind_to (count, Qnil);
|
|
768
|
|
769 if (synch_process_death)
|
|
770 return build_string (synch_process_death);
|
|
771 return make_number (synch_process_retcode);
|
|
772 }
|
|
773 #endif
|
|
774
|
1912
|
775 static Lisp_Object
|
296
|
776 delete_temp_file (name)
|
|
777 Lisp_Object name;
|
|
778 {
|
10083
|
779 /* Use Fdelete_file (indirectly) because that runs a file name handler.
|
8737
|
780 We did that when writing the file, so we should do so when deleting. */
|
10083
|
781 internal_delete_file (name);
|
296
|
782 }
|
|
783
|
|
784 DEFUN ("call-process-region", Fcall_process_region, Scall_process_region,
|
|
785 3, MANY, 0,
|
|
786 "Send text from START to END to a synchronous process running PROGRAM.\n\
|
23885
|
787 The remaining arguments are optional.\n\
|
296
|
788 Delete the text if fourth arg DELETE is non-nil.\n\
|
10839
|
789 \n\
|
296
|
790 Insert output in BUFFER before point; t means current buffer;\n\
|
|
791 nil for BUFFER means discard it; 0 means discard and don't wait.\n\
|
10839
|
792 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,\n\
|
|
793 REAL-BUFFER says what to do with standard output, as above,\n\
|
|
794 while STDERR-FILE says what to do with standard error in the child.\n\
|
|
795 STDERR-FILE may be nil (discard standard error output),\n\
|
|
796 t (mix it with ordinary output), or a file name string.\n\
|
|
797 \n\
|
296
|
798 Sixth arg DISPLAY non-nil means redisplay buffer as output is inserted.\n\
|
|
799 Remaining args are passed to PROGRAM at startup as command args.\n\
|
10839
|
800 \n\
|
|
801 If BUFFER is nil, `call-process-region' returns immediately with value nil.\n\
|
|
802 Otherwise it waits for PROGRAM to terminate\n\
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
803 and returns a numeric exit status or a signal description string.\n\
|
1504
|
804 If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
|
296
|
805 (nargs, args)
|
|
806 int nargs;
|
|
807 register Lisp_Object *args;
|
|
808 {
|
8555
|
809 struct gcpro gcpro1;
|
|
810 Lisp_Object filename_string;
|
|
811 register Lisp_Object start, end;
|
16659
|
812 int count = specpdl_ptr - specpdl;
|
18539
|
813 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
|
17025
|
814 Lisp_Object coding_systems = Qt;
|
|
815 Lisp_Object val, *args2;
|
|
816 int i;
|
9786
|
817 #ifdef DOS_NT
|
5501
|
818 char *tempfile;
|
|
819 char *outf = '\0';
|
|
820
|
23462
|
821 if ((outf = egetenv ("TMPDIR"))
|
|
822 || (outf = egetenv ("TMP"))
|
|
823 || (outf = egetenv ("TEMP")))
|
5501
|
824 strcpy (tempfile = alloca (strlen (outf) + 20), outf);
|
|
825 else
|
|
826 {
|
|
827 tempfile = alloca (20);
|
|
828 *tempfile = '\0';
|
|
829 }
|
12238
|
830 if (!IS_DIRECTORY_SEP (tempfile[strlen (tempfile) - 1]))
|
5501
|
831 strcat (tempfile, "/");
|
15824
|
832 if ('/' == DIRECTORY_SEP)
|
|
833 dostounix_filename (tempfile);
|
|
834 else
|
|
835 unixtodos_filename (tempfile);
|
12238
|
836 #ifdef WINDOWSNT
|
|
837 strcat (tempfile, "emXXXXXX");
|
|
838 #else
|
5501
|
839 strcat (tempfile, "detmp.XXX");
|
12238
|
840 #endif
|
9786
|
841 #else /* not DOS_NT */
|
21244
|
842 char *tempfile = (char *) alloca (STRING_BYTES (XSTRING (Vtemp_file_name_pattern)) + 1);
|
16627
|
843 bcopy (XSTRING (Vtemp_file_name_pattern)->data, tempfile,
|
21244
|
844 STRING_BYTES (XSTRING (Vtemp_file_name_pattern)) + 1);
|
9786
|
845 #endif /* not DOS_NT */
|
5501
|
846
|
296
|
847 mktemp (tempfile);
|
|
848
|
|
849 filename_string = build_string (tempfile);
|
8555
|
850 GCPRO1 (filename_string);
|
296
|
851 start = args[0];
|
|
852 end = args[1];
|
17025
|
853 /* Decide coding-system of the contents of the temporary file. */
|
19730
|
854 if (!NILP (Vcoding_system_for_write))
|
|
855 val = Vcoding_system_for_write;
|
|
856 else if (NILP (current_buffer->enable_multibyte_characters))
|
17025
|
857 val = Qnil;
|
|
858 else
|
18651
|
859 {
|
19730
|
860 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
|
|
861 args2[0] = Qcall_process_region;
|
|
862 for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
|
|
863 coding_systems = Ffind_operation_coding_system (nargs + 1, args2);
|
|
864 if (CONSP (coding_systems))
|
|
865 val = XCONS (coding_systems)->cdr;
|
|
866 else if (CONSP (Vdefault_process_coding_system))
|
|
867 val = XCONS (Vdefault_process_coding_system)->cdr;
|
18651
|
868 else
|
19730
|
869 val = Qnil;
|
18651
|
870 }
|
19730
|
871
|
21626
|
872 {
|
|
873 int count1 = specpdl_ptr - specpdl;
|
|
874
|
|
875 specbind (intern ("coding-system-for-write"), val);
|
|
876 Fwrite_region (start, end, filename_string, Qnil, Qlambda, Qnil, Qnil);
|
|
877
|
|
878 unbind_to (count1, Qnil);
|
|
879 }
|
17025
|
880
|
19730
|
881 /* Note that Fcall_process takes care of binding
|
|
882 coding-system-for-read. */
|
7397
|
883
|
296
|
884 record_unwind_protect (delete_temp_file, filename_string);
|
|
885
|
23885
|
886 if (nargs > 3 && !NILP (args[3]))
|
296
|
887 Fdelete_region (start, end);
|
|
888
|
23885
|
889 if (nargs > 3)
|
|
890 {
|
|
891 args += 2;
|
|
892 nargs -= 2;
|
|
893 }
|
|
894 else
|
|
895 {
|
|
896 args[0] = args[2];
|
|
897 nargs = 2;
|
|
898 }
|
|
899 args[1] = filename_string;
|
296
|
900
|
23885
|
901 RETURN_UNGCPRO (unbind_to (count, Fcall_process (nargs, args)));
|
296
|
902 }
|
|
903
|
|
904 #ifndef VMS /* VMS version is in vmsproc.c. */
|
|
905
|
21514
|
906 static int relocate_fd ();
|
|
907
|
296
|
908 /* This is the last thing run in a newly forked inferior
|
|
909 either synchronous or asynchronous.
|
|
910 Copy descriptors IN, OUT and ERR as descriptors 0, 1 and 2.
|
|
911 Initialize inferior's priority, pgrp, connected dir and environment.
|
|
912 then exec another program based on new_argv.
|
|
913
|
|
914 This function may change environ for the superior process.
|
|
915 Therefore, the superior process must save and restore the value
|
|
916 of environ around the vfork and the call to this function.
|
|
917
|
|
918 SET_PGRP is nonzero if we should put the subprocess into a separate
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
919 process group.
|
296
|
920
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
921 CURRENT_DIR is an elisp string giving the path of the current
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
922 directory the subprocess should have. Since we can't really signal
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
923 a decent error from within the child, this should be verified as an
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
924 executable directory by the parent. */
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
925
|
21514
|
926 int
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
927 child_setup (in, out, err, new_argv, set_pgrp, current_dir)
|
296
|
928 int in, out, err;
|
|
929 register char **new_argv;
|
|
930 int set_pgrp;
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
931 Lisp_Object current_dir;
|
296
|
932 {
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
933 char **env;
|
7722
|
934 char *pwd_var;
|
9786
|
935 #ifdef WINDOWSNT
|
|
936 int cpid;
|
15087
|
937 HANDLE handles[3];
|
9786
|
938 #endif /* WINDOWSNT */
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
939
|
5530
7ff479a8e8bf
(child_setup): Don't declare PID `register'; we later take its address.
Roland McGrath <roland@gnu.org>
diff
changeset
|
940 int pid = getpid ();
|
296
|
941
|
7481
|
942 #ifdef SET_EMACS_PRIORITY
|
1201
|
943 {
|
|
944 extern int emacs_priority;
|
|
945
|
7481
|
946 if (emacs_priority < 0)
|
|
947 nice (- emacs_priority);
|
1201
|
948 }
|
7161
|
949 #endif
|
296
|
950
|
|
951 #ifdef subprocesses
|
|
952 /* Close Emacs's descriptors that this process should not have. */
|
|
953 close_process_descs ();
|
|
954 #endif
|
21694
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
955 /* DOS_NT isn't in a vfork, so if we are in the middle of load-file,
|
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
956 we will lose if we call close_load_descs here. */
|
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
957 #ifndef DOS_NT
|
5569
|
958 close_load_descs ();
|
21694
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
959 #endif
|
296
|
960
|
|
961 /* Note that use of alloca is always safe here. It's obvious for systems
|
|
962 that do not have true vfork or that have true (stack) alloca.
|
|
963 If using vfork and C_ALLOCA it is safe because that changes
|
|
964 the superior's static variables as if the superior had done alloca
|
|
965 and will be cleaned up in the usual way. */
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
966 {
|
7722
|
967 register char *temp;
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
968 register int i;
|
296
|
969
|
21244
|
970 i = STRING_BYTES (XSTRING (current_dir));
|
7722
|
971 pwd_var = (char *) alloca (i + 6);
|
|
972 temp = pwd_var + 4;
|
|
973 bcopy ("PWD=", pwd_var, 4);
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
974 bcopy (XSTRING (current_dir)->data, temp, i);
|
9786
|
975 if (!IS_DIRECTORY_SEP (temp[i - 1])) temp[i++] = DIRECTORY_SEP;
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
976 temp[i] = 0;
|
538
|
977
|
21694
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
978 #ifndef DOS_NT
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
979 /* We can't signal an Elisp error here; we're in a vfork. Since
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
980 the callers check the current directory before forking, this
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
981 should only return an error if the directory's permissions
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
982 are changed between the check and this chdir, but we should
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
983 at least check. */
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
984 if (chdir (temp) < 0)
|
9609
|
985 _exit (errno);
|
19967
|
986 #endif
|
7722
|
987
|
21694
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
988 #ifdef DOS_NT
|
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
989 /* Get past the drive letter, so that d:/ is left alone. */
|
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
990 if (i > 2 && IS_DEVICE_SEP (temp[1]) && IS_DIRECTORY_SEP (temp[2]))
|
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
991 {
|
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
992 temp += 2;
|
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
993 i -= 2;
|
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
994 }
|
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
995 #endif
|
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
996
|
7722
|
997 /* Strip trailing slashes for PWD, but leave "/" and "//" alone. */
|
9786
|
998 while (i > 2 && IS_DIRECTORY_SEP (temp[i - 1]))
|
7722
|
999 temp[--i] = 0;
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1000 }
|
296
|
1001
|
|
1002 /* Set `env' to a vector of the strings in Vprocess_environment. */
|
|
1003 {
|
|
1004 register Lisp_Object tem;
|
|
1005 register char **new_env;
|
|
1006 register int new_length;
|
|
1007
|
|
1008 new_length = 0;
|
|
1009 for (tem = Vprocess_environment;
|
9138
|
1010 CONSP (tem) && STRINGP (XCONS (tem)->car);
|
296
|
1011 tem = XCONS (tem)->cdr)
|
|
1012 new_length++;
|
|
1013
|
7722
|
1014 /* new_length + 2 to include PWD and terminating 0. */
|
|
1015 env = new_env = (char **) alloca ((new_length + 2) * sizeof (char *));
|
|
1016
|
|
1017 /* If we have a PWD envvar, pass one down,
|
|
1018 but with corrected value. */
|
|
1019 if (getenv ("PWD"))
|
|
1020 *new_env++ = pwd_var;
|
296
|
1021
|
2757
|
1022 /* Copy the Vprocess_environment strings into new_env. */
|
296
|
1023 for (tem = Vprocess_environment;
|
9138
|
1024 CONSP (tem) && STRINGP (XCONS (tem)->car);
|
296
|
1025 tem = XCONS (tem)->cdr)
|
2757
|
1026 {
|
|
1027 char **ep = env;
|
|
1028 char *string = (char *) XSTRING (XCONS (tem)->car)->data;
|
|
1029 /* See if this string duplicates any string already in the env.
|
|
1030 If so, don't put it in.
|
|
1031 When an env var has multiple definitions,
|
|
1032 we keep the definition that comes first in process-environment. */
|
|
1033 for (; ep != new_env; ep++)
|
|
1034 {
|
|
1035 char *p = *ep, *q = string;
|
|
1036 while (1)
|
|
1037 {
|
|
1038 if (*q == 0)
|
|
1039 /* The string is malformed; might as well drop it. */
|
|
1040 goto duplicate;
|
|
1041 if (*q != *p)
|
|
1042 break;
|
|
1043 if (*q == '=')
|
|
1044 goto duplicate;
|
|
1045 p++, q++;
|
|
1046 }
|
|
1047 }
|
|
1048 *new_env++ = string;
|
|
1049 duplicate: ;
|
|
1050 }
|
296
|
1051 *new_env = 0;
|
|
1052 }
|
9786
|
1053 #ifdef WINDOWSNT
|
|
1054 prepare_standard_handles (in, out, err, handles);
|
19967
|
1055 set_process_dir (XSTRING (current_dir)->data);
|
9786
|
1056 #else /* not WINDOWSNT */
|
2286
|
1057 /* Make sure that in, out, and err are not actually already in
|
|
1058 descriptors zero, one, or two; this could happen if Emacs is
|
5501
|
1059 started with its standard in, out, or error closed, as might
|
2286
|
1060 happen under X. */
|
12430
|
1061 {
|
|
1062 int oin = in, oout = out;
|
|
1063
|
|
1064 /* We have to avoid relocating the same descriptor twice! */
|
|
1065
|
|
1066 in = relocate_fd (in, 3);
|
|
1067
|
|
1068 if (out == oin)
|
|
1069 out = in;
|
|
1070 else
|
6614
|
1071 out = relocate_fd (out, 3);
|
12430
|
1072
|
|
1073 if (err == oin)
|
|
1074 err = in;
|
|
1075 else if (err == oout)
|
|
1076 err = out;
|
|
1077 else
|
6614
|
1078 err = relocate_fd (err, 3);
|
12430
|
1079 }
|
2286
|
1080
|
21694
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
1081 #ifndef MSDOS
|
296
|
1082 close (0);
|
|
1083 close (1);
|
|
1084 close (2);
|
|
1085
|
|
1086 dup2 (in, 0);
|
|
1087 dup2 (out, 1);
|
|
1088 dup2 (err, 2);
|
|
1089 close (in);
|
|
1090 close (out);
|
|
1091 close (err);
|
21694
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
1092 #endif /* not MSDOS */
|
9786
|
1093 #endif /* not WINDOWSNT */
|
296
|
1094
|
14872
|
1095 #if defined(USG) && !defined(BSD_PGRPS)
|
5179
|
1096 #ifndef SETPGRP_RELEASES_CTTY
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1097 setpgrp (); /* No arguments but equivalent in this case */
|
5179
|
1098 #endif
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1099 #else
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1100 setpgrp (pid, pid);
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1101 #endif /* USG */
|
5348
|
1102 /* setpgrp_of_tty is incorrect here; it uses input_fd. */
|
|
1103 EMACS_SET_TTY_PGRP (0, &pid);
|
296
|
1104
|
|
1105 #ifdef vipc
|
|
1106 something missing here;
|
|
1107 #endif /* vipc */
|
|
1108
|
21694
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
1109 #ifdef MSDOS
|
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
1110 pid = run_msdos_command (new_argv, pwd_var + 4, in, out, err, env);
|
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
1111 if (pid == -1)
|
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
1112 /* An error occurred while trying to run the subprocess. */
|
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
1113 report_file_error ("Spawning child process", Qnil);
|
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
1114 return pid;
|
6e12eeda6913
(Fcall_process) [MSDOS]: Call child_setup instead of run_msdos_command.
Eli Zaretskii <eliz@gnu.org>
diff
changeset
|
1115 #else /* not MSDOS */
|
9786
|
1116 #ifdef WINDOWSNT
|
|
1117 /* Spawn the child. (See ntproc.c:Spawnve). */
|
|
1118 cpid = spawnve (_P_NOWAIT, new_argv[0], new_argv, env);
|
20041
|
1119 reset_standard_handles (in, out, err, handles);
|
11379
|
1120 if (cpid == -1)
|
|
1121 /* An error occurred while trying to spawn the process. */
|
|
1122 report_file_error ("Spawning child process", Qnil);
|
9786
|
1123 return cpid;
|
|
1124 #else /* not WINDOWSNT */
|
296
|
1125 /* execvp does not accept an environment arg so the only way
|
|
1126 to pass this environment is to set environ. Our caller
|
|
1127 is responsible for restoring the ambient value of environ. */
|
|
1128 environ = env;
|
|
1129 execvp (new_argv[0], new_argv);
|
|
1130
|
14438
|
1131 write (1, "Can't exec program: ", 20);
|
296
|
1132 write (1, new_argv[0], strlen (new_argv[0]));
|
11513
|
1133 write (1, "\n", 1);
|
296
|
1134 _exit (1);
|
9786
|
1135 #endif /* not WINDOWSNT */
|
5501
|
1136 #endif /* not MSDOS */
|
296
|
1137 }
|
|
1138
|
21454
|
1139 /* Move the file descriptor FD so that its number is not less than MINFD.
|
2286
|
1140 If the file descriptor is moved at all, the original is freed. */
|
21514
|
1141 static int
|
21454
|
1142 relocate_fd (fd, minfd)
|
|
1143 int fd, minfd;
|
2286
|
1144 {
|
21454
|
1145 if (fd >= minfd)
|
2286
|
1146 return fd;
|
|
1147 else
|
|
1148 {
|
|
1149 int new = dup (fd);
|
|
1150 if (new == -1)
|
|
1151 {
|
2509
|
1152 char *message1 = "Error while setting up child: ";
|
5516
|
1153 char *errmessage = strerror (errno);
|
2509
|
1154 char *message2 = "\n";
|
|
1155 write (2, message1, strlen (message1));
|
5516
|
1156 write (2, errmessage, strlen (errmessage));
|
2509
|
1157 write (2, message2, strlen (message2));
|
2286
|
1158 _exit (1);
|
|
1159 }
|
|
1160 /* Note that we hold the original FD open while we recurse,
|
|
1161 to guarantee we'll get a new FD if we need it. */
|
21454
|
1162 new = relocate_fd (new, minfd);
|
2286
|
1163 close (fd);
|
|
1164 return new;
|
|
1165 }
|
|
1166 }
|
|
1167
|
942
|
1168 static int
|
|
1169 getenv_internal (var, varlen, value, valuelen)
|
|
1170 char *var;
|
|
1171 int varlen;
|
|
1172 char **value;
|
|
1173 int *valuelen;
|
|
1174 {
|
|
1175 Lisp_Object scan;
|
|
1176
|
|
1177 for (scan = Vprocess_environment; CONSP (scan); scan = XCONS (scan)->cdr)
|
|
1178 {
|
6495
c88f34090aea
(call_process_cleanup, getenv_internal): Use assignment, not initialization.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
1179 Lisp_Object entry;
|
c88f34090aea
(call_process_cleanup, getenv_internal): Use assignment, not initialization.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
1180
|
c88f34090aea
(call_process_cleanup, getenv_internal): Use assignment, not initialization.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
1181 entry = XCONS (scan)->car;
|
9138
|
1182 if (STRINGP (entry)
|
21244
|
1183 && STRING_BYTES (XSTRING (entry)) > varlen
|
942
|
1184 && XSTRING (entry)->data[varlen] == '='
|
9786
|
1185 #ifdef WINDOWSNT
|
|
1186 /* NT environment variables are case insensitive. */
|
11393
|
1187 && ! strnicmp (XSTRING (entry)->data, var, varlen)
|
9786
|
1188 #else /* not WINDOWSNT */
|
11393
|
1189 && ! bcmp (XSTRING (entry)->data, var, varlen)
|
9786
|
1190 #endif /* not WINDOWSNT */
|
11393
|
1191 )
|
942
|
1192 {
|
|
1193 *value = (char *) XSTRING (entry)->data + (varlen + 1);
|
21244
|
1194 *valuelen = STRING_BYTES (XSTRING (entry)) - (varlen + 1);
|
942
|
1195 return 1;
|
|
1196 }
|
|
1197 }
|
|
1198
|
|
1199 return 0;
|
|
1200 }
|
|
1201
|
5251
|
1202 DEFUN ("getenv", Fgetenv, Sgetenv, 1, 1, 0,
|
942
|
1203 "Return the value of environment variable VAR, as a string.\n\
|
|
1204 VAR should be a string. Value is nil if VAR is undefined in the environment.\n\
|
|
1205 This function consults the variable ``process-environment'' for its value.")
|
|
1206 (var)
|
|
1207 Lisp_Object var;
|
|
1208 {
|
|
1209 char *value;
|
|
1210 int valuelen;
|
|
1211
|
|
1212 CHECK_STRING (var, 0);
|
21244
|
1213 if (getenv_internal (XSTRING (var)->data, STRING_BYTES (XSTRING (var)),
|
942
|
1214 &value, &valuelen))
|
|
1215 return make_string (value, valuelen);
|
|
1216 else
|
|
1217 return Qnil;
|
|
1218 }
|
|
1219
|
|
1220 /* A version of getenv that consults process_environment, easily
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1221 callable from C. */
|
942
|
1222 char *
|
|
1223 egetenv (var)
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1224 char *var;
|
942
|
1225 {
|
|
1226 char *value;
|
|
1227 int valuelen;
|
|
1228
|
|
1229 if (getenv_internal (var, strlen (var), &value, &valuelen))
|
|
1230 return value;
|
|
1231 else
|
|
1232 return 0;
|
|
1233 }
|
|
1234
|
296
|
1235 #endif /* not VMS */
|
|
1236
|
5154
|
1237 /* This is run before init_cmdargs. */
|
5501
|
1238
|
21514
|
1239 void
|
5154
|
1240 init_callproc_1 ()
|
|
1241 {
|
|
1242 char *data_dir = egetenv ("EMACSDATA");
|
6031
|
1243 char *doc_dir = egetenv ("EMACSDOC");
|
|
1244
|
5154
|
1245 Vdata_directory
|
5501
|
1246 = Ffile_name_as_directory (build_string (data_dir ? data_dir
|
5154
|
1247 : PATH_DATA));
|
6031
|
1248 Vdoc_directory
|
|
1249 = Ffile_name_as_directory (build_string (doc_dir ? doc_dir
|
|
1250 : PATH_DOC));
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1251
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1252 /* Check the EMACSPATH environment variable, defaulting to the
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1253 PATH_EXEC path from paths.h. */
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1254 Vexec_path = decode_env_path ("EMACSPATH", PATH_EXEC);
|
296
|
1255 Vexec_directory = Ffile_name_as_directory (Fcar (Vexec_path));
|
|
1256 Vexec_path = nconc2 (decode_env_path ("PATH", ""), Vexec_path);
|
5154
|
1257 }
|
|
1258
|
12615
|
1259 /* This is run after init_cmdargs, when Vinstallation_directory is valid. */
|
5154
|
1260
|
21514
|
1261 void
|
5154
|
1262 init_callproc ()
|
|
1263 {
|
|
1264 char *data_dir = egetenv ("EMACSDATA");
|
|
1265
|
|
1266 register char * sh;
|
|
1267 Lisp_Object tempdir;
|
|
1268
|
22373
cb8484085daf
(init_callproc): Check Vinstallation_directory even if !initialized.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1269 if (!NILP (Vinstallation_directory))
|
5154
|
1270 {
|
5618
|
1271 /* Add to the path the lib-src subdir of the installation dir. */
|
|
1272 Lisp_Object tem;
|
|
1273 tem = Fexpand_file_name (build_string ("lib-src"),
|
|
1274 Vinstallation_directory);
|
|
1275 if (NILP (Fmember (tem, Vexec_path)))
|
5154
|
1276 {
|
9786
|
1277 #ifndef DOS_NT
|
7824
|
1278 /* MSDOS uses wrapped binaries, so don't do this. */
|
5154
|
1279 Vexec_path = nconc2 (Vexec_path, Fcons (tem, Qnil));
|
|
1280 Vexec_directory = Ffile_name_as_directory (tem);
|
9786
|
1281 #endif /* not DOS_NT */
|
12615
|
1282 }
|
5154
|
1283
|
12615
|
1284 /* Maybe use ../etc as well as ../lib-src. */
|
|
1285 if (data_dir == 0)
|
|
1286 {
|
|
1287 tem = Fexpand_file_name (build_string ("etc"),
|
|
1288 Vinstallation_directory);
|
|
1289 Vdoc_directory = Ffile_name_as_directory (tem);
|
5154
|
1290 }
|
|
1291 }
|
7465
|
1292
|
|
1293 /* Look for the files that should be in etc. We don't use
|
|
1294 Vinstallation_directory, because these files are never installed
|
12615
|
1295 near the executable, and they are never in the build
|
7465
|
1296 directory when that's different from the source directory.
|
|
1297
|
|
1298 Instead, if these files are not in the nominal place, we try the
|
|
1299 source directory. */
|
|
1300 if (data_dir == 0)
|
|
1301 {
|
|
1302 Lisp_Object tem, tem1, newdir;
|
|
1303
|
|
1304 tem = Fexpand_file_name (build_string ("GNU"), Vdata_directory);
|
|
1305 tem1 = Ffile_exists_p (tem);
|
|
1306 if (NILP (tem1))
|
|
1307 {
|
|
1308 newdir = Fexpand_file_name (build_string ("../etc/"),
|
|
1309 build_string (PATH_DUMPLOADSEARCH));
|
|
1310 tem = Fexpand_file_name (build_string ("GNU"), newdir);
|
|
1311 tem1 = Ffile_exists_p (tem);
|
|
1312 if (!NILP (tem1))
|
|
1313 Vdata_directory = newdir;
|
|
1314 }
|
|
1315 }
|
296
|
1316
|
19498
|
1317 #ifndef CANNOT_DUMP
|
|
1318 if (initialized)
|
|
1319 #endif
|
|
1320 {
|
|
1321 tempdir = Fdirectory_file_name (Vexec_directory);
|
|
1322 if (access (XSTRING (tempdir)->data, 0) < 0)
|
|
1323 dir_warning ("Warning: arch-dependent data dir (%s) does not exist.\n",
|
|
1324 Vexec_directory);
|
|
1325 }
|
296
|
1326
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1327 tempdir = Fdirectory_file_name (Vdata_directory);
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1328 if (access (XSTRING (tempdir)->data, 0) < 0)
|
16486
|
1329 dir_warning ("Warning: arch-independent data dir (%s) does not exist.\n",
|
|
1330 Vdata_directory);
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1331
|
296
|
1332 #ifdef VMS
|
|
1333 Vshell_file_name = build_string ("*dcl*");
|
|
1334 #else
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1335 sh = (char *) getenv ("SHELL");
|
296
|
1336 Vshell_file_name = build_string (sh ? sh : "/bin/sh");
|
|
1337 #endif
|
16627
|
1338
|
|
1339 #ifdef VMS
|
|
1340 Vtemp_file_name_pattern = build_string ("tmp:emacsXXXXXX.");
|
|
1341 #else
|
|
1342 if (getenv ("TMPDIR"))
|
|
1343 {
|
|
1344 char *dir = getenv ("TMPDIR");
|
|
1345 Vtemp_file_name_pattern
|
|
1346 = Fexpand_file_name (build_string ("emacsXXXXXX"),
|
|
1347 build_string (dir));
|
|
1348 }
|
|
1349 else
|
|
1350 Vtemp_file_name_pattern = build_string ("/tmp/emacsXXXXXX");
|
|
1351 #endif
|
1912
|
1352 }
|
|
1353
|
21514
|
1354 void
|
1912
|
1355 set_process_environment ()
|
|
1356 {
|
|
1357 register char **envp;
|
296
|
1358
|
|
1359 Vprocess_environment = Qnil;
|
|
1360 #ifndef CANNOT_DUMP
|
|
1361 if (initialized)
|
|
1362 #endif
|
|
1363 for (envp = environ; *envp; envp++)
|
|
1364 Vprocess_environment = Fcons (build_string (*envp),
|
|
1365 Vprocess_environment);
|
|
1366 }
|
|
1367
|
21514
|
1368 void
|
296
|
1369 syms_of_callproc ()
|
|
1370 {
|
9786
|
1371 #ifdef DOS_NT
|
7397
|
1372 Qbuffer_file_type = intern ("buffer-file-type");
|
|
1373 staticpro (&Qbuffer_file_type);
|
9786
|
1374 #endif /* DOS_NT */
|
5501
|
1375
|
296
|
1376 DEFVAR_LISP ("shell-file-name", &Vshell_file_name,
|
|
1377 "*File name to load inferior shells from.\n\
|
|
1378 Initialized from the SHELL environment variable.");
|
|
1379
|
|
1380 DEFVAR_LISP ("exec-path", &Vexec_path,
|
|
1381 "*List of directories to search programs to run in subprocesses.\n\
|
|
1382 Each element is a string (directory name) or nil (try default directory).");
|
|
1383
|
|
1384 DEFVAR_LISP ("exec-directory", &Vexec_directory,
|
21209
|
1385 "Directory for executables for Emacs to invoke.\n\
|
|
1386 More generally, this includes any architecture-dependent files\n\
|
|
1387 that are built and installed from the Emacs distribution.");
|
439
|
1388
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1389 DEFVAR_LISP ("data-directory", &Vdata_directory,
|
21209
|
1390 "Directory of machine-independent files that come with GNU Emacs.\n\
|
|
1391 These are files intended for Emacs to use while it runs.");
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1392
|
6031
|
1393 DEFVAR_LISP ("doc-directory", &Vdoc_directory,
|
|
1394 "Directory containing the DOC file that comes with GNU Emacs.\n\
|
|
1395 This is usually the same as data-directory.");
|
|
1396
|
3064
|
1397 DEFVAR_LISP ("configure-info-directory", &Vconfigure_info_directory,
|
|
1398 "For internal use by the build procedure only.\n\
|
|
1399 This is the name of the directory in which the build procedure installed\n\
|
|
1400 Emacs's info files; the default value for Info-default-directory-list\n\
|
|
1401 includes this.");
|
|
1402 Vconfigure_info_directory = build_string (PATH_INFO);
|
|
1403
|
16627
|
1404 DEFVAR_LISP ("temp-file-name-pattern", &Vtemp_file_name_pattern,
|
|
1405 "Pattern for making names for temporary files.\n\
|
|
1406 This is used by `call-process-region'.");
|
19012
|
1407 /* This variable is initialized in init_callproc. */
|
16627
|
1408
|
296
|
1409 DEFVAR_LISP ("process-environment", &Vprocess_environment,
|
948
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1410 "List of environment variables for subprocesses to inherit.\n\
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1411 Each element should be a string of the form ENVVARNAME=VALUE.\n\
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1412 The environment which Emacs inherits is placed in this variable\n\
|
928ed74adf4f
Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
diff
changeset
|
1413 when Emacs starts.");
|
296
|
1414
|
|
1415 #ifndef VMS
|
|
1416 defsubr (&Scall_process);
|
1596
|
1417 defsubr (&Sgetenv);
|
296
|
1418 #endif
|
|
1419 defsubr (&Scall_process_region);
|
|
1420 }
|