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