(File Shadowing): New.
[emacs.git] / src / callproc.c
blobb29572bae0cc66e779da65a28bbfb82fe0baac74
1 /* Synchronous subprocess invocation for GNU Emacs.
2 Copyright (C) 1985,86,87,88,93,94,95,99,2000 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
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.
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.
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. */
22 #include <config.h>
23 #include <signal.h>
24 #include <errno.h>
25 #include <stdio.h>
27 extern int errno;
29 /* Define SIGCHLD as an alias for SIGCLD. */
31 #if !defined (SIGCHLD) && defined (SIGCLD)
32 #define SIGCHLD SIGCLD
33 #endif /* SIGCLD */
35 #include <sys/types.h>
37 #ifdef HAVE_UNISTD_H
38 #include <unistd.h>
39 #endif
41 #include <sys/file.h>
42 #ifdef USG5
43 #define INCLUDED_FCNTL
44 #include <fcntl.h>
45 #endif
47 #ifdef WINDOWSNT
48 #define NOMINMAX
49 #include <windows.h>
50 #include <stdlib.h> /* for proper declaration of environ */
51 #include <fcntl.h>
52 #include "w32.h"
53 #define _P_NOWAIT 1 /* from process.h */
54 #endif
56 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
57 #define INCLUDED_FCNTL
58 #include <fcntl.h>
59 #include <sys/stat.h>
60 #include <sys/param.h>
61 #include <errno.h>
62 #endif /* MSDOS */
64 #ifndef O_RDONLY
65 #define O_RDONLY 0
66 #endif
68 #ifndef O_WRONLY
69 #define O_WRONLY 1
70 #endif
72 #include "lisp.h"
73 #include "commands.h"
74 #include "buffer.h"
75 #include "charset.h"
76 #include "ccl.h"
77 #include "coding.h"
78 #include "composite.h"
79 #include <epaths.h>
80 #include "process.h"
81 #include "syssignal.h"
82 #include "systty.h"
84 #ifdef MSDOS
85 #include "msdos.h"
86 #endif
88 #ifdef VMS
89 extern noshare char **environ;
90 #else
91 extern char **environ;
92 #endif
94 #ifdef HAVE_SETPGID
95 #if !defined (USG) || defined (BSD_PGRPS)
96 #undef setpgrp
97 #define setpgrp setpgid
98 #endif
99 #endif
101 #define max(a, b) ((a) > (b) ? (a) : (b))
103 Lisp_Object Vexec_path, Vexec_directory, Vdata_directory, Vdoc_directory;
104 Lisp_Object Vconfigure_info_directory;
105 Lisp_Object Vtemp_file_name_pattern;
107 Lisp_Object Vshell_file_name;
109 Lisp_Object Vprocess_environment;
111 #ifdef DOS_NT
112 Lisp_Object Qbuffer_file_type;
113 #endif /* DOS_NT */
115 /* True iff we are about to fork off a synchronous process or if we
116 are waiting for it. */
117 int synch_process_alive;
119 /* Nonzero => this is a string explaining death of synchronous subprocess. */
120 char *synch_process_death;
122 /* If synch_process_death is zero,
123 this is exit code of synchronous subprocess. */
124 int synch_process_retcode;
126 extern Lisp_Object Vdoc_file_name;
128 extern Lisp_Object Vfile_name_coding_system, Vdefault_file_name_coding_system;
130 /* Clean up when exiting Fcall_process.
131 On MSDOS, delete the temporary file on any kind of termination.
132 On Unix, kill the process and any children on termination by signal. */
134 /* Nonzero if this is termination due to exit. */
135 static int call_process_exited;
137 #ifndef VMS /* VMS version is in vmsproc.c. */
139 static Lisp_Object
140 call_process_kill (fdpid)
141 Lisp_Object fdpid;
143 emacs_close (XFASTINT (Fcar (fdpid)));
144 EMACS_KILLPG (XFASTINT (Fcdr (fdpid)), SIGKILL);
145 synch_process_alive = 0;
146 return Qnil;
149 Lisp_Object
150 call_process_cleanup (fdpid)
151 Lisp_Object fdpid;
153 #if defined (MSDOS) || defined (macintosh)
154 /* for MSDOS fdpid is really (fd . tempfile) */
155 register Lisp_Object file;
156 file = Fcdr (fdpid);
157 emacs_close (XFASTINT (Fcar (fdpid)));
158 if (strcmp (XSTRING (file)-> data, NULL_DEVICE) != 0)
159 unlink (XSTRING (file)->data);
160 #else /* not MSDOS and not macintosh */
161 register int pid = XFASTINT (Fcdr (fdpid));
163 if (call_process_exited)
165 emacs_close (XFASTINT (Fcar (fdpid)));
166 return Qnil;
169 if (EMACS_KILLPG (pid, SIGINT) == 0)
171 int count = specpdl_ptr - specpdl;
172 record_unwind_protect (call_process_kill, fdpid);
173 message1 ("Waiting for process to die...(type C-g again to kill it instantly)");
174 immediate_quit = 1;
175 QUIT;
176 wait_for_termination (pid);
177 immediate_quit = 0;
178 specpdl_ptr = specpdl + count; /* Discard the unwind protect. */
179 message1 ("Waiting for process to die...done");
181 synch_process_alive = 0;
182 emacs_close (XFASTINT (Fcar (fdpid)));
183 #endif /* not MSDOS */
184 return Qnil;
187 DEFUN ("call-process", Fcall_process, Scall_process, 1, MANY, 0,
188 "Call PROGRAM synchronously in separate process.\n\
189 The remaining arguments are optional.\n\
190 The program's input comes from file INFILE (nil means `/dev/null').\n\
191 Insert output in BUFFER before point; t means current buffer;\n\
192 nil for BUFFER means discard it; 0 means discard and don't wait.\n\
193 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,\n\
194 REAL-BUFFER says what to do with standard output, as above,\n\
195 while STDERR-FILE says what to do with standard error in the child.\n\
196 STDERR-FILE may be nil (discard standard error output),\n\
197 t (mix it with ordinary output), or a file name string.\n\
199 Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted.\n\
200 Remaining arguments are strings passed as command arguments to PROGRAM.\n\
202 If BUFFER is 0, `call-process' returns immediately with value nil.\n\
203 Otherwise it waits for PROGRAM to terminate\n\
204 and returns a numeric exit status or a signal description string.\n\
205 If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
206 (nargs, args)
207 int nargs;
208 register Lisp_Object *args;
210 Lisp_Object infile, buffer, current_dir, display, path;
211 int fd[2];
212 int filefd;
213 register int pid;
214 char buf[16384];
215 char *bufptr = buf;
216 int bufsize = 16384;
217 int count = specpdl_ptr - specpdl;
219 register unsigned char **new_argv
220 = (unsigned char **) alloca ((max (2, nargs - 2)) * sizeof (char *));
221 struct buffer *old = current_buffer;
222 /* File to use for stderr in the child.
223 t means use same as standard output. */
224 Lisp_Object error_file;
225 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
226 char *outf, *tempfile;
227 int outfilefd;
228 #endif
229 #ifdef macintosh
230 char *tempfile;
231 int outfilefd;
232 #endif
233 #if 0
234 int mask;
235 #endif
236 struct coding_system process_coding; /* coding-system of process output */
237 struct coding_system argument_coding; /* coding-system of arguments */
238 /* Set to the return value of Ffind_operation_coding_system. */
239 Lisp_Object coding_systems;
241 /* Qt denotes that Ffind_operation_coding_system is not yet called. */
242 coding_systems = Qt;
244 CHECK_STRING (args[0], 0);
246 error_file = Qt;
248 #ifndef subprocesses
249 /* Without asynchronous processes we cannot have BUFFER == 0. */
250 if (nargs >= 3
251 && (INTEGERP (CONSP (args[2]) ? XCAR (args[2]) : args[2])))
252 error ("Operating system cannot handle asynchronous subprocesses");
253 #endif /* subprocesses */
255 /* Decide the coding-system for giving arguments. */
257 Lisp_Object val, *args2;
258 int i;
260 /* If arguments are supplied, we may have to encode them. */
261 if (nargs >= 5)
263 int must_encode = 0;
265 for (i = 4; i < nargs; i++)
266 CHECK_STRING (args[i], i);
268 for (i = 4; i < nargs; i++)
269 if (STRING_MULTIBYTE (args[i]))
270 must_encode = 1;
272 if (!NILP (Vcoding_system_for_write))
273 val = Vcoding_system_for_write;
274 else if (! must_encode)
275 val = Qnil;
276 else
278 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
279 args2[0] = Qcall_process;
280 for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
281 coding_systems = Ffind_operation_coding_system (nargs + 1, args2);
282 if (CONSP (coding_systems))
283 val = XCDR (coding_systems);
284 else if (CONSP (Vdefault_process_coding_system))
285 val = XCDR (Vdefault_process_coding_system);
286 else
287 val = Qnil;
289 setup_coding_system (Fcheck_coding_system (val), &argument_coding);
293 if (nargs >= 2 && ! NILP (args[1]))
295 infile = Fexpand_file_name (args[1], current_buffer->directory);
296 CHECK_STRING (infile, 1);
298 else
299 infile = build_string (NULL_DEVICE);
301 if (nargs >= 3)
303 buffer = args[2];
305 /* If BUFFER is a list, its meaning is
306 (BUFFER-FOR-STDOUT FILE-FOR-STDERR). */
307 if (CONSP (buffer))
309 if (CONSP (XCDR (buffer)))
311 Lisp_Object stderr_file;
312 stderr_file = XCAR (XCDR (buffer));
314 if (NILP (stderr_file) || EQ (Qt, stderr_file))
315 error_file = stderr_file;
316 else
317 error_file = Fexpand_file_name (stderr_file, Qnil);
320 buffer = XCAR (buffer);
323 if (!(EQ (buffer, Qnil)
324 || EQ (buffer, Qt)
325 || INTEGERP (buffer)))
327 Lisp_Object spec_buffer;
328 spec_buffer = buffer;
329 buffer = Fget_buffer_create (buffer);
330 /* Mention the buffer name for a better error message. */
331 if (NILP (buffer))
332 CHECK_BUFFER (spec_buffer, 2);
333 CHECK_BUFFER (buffer, 2);
336 else
337 buffer = Qnil;
339 /* Make sure that the child will be able to chdir to the current
340 buffer's current directory, or its unhandled equivalent. We
341 can't just have the child check for an error when it does the
342 chdir, since it's in a vfork.
344 We have to GCPRO around this because Fexpand_file_name,
345 Funhandled_file_name_directory, and Ffile_accessible_directory_p
346 might call a file name handling function. The argument list is
347 protected by the caller, so all we really have to worry about is
348 buffer. */
350 struct gcpro gcpro1, gcpro2, gcpro3;
352 current_dir = current_buffer->directory;
354 GCPRO3 (infile, buffer, current_dir);
356 current_dir
357 = expand_and_dir_to_file (Funhandled_file_name_directory (current_dir),
358 Qnil);
359 if (NILP (Ffile_accessible_directory_p (current_dir)))
360 report_file_error ("Setting current directory",
361 Fcons (current_buffer->directory, Qnil));
363 UNGCPRO;
366 display = nargs >= 4 ? args[3] : Qnil;
368 filefd = emacs_open (XSTRING (infile)->data, O_RDONLY, 0);
369 if (filefd < 0)
371 report_file_error ("Opening process input file", Fcons (infile, Qnil));
373 /* Search for program; barf if not found. */
375 struct gcpro gcpro1;
377 GCPRO1 (current_dir);
378 openp (Vexec_path, args[0], EXEC_SUFFIXES, &path, 1);
379 UNGCPRO;
381 if (NILP (path))
383 emacs_close (filefd);
384 report_file_error ("Searching for program", Fcons (args[0], Qnil));
386 new_argv[0] = XSTRING (path)->data;
387 if (nargs > 4)
389 register int i;
390 struct gcpro gcpro1, gcpro2, gcpro3;
392 GCPRO3 (infile, buffer, current_dir);
393 argument_coding.dst_multibyte = 0;
394 for (i = 4; i < nargs; i++)
396 argument_coding.src_multibyte = STRING_MULTIBYTE (args[i]);
397 if (CODING_REQUIRE_ENCODING (&argument_coding))
399 /* We must encode this argument. */
400 args[i] = encode_coding_string (args[i], &argument_coding, 1);
401 if (argument_coding.type == coding_type_ccl)
402 setup_ccl_program (&(argument_coding.spec.ccl.encoder), Qnil);
404 new_argv[i - 3] = XSTRING (args[i])->data;
406 UNGCPRO;
407 new_argv[nargs - 3] = 0;
409 else
410 new_argv[1] = 0;
412 #ifdef MSDOS /* MW, July 1993 */
413 if ((outf = egetenv ("TMPDIR")))
414 strcpy (tempfile = alloca (strlen (outf) + 20), outf);
415 else
417 tempfile = alloca (20);
418 *tempfile = '\0';
420 dostounix_filename (tempfile);
421 if (*tempfile == '\0' || tempfile[strlen (tempfile) - 1] != '/')
422 strcat (tempfile, "/");
423 strcat (tempfile, "detmp.XXX");
424 mktemp (tempfile);
426 outfilefd = creat (tempfile, S_IREAD | S_IWRITE);
427 if (outfilefd < 0)
429 emacs_close (filefd);
430 report_file_error ("Opening process output file",
431 Fcons (build_string (tempfile), Qnil));
433 fd[0] = filefd;
434 fd[1] = outfilefd;
435 #endif /* MSDOS */
437 #ifdef macintosh
438 /* Since we don't have pipes on the Mac, create a temporary file to
439 hold the output of the subprocess. */
440 tempfile = (char *) alloca (STRING_BYTES (XSTRING (Vtemp_file_name_pattern)) + 1);
441 bcopy (XSTRING (Vtemp_file_name_pattern)->data, tempfile,
442 STRING_BYTES (XSTRING (Vtemp_file_name_pattern)) + 1);
444 mktemp (tempfile);
446 outfilefd = creat (tempfile, S_IREAD | S_IWRITE);
447 if (outfilefd < 0)
449 close (filefd);
450 report_file_error ("Opening process output file",
451 Fcons (build_string (tempfile), Qnil));
453 fd[0] = filefd;
454 fd[1] = outfilefd;
455 #endif /* macintosh */
457 if (INTEGERP (buffer))
458 fd[1] = emacs_open (NULL_DEVICE, O_WRONLY, 0), fd[0] = -1;
459 else
461 #ifndef MSDOS
462 #ifndef macintosh
463 pipe (fd);
464 #endif
465 #endif
466 #if 0
467 /* Replaced by close_process_descs */
468 set_exclusive_use (fd[0]);
469 #endif
473 /* child_setup must clobber environ in systems with true vfork.
474 Protect it from permanent change. */
475 register char **save_environ = environ;
476 register int fd1 = fd[1];
477 int fd_error = fd1;
479 #if 0 /* Some systems don't have sigblock. */
480 mask = sigblock (sigmask (SIGCHLD));
481 #endif
483 /* Record that we're about to create a synchronous process. */
484 synch_process_alive = 1;
486 /* These vars record information from process termination.
487 Clear them now before process can possibly terminate,
488 to avoid timing error if process terminates soon. */
489 synch_process_death = 0;
490 synch_process_retcode = 0;
492 if (NILP (error_file))
493 fd_error = emacs_open (NULL_DEVICE, O_WRONLY, 0);
494 else if (STRINGP (error_file))
496 #ifdef DOS_NT
497 fd_error = emacs_open (XSTRING (error_file)->data,
498 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT,
499 S_IREAD | S_IWRITE);
500 #else /* not DOS_NT */
501 fd_error = creat (XSTRING (error_file)->data, 0666);
502 #endif /* not DOS_NT */
505 if (fd_error < 0)
507 emacs_close (filefd);
508 if (fd[0] != filefd)
509 emacs_close (fd[0]);
510 if (fd1 >= 0)
511 emacs_close (fd1);
512 #ifdef MSDOS
513 unlink (tempfile);
514 #endif
515 report_file_error ("Cannot redirect stderr",
516 Fcons ((NILP (error_file)
517 ? build_string (NULL_DEVICE) : error_file),
518 Qnil));
521 current_dir = ENCODE_FILE (current_dir);
523 #ifdef macintosh
525 /* Call run_mac_command in sysdep.c here directly instead of doing
526 a child_setup as for MSDOS and other platforms. Note that this
527 code does not handle passing the environment to the synchronous
528 Mac subprocess. */
529 char *infn, *outfn, *errfn, *currdn;
531 /* close these files so subprocess can write to them */
532 close (outfilefd);
533 if (fd_error != outfilefd)
534 close (fd_error);
535 fd1 = -1; /* No harm in closing that one! */
537 infn = XSTRING (infile)->data;
538 outfn = tempfile;
539 if (NILP (error_file))
540 errfn = NULL_DEVICE;
541 else if (EQ (Qt, error_file))
542 errfn = outfn;
543 else
544 errfn = XSTRING (error_file)->data;
545 currdn = XSTRING (current_dir)->data;
546 pid = run_mac_command (new_argv, currdn, infn, outfn, errfn);
548 /* Record that the synchronous process exited and note its
549 termination status. */
550 synch_process_alive = 0;
551 synch_process_retcode = pid;
552 if (synch_process_retcode < 0) /* means it couldn't be exec'ed */
554 synchronize_system_messages_locale ();
555 synch_process_death = strerror (errno);
558 /* Since CRLF is converted to LF within `decode_coding', we can
559 always open a file with binary mode. */
560 fd[0] = open (tempfile, O_BINARY);
561 if (fd[0] < 0)
563 unlink (tempfile);
564 close (filefd);
565 report_file_error ("Cannot re-open temporary file", Qnil);
568 #else /* not macintosh */
569 #ifdef MSDOS /* MW, July 1993 */
570 /* Note that on MSDOS `child_setup' actually returns the child process
571 exit status, not its PID, so we assign it to `synch_process_retcode'
572 below. */
573 pid = child_setup (filefd, outfilefd, fd_error, (char **) new_argv,
574 0, current_dir);
576 /* Record that the synchronous process exited and note its
577 termination status. */
578 synch_process_alive = 0;
579 synch_process_retcode = pid;
580 if (synch_process_retcode < 0) /* means it couldn't be exec'ed */
582 synchronize_system_messages_locale ();
583 synch_process_death = strerror (errno);
586 emacs_close (outfilefd);
587 if (fd_error != outfilefd)
588 emacs_close (fd_error);
589 fd1 = -1; /* No harm in closing that one! */
590 /* Since CRLF is converted to LF within `decode_coding', we can
591 always open a file with binary mode. */
592 fd[0] = emacs_open (tempfile, O_RDONLY | O_BINARY, 0);
593 if (fd[0] < 0)
595 unlink (tempfile);
596 emacs_close (filefd);
597 report_file_error ("Cannot re-open temporary file", Qnil);
599 #else /* not MSDOS */
600 #ifdef WINDOWSNT
601 pid = child_setup (filefd, fd1, fd_error, (char **) new_argv,
602 0, current_dir);
603 #else /* not WINDOWSNT */
604 pid = vfork ();
606 if (pid == 0)
608 if (fd[0] >= 0)
609 emacs_close (fd[0]);
610 #ifdef HAVE_SETSID
611 setsid ();
612 #endif
613 #if defined (USG) && !defined (BSD_PGRPS)
614 setpgrp ();
615 #else
616 setpgrp (pid, pid);
617 #endif /* USG */
618 child_setup (filefd, fd1, fd_error, (char **) new_argv,
619 0, current_dir);
621 #endif /* not WINDOWSNT */
623 /* The MSDOS case did this already. */
624 if (fd_error >= 0)
625 emacs_close (fd_error);
626 #endif /* not MSDOS */
627 #endif /* not macintosh */
629 environ = save_environ;
631 /* Close most of our fd's, but not fd[0]
632 since we will use that to read input from. */
633 emacs_close (filefd);
634 if (fd1 >= 0 && fd1 != fd_error)
635 emacs_close (fd1);
638 if (pid < 0)
640 if (fd[0] >= 0)
641 emacs_close (fd[0]);
642 report_file_error ("Doing vfork", Qnil);
645 if (INTEGERP (buffer))
647 if (fd[0] >= 0)
648 emacs_close (fd[0]);
649 #ifndef subprocesses
650 /* If Emacs has been built with asynchronous subprocess support,
651 we don't need to do this, I think because it will then have
652 the facilities for handling SIGCHLD. */
653 wait_without_blocking ();
654 #endif /* subprocesses */
655 return Qnil;
658 /* Enable sending signal if user quits below. */
659 call_process_exited = 0;
661 #if defined(MSDOS) || defined(macintosh)
662 /* MSDOS needs different cleanup information. */
663 record_unwind_protect (call_process_cleanup,
664 Fcons (make_number (fd[0]), build_string (tempfile)));
665 #else
666 record_unwind_protect (call_process_cleanup,
667 Fcons (make_number (fd[0]), make_number (pid)));
668 #endif /* not MSDOS and not macintosh */
671 if (BUFFERP (buffer))
672 Fset_buffer (buffer);
674 if (NILP (buffer))
676 /* If BUFFER is nil, we must read process output once and then
677 discard it, so setup coding system but with nil. */
678 setup_coding_system (Qnil, &process_coding);
680 else
682 Lisp_Object val, *args2;
684 val = Qnil;
685 if (!NILP (Vcoding_system_for_read))
686 val = Vcoding_system_for_read;
687 else
689 if (EQ (coding_systems, Qt))
691 int i;
693 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
694 args2[0] = Qcall_process;
695 for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
696 coding_systems
697 = Ffind_operation_coding_system (nargs + 1, args2);
699 if (CONSP (coding_systems))
700 val = XCAR (coding_systems);
701 else if (CONSP (Vdefault_process_coding_system))
702 val = XCAR (Vdefault_process_coding_system);
703 else
704 val = Qnil;
706 setup_coding_system (Fcheck_coding_system (val), &process_coding);
707 /* In unibyte mode, character code conversion should not take
708 place but EOL conversion should. So, setup raw-text or one
709 of the subsidiary according to the information just setup. */
710 if (NILP (current_buffer->enable_multibyte_characters)
711 && !NILP (val))
712 setup_raw_text_coding_system (&process_coding);
714 process_coding.src_multibyte = 0;
715 process_coding.dst_multibyte
716 = (BUFFERP (buffer)
717 ? ! NILP (XBUFFER (buffer)->enable_multibyte_characters)
718 : ! NILP (current_buffer->enable_multibyte_characters));
720 immediate_quit = 1;
721 QUIT;
724 register int nread;
725 int first = 1;
726 int total_read = 0;
727 int carryover = 0;
728 int display_on_the_fly = !NILP (display) && INTERACTIVE;
729 struct coding_system saved_coding;
730 int pt_orig = PT, pt_byte_orig = PT_BYTE;
731 int inserted;
733 saved_coding = process_coding;
734 if (process_coding.composing != COMPOSITION_DISABLED)
735 coding_allocate_composition_data (&process_coding, PT);
736 while (1)
738 /* Repeatedly read until we've filled as much as possible
739 of the buffer size we have. But don't read
740 less than 1024--save that for the next bufferful. */
741 nread = carryover;
742 while (nread < bufsize - 1024)
744 int this_read = emacs_read (fd[0], bufptr + nread,
745 bufsize - nread);
747 if (this_read < 0)
748 goto give_up;
750 if (this_read == 0)
752 process_coding.mode |= CODING_MODE_LAST_BLOCK;
753 break;
756 nread += this_read;
757 total_read += this_read;
759 if (display_on_the_fly)
760 break;
763 /* Now NREAD is the total amount of data in the buffer. */
764 immediate_quit = 0;
766 if (!NILP (buffer))
768 if (! CODING_MAY_REQUIRE_DECODING (&process_coding))
769 insert_1_both (bufptr, nread, nread, 0, 1, 0);
770 else
771 { /* We have to decode the input. */
772 int size;
773 char *decoding_buf;
775 repeat_decoding:
776 size = decoding_buffer_size (&process_coding, nread);
777 decoding_buf = (char *) xmalloc (size);
778 if (process_coding.cmp_data)
779 process_coding.cmp_data->char_offset = PT;
780 decode_coding (&process_coding, bufptr, decoding_buf,
781 nread, size);
782 if (display_on_the_fly
783 && saved_coding.type == coding_type_undecided
784 && process_coding.type != coding_type_undecided)
786 /* We have detected some coding system. But,
787 there's a possibility that the detection was
788 done by insufficient data. So, we give up
789 displaying on the fly. */
790 xfree (decoding_buf);
791 display_on_the_fly = 0;
792 process_coding = saved_coding;
793 carryover = nread;
794 continue;
796 if (process_coding.produced > 0)
797 insert_1_both (decoding_buf, process_coding.produced_char,
798 process_coding.produced, 0, 1, 0);
799 xfree (decoding_buf);
800 nread -= process_coding.consumed;
801 carryover = nread;
802 if (carryover > 0)
803 /* As CARRYOVER should not be that large, we had
804 better avoid overhead of bcopy. */
805 BCOPY_SHORT (bufptr + process_coding.consumed, bufptr,
806 carryover);
807 if (process_coding.result == CODING_FINISH_INSUFFICIENT_CMP)
809 /* The decoding ended because of insufficient data
810 area to record information about composition.
811 We must try decoding with additional data area
812 before reading more output for the process. */
813 coding_allocate_composition_data (&process_coding, PT);
814 goto repeat_decoding;
819 if (process_coding.mode & CODING_MODE_LAST_BLOCK)
820 break;
822 /* Make the buffer bigger as we continue to read more data,
823 but not past 64k. */
824 if (bufsize < 64 * 1024 && total_read > 32 * bufsize)
826 bufsize *= 2;
827 bufptr = (char *) alloca (bufsize);
830 if (!NILP (display) && INTERACTIVE)
832 if (first)
833 prepare_menu_bars ();
834 first = 0;
835 redisplay_preserve_echo_area ();
837 immediate_quit = 1;
838 QUIT;
840 give_up: ;
842 if (!NILP (buffer)
843 && process_coding.cmp_data)
845 coding_restore_composition (&process_coding, Fcurrent_buffer ());
846 coding_free_composition_data (&process_coding);
850 int post_read_count = specpdl_ptr - specpdl;
852 record_unwind_protect (save_excursion_restore, save_excursion_save ());
853 inserted = PT - pt_orig;
854 TEMP_SET_PT_BOTH (pt_orig, pt_byte_orig);
855 if (SYMBOLP (process_coding.post_read_conversion)
856 && !NILP (Ffboundp (process_coding.post_read_conversion)))
857 call1 (process_coding.post_read_conversion, make_number (inserted));
859 Vlast_coding_system_used = process_coding.symbol;
861 /* If the caller required, let the buffer inherit the
862 coding-system used to decode the process output. */
863 if (inherit_process_coding_system)
864 call1 (intern ("after-insert-file-set-buffer-file-coding-system"),
865 make_number (total_read));
867 unbind_to (post_read_count, Qnil);
871 /* Wait for it to terminate, unless it already has. */
872 wait_for_termination (pid);
874 immediate_quit = 0;
876 set_buffer_internal (old);
878 /* Don't kill any children that the subprocess may have left behind
879 when exiting. */
880 call_process_exited = 1;
882 unbind_to (count, Qnil);
884 if (synch_process_death)
885 return code_convert_string_norecord (build_string (synch_process_death),
886 Vlocale_coding_system, 0);
887 return make_number (synch_process_retcode);
889 #endif
891 static Lisp_Object
892 delete_temp_file (name)
893 Lisp_Object name;
895 /* Use Fdelete_file (indirectly) because that runs a file name handler.
896 We did that when writing the file, so we should do so when deleting. */
897 internal_delete_file (name);
898 return Qnil;
901 DEFUN ("call-process-region", Fcall_process_region, Scall_process_region,
902 3, MANY, 0,
903 "Send text from START to END to a synchronous process running PROGRAM.\n\
904 The remaining arguments are optional.\n\
905 Delete the text if fourth arg DELETE is non-nil.\n\
907 Insert output in BUFFER before point; t means current buffer;\n\
908 nil for BUFFER means discard it; 0 means discard and don't wait.\n\
909 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,\n\
910 REAL-BUFFER says what to do with standard output, as above,\n\
911 while STDERR-FILE says what to do with standard error in the child.\n\
912 STDERR-FILE may be nil (discard standard error output),\n\
913 t (mix it with ordinary output), or a file name string.\n\
915 Sixth arg DISPLAY non-nil means redisplay buffer as output is inserted.\n\
916 Remaining args are passed to PROGRAM at startup as command args.\n\
918 If BUFFER is nil, `call-process-region' returns immediately with value nil.\n\
919 Otherwise it waits for PROGRAM to terminate\n\
920 and returns a numeric exit status or a signal description string.\n\
921 If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
922 (nargs, args)
923 int nargs;
924 register Lisp_Object *args;
926 struct gcpro gcpro1;
927 Lisp_Object filename_string;
928 register Lisp_Object start, end;
929 int count = specpdl_ptr - specpdl;
930 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
931 Lisp_Object coding_systems;
932 Lisp_Object val, *args2;
933 int i;
934 #ifdef DOS_NT
935 char *tempfile;
936 char *outf = '\0';
938 if ((outf = egetenv ("TMPDIR"))
939 || (outf = egetenv ("TMP"))
940 || (outf = egetenv ("TEMP")))
941 strcpy (tempfile = alloca (strlen (outf) + 20), outf);
942 else
944 tempfile = alloca (20);
945 *tempfile = '\0';
947 if (!IS_DIRECTORY_SEP (tempfile[strlen (tempfile) - 1]))
948 strcat (tempfile, "/");
949 if ('/' == DIRECTORY_SEP)
950 dostounix_filename (tempfile);
951 else
952 unixtodos_filename (tempfile);
953 #ifdef WINDOWSNT
954 strcat (tempfile, "emXXXXXX");
955 #else
956 strcat (tempfile, "detmp.XXX");
957 #endif
958 #else /* not DOS_NT */
959 char *tempfile = (char *) alloca (STRING_BYTES (XSTRING (Vtemp_file_name_pattern)) + 1);
960 bcopy (XSTRING (Vtemp_file_name_pattern)->data, tempfile,
961 STRING_BYTES (XSTRING (Vtemp_file_name_pattern)) + 1);
962 #endif /* not DOS_NT */
964 coding_systems = Qt;
966 mktemp (tempfile);
968 filename_string = build_string (tempfile);
969 GCPRO1 (filename_string);
970 start = args[0];
971 end = args[1];
972 /* Decide coding-system of the contents of the temporary file. */
973 if (!NILP (Vcoding_system_for_write))
974 val = Vcoding_system_for_write;
975 else if (NILP (current_buffer->enable_multibyte_characters))
976 val = Qnil;
977 else
979 args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
980 args2[0] = Qcall_process_region;
981 for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
982 coding_systems = Ffind_operation_coding_system (nargs + 1, args2);
983 if (CONSP (coding_systems))
984 val = XCDR (coding_systems);
985 else if (CONSP (Vdefault_process_coding_system))
986 val = XCDR (Vdefault_process_coding_system);
987 else
988 val = Qnil;
992 int count1 = specpdl_ptr - specpdl;
994 specbind (intern ("coding-system-for-write"), val);
995 Fwrite_region (start, end, filename_string, Qnil, Qlambda, Qnil, Qnil);
997 unbind_to (count1, Qnil);
1000 /* Note that Fcall_process takes care of binding
1001 coding-system-for-read. */
1003 record_unwind_protect (delete_temp_file, filename_string);
1005 if (nargs > 3 && !NILP (args[3]))
1006 Fdelete_region (start, end);
1008 if (nargs > 3)
1010 args += 2;
1011 nargs -= 2;
1013 else
1015 args[0] = args[2];
1016 nargs = 2;
1018 args[1] = filename_string;
1020 RETURN_UNGCPRO (unbind_to (count, Fcall_process (nargs, args)));
1023 #ifndef VMS /* VMS version is in vmsproc.c. */
1025 static int relocate_fd ();
1027 /* This is the last thing run in a newly forked inferior
1028 either synchronous or asynchronous.
1029 Copy descriptors IN, OUT and ERR as descriptors 0, 1 and 2.
1030 Initialize inferior's priority, pgrp, connected dir and environment.
1031 then exec another program based on new_argv.
1033 This function may change environ for the superior process.
1034 Therefore, the superior process must save and restore the value
1035 of environ around the vfork and the call to this function.
1037 SET_PGRP is nonzero if we should put the subprocess into a separate
1038 process group.
1040 CURRENT_DIR is an elisp string giving the path of the current
1041 directory the subprocess should have. Since we can't really signal
1042 a decent error from within the child, this should be verified as an
1043 executable directory by the parent. */
1046 child_setup (in, out, err, new_argv, set_pgrp, current_dir)
1047 int in, out, err;
1048 register char **new_argv;
1049 int set_pgrp;
1050 Lisp_Object current_dir;
1052 char **env;
1053 char *pwd_var;
1054 #ifdef WINDOWSNT
1055 int cpid;
1056 HANDLE handles[3];
1057 #endif /* WINDOWSNT */
1059 int pid = getpid ();
1061 #ifdef SET_EMACS_PRIORITY
1063 extern int emacs_priority;
1065 if (emacs_priority < 0)
1066 nice (- emacs_priority);
1068 #endif
1070 #ifdef subprocesses
1071 /* Close Emacs's descriptors that this process should not have. */
1072 close_process_descs ();
1073 #endif
1074 /* DOS_NT isn't in a vfork, so if we are in the middle of load-file,
1075 we will lose if we call close_load_descs here. */
1076 #ifndef DOS_NT
1077 close_load_descs ();
1078 #endif
1080 /* Note that use of alloca is always safe here. It's obvious for systems
1081 that do not have true vfork or that have true (stack) alloca.
1082 If using vfork and C_ALLOCA it is safe because that changes
1083 the superior's static variables as if the superior had done alloca
1084 and will be cleaned up in the usual way. */
1086 register char *temp;
1087 register int i;
1089 i = STRING_BYTES (XSTRING (current_dir));
1090 #ifdef MSDOS
1091 /* MSDOS must have all environment variables malloc'ed, because
1092 low-level libc functions that launch subsidiary processes rely
1093 on that. */
1094 pwd_var = (char *) xmalloc (i + 6);
1095 #else
1096 pwd_var = (char *) alloca (i + 6);
1097 #endif
1098 temp = pwd_var + 4;
1099 bcopy ("PWD=", pwd_var, 4);
1100 bcopy (XSTRING (current_dir)->data, temp, i);
1101 if (!IS_DIRECTORY_SEP (temp[i - 1])) temp[i++] = DIRECTORY_SEP;
1102 temp[i] = 0;
1104 #ifndef DOS_NT
1105 /* We can't signal an Elisp error here; we're in a vfork. Since
1106 the callers check the current directory before forking, this
1107 should only return an error if the directory's permissions
1108 are changed between the check and this chdir, but we should
1109 at least check. */
1110 if (chdir (temp) < 0)
1111 _exit (errno);
1112 #endif
1114 #ifdef DOS_NT
1115 /* Get past the drive letter, so that d:/ is left alone. */
1116 if (i > 2 && IS_DEVICE_SEP (temp[1]) && IS_DIRECTORY_SEP (temp[2]))
1118 temp += 2;
1119 i -= 2;
1121 #endif
1123 /* Strip trailing slashes for PWD, but leave "/" and "//" alone. */
1124 while (i > 2 && IS_DIRECTORY_SEP (temp[i - 1]))
1125 temp[--i] = 0;
1128 /* Set `env' to a vector of the strings in Vprocess_environment. */
1130 register Lisp_Object tem;
1131 register char **new_env;
1132 register int new_length;
1134 new_length = 0;
1135 for (tem = Vprocess_environment;
1136 CONSP (tem) && STRINGP (XCAR (tem));
1137 tem = XCDR (tem))
1138 new_length++;
1140 /* new_length + 2 to include PWD and terminating 0. */
1141 env = new_env = (char **) alloca ((new_length + 2) * sizeof (char *));
1143 /* If we have a PWD envvar, pass one down,
1144 but with corrected value. */
1145 if (getenv ("PWD"))
1146 *new_env++ = pwd_var;
1148 /* Copy the Vprocess_environment strings into new_env. */
1149 for (tem = Vprocess_environment;
1150 CONSP (tem) && STRINGP (XCAR (tem));
1151 tem = XCDR (tem))
1153 char **ep = env;
1154 char *string = (char *) XSTRING (XCAR (tem))->data;
1155 /* See if this string duplicates any string already in the env.
1156 If so, don't put it in.
1157 When an env var has multiple definitions,
1158 we keep the definition that comes first in process-environment. */
1159 for (; ep != new_env; ep++)
1161 char *p = *ep, *q = string;
1162 while (1)
1164 if (*q == 0)
1165 /* The string is malformed; might as well drop it. */
1166 goto duplicate;
1167 if (*q != *p)
1168 break;
1169 if (*q == '=')
1170 goto duplicate;
1171 p++, q++;
1174 *new_env++ = string;
1175 duplicate: ;
1177 *new_env = 0;
1179 #ifdef WINDOWSNT
1180 prepare_standard_handles (in, out, err, handles);
1181 set_process_dir (XSTRING (current_dir)->data);
1182 #else /* not WINDOWSNT */
1183 /* Make sure that in, out, and err are not actually already in
1184 descriptors zero, one, or two; this could happen if Emacs is
1185 started with its standard in, out, or error closed, as might
1186 happen under X. */
1188 int oin = in, oout = out;
1190 /* We have to avoid relocating the same descriptor twice! */
1192 in = relocate_fd (in, 3);
1194 if (out == oin)
1195 out = in;
1196 else
1197 out = relocate_fd (out, 3);
1199 if (err == oin)
1200 err = in;
1201 else if (err == oout)
1202 err = out;
1203 else
1204 err = relocate_fd (err, 3);
1207 #ifndef MSDOS
1208 emacs_close (0);
1209 emacs_close (1);
1210 emacs_close (2);
1212 dup2 (in, 0);
1213 dup2 (out, 1);
1214 dup2 (err, 2);
1215 emacs_close (in);
1216 emacs_close (out);
1217 emacs_close (err);
1218 #endif /* not MSDOS */
1219 #endif /* not WINDOWSNT */
1221 #if defined(USG) && !defined(BSD_PGRPS)
1222 #ifndef SETPGRP_RELEASES_CTTY
1223 setpgrp (); /* No arguments but equivalent in this case */
1224 #endif
1225 #else
1226 setpgrp (pid, pid);
1227 #endif /* USG */
1228 /* setpgrp_of_tty is incorrect here; it uses input_fd. */
1229 EMACS_SET_TTY_PGRP (0, &pid);
1231 #ifdef vipc
1232 something missing here;
1233 #endif /* vipc */
1235 #ifdef MSDOS
1236 pid = run_msdos_command (new_argv, pwd_var + 4, in, out, err, env);
1237 xfree (pwd_var);
1238 if (pid == -1)
1239 /* An error occurred while trying to run the subprocess. */
1240 report_file_error ("Spawning child process", Qnil);
1241 return pid;
1242 #else /* not MSDOS */
1243 #ifdef WINDOWSNT
1244 /* Spawn the child. (See ntproc.c:Spawnve). */
1245 cpid = spawnve (_P_NOWAIT, new_argv[0], new_argv, env);
1246 reset_standard_handles (in, out, err, handles);
1247 if (cpid == -1)
1248 /* An error occurred while trying to spawn the process. */
1249 report_file_error ("Spawning child process", Qnil);
1250 return cpid;
1251 #else /* not WINDOWSNT */
1252 /* execvp does not accept an environment arg so the only way
1253 to pass this environment is to set environ. Our caller
1254 is responsible for restoring the ambient value of environ. */
1255 environ = env;
1256 execvp (new_argv[0], new_argv);
1258 emacs_write (1, "Can't exec program: ", 20);
1259 emacs_write (1, new_argv[0], strlen (new_argv[0]));
1260 emacs_write (1, "\n", 1);
1261 _exit (1);
1262 #endif /* not WINDOWSNT */
1263 #endif /* not MSDOS */
1266 /* Move the file descriptor FD so that its number is not less than MINFD.
1267 If the file descriptor is moved at all, the original is freed. */
1268 static int
1269 relocate_fd (fd, minfd)
1270 int fd, minfd;
1272 if (fd >= minfd)
1273 return fd;
1274 else
1276 int new = dup (fd);
1277 if (new == -1)
1279 char *message1 = "Error while setting up child: ";
1280 char *errmessage = strerror (errno);
1281 char *message2 = "\n";
1282 emacs_write (2, message1, strlen (message1));
1283 emacs_write (2, errmessage, strlen (errmessage));
1284 emacs_write (2, message2, strlen (message2));
1285 _exit (1);
1287 /* Note that we hold the original FD open while we recurse,
1288 to guarantee we'll get a new FD if we need it. */
1289 new = relocate_fd (new, minfd);
1290 emacs_close (fd);
1291 return new;
1295 static int
1296 getenv_internal (var, varlen, value, valuelen)
1297 char *var;
1298 int varlen;
1299 char **value;
1300 int *valuelen;
1302 Lisp_Object scan;
1304 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
1306 Lisp_Object entry;
1308 entry = XCAR (scan);
1309 if (STRINGP (entry)
1310 && STRING_BYTES (XSTRING (entry)) > varlen
1311 && XSTRING (entry)->data[varlen] == '='
1312 #ifdef WINDOWSNT
1313 /* NT environment variables are case insensitive. */
1314 && ! strnicmp (XSTRING (entry)->data, var, varlen)
1315 #else /* not WINDOWSNT */
1316 && ! bcmp (XSTRING (entry)->data, var, varlen)
1317 #endif /* not WINDOWSNT */
1320 *value = (char *) XSTRING (entry)->data + (varlen + 1);
1321 *valuelen = STRING_BYTES (XSTRING (entry)) - (varlen + 1);
1322 return 1;
1326 return 0;
1329 DEFUN ("getenv-internal", Fgetenv_internal, Sgetenv_internal, 1, 1, 0,
1330 "Return the value of environment variable VAR, as a string.\n\
1331 VAR should be a string. Value is nil if VAR is undefined in the environment.\n\
1332 This function consults the variable ``process-environment'' for its value.")
1333 (var)
1334 Lisp_Object var;
1336 char *value;
1337 int valuelen;
1339 CHECK_STRING (var, 0);
1340 if (getenv_internal (XSTRING (var)->data, STRING_BYTES (XSTRING (var)),
1341 &value, &valuelen))
1342 return make_string (value, valuelen);
1343 else
1344 return Qnil;
1347 /* A version of getenv that consults process_environment, easily
1348 callable from C. */
1349 char *
1350 egetenv (var)
1351 char *var;
1353 char *value;
1354 int valuelen;
1356 if (getenv_internal (var, strlen (var), &value, &valuelen))
1357 return value;
1358 else
1359 return 0;
1362 #endif /* not VMS */
1364 /* This is run before init_cmdargs. */
1366 void
1367 init_callproc_1 ()
1369 char *data_dir = egetenv ("EMACSDATA");
1370 char *doc_dir = egetenv ("EMACSDOC");
1372 Vdata_directory
1373 = Ffile_name_as_directory (build_string (data_dir ? data_dir
1374 : PATH_DATA));
1375 Vdoc_directory
1376 = Ffile_name_as_directory (build_string (doc_dir ? doc_dir
1377 : PATH_DOC));
1379 /* Check the EMACSPATH environment variable, defaulting to the
1380 PATH_EXEC path from epaths.h. */
1381 Vexec_path = decode_env_path ("EMACSPATH", PATH_EXEC);
1382 Vexec_directory = Ffile_name_as_directory (Fcar (Vexec_path));
1383 Vexec_path = nconc2 (decode_env_path ("PATH", ""), Vexec_path);
1386 /* This is run after init_cmdargs, when Vinstallation_directory is valid. */
1388 void
1389 init_callproc ()
1391 char *data_dir = egetenv ("EMACSDATA");
1393 register char * sh;
1394 Lisp_Object tempdir;
1396 if (!NILP (Vinstallation_directory))
1398 /* Add to the path the lib-src subdir of the installation dir. */
1399 Lisp_Object tem;
1400 tem = Fexpand_file_name (build_string ("lib-src"),
1401 Vinstallation_directory);
1402 #ifndef DOS_NT
1403 /* MSDOS uses wrapped binaries, so don't do this. */
1404 if (NILP (Fmember (tem, Vexec_path)))
1405 Vexec_path = nconc2 (Vexec_path, Fcons (tem, Qnil));
1407 Vexec_directory = Ffile_name_as_directory (tem);
1408 #endif /* not DOS_NT */
1410 /* Maybe use ../etc as well as ../lib-src. */
1411 if (data_dir == 0)
1413 tem = Fexpand_file_name (build_string ("etc"),
1414 Vinstallation_directory);
1415 Vdoc_directory = Ffile_name_as_directory (tem);
1419 /* Look for the files that should be in etc. We don't use
1420 Vinstallation_directory, because these files are never installed
1421 near the executable, and they are never in the build
1422 directory when that's different from the source directory.
1424 Instead, if these files are not in the nominal place, we try the
1425 source directory. */
1426 if (data_dir == 0)
1428 Lisp_Object tem, tem1, newdir;
1430 tem = Fexpand_file_name (build_string ("GNU"), Vdata_directory);
1431 tem1 = Ffile_exists_p (tem);
1432 if (NILP (tem1))
1434 newdir = Fexpand_file_name (build_string ("../etc/"),
1435 build_string (PATH_DUMPLOADSEARCH));
1436 tem = Fexpand_file_name (build_string ("GNU"), newdir);
1437 tem1 = Ffile_exists_p (tem);
1438 if (!NILP (tem1))
1439 Vdata_directory = newdir;
1443 #ifndef CANNOT_DUMP
1444 if (initialized)
1445 #endif
1447 tempdir = Fdirectory_file_name (Vexec_directory);
1448 if (access (XSTRING (tempdir)->data, 0) < 0)
1449 dir_warning ("Warning: arch-dependent data dir (%s) does not exist.\n",
1450 Vexec_directory);
1453 tempdir = Fdirectory_file_name (Vdata_directory);
1454 if (access (XSTRING (tempdir)->data, 0) < 0)
1455 dir_warning ("Warning: arch-independent data dir (%s) does not exist.\n",
1456 Vdata_directory);
1458 #ifdef VMS
1459 Vshell_file_name = build_string ("*dcl*");
1460 #else
1461 sh = (char *) getenv ("SHELL");
1462 Vshell_file_name = build_string (sh ? sh : "/bin/sh");
1463 #endif
1465 #ifdef VMS
1466 Vtemp_file_name_pattern = build_string ("tmp:emacsXXXXXX.");
1467 #else
1468 if (getenv ("TMPDIR"))
1470 char *dir = getenv ("TMPDIR");
1471 Vtemp_file_name_pattern
1472 = Fexpand_file_name (build_string ("emacsXXXXXX"),
1473 build_string (dir));
1475 else
1476 Vtemp_file_name_pattern = build_string ("/tmp/emacsXXXXXX");
1477 #endif
1480 void
1481 set_process_environment ()
1483 register char **envp;
1485 Vprocess_environment = Qnil;
1486 #ifndef CANNOT_DUMP
1487 if (initialized)
1488 #endif
1489 for (envp = environ; *envp; envp++)
1490 Vprocess_environment = Fcons (build_string (*envp),
1491 Vprocess_environment);
1494 void
1495 syms_of_callproc ()
1497 #ifdef DOS_NT
1498 Qbuffer_file_type = intern ("buffer-file-type");
1499 staticpro (&Qbuffer_file_type);
1500 #endif /* DOS_NT */
1502 DEFVAR_LISP ("shell-file-name", &Vshell_file_name,
1503 "*File name to load inferior shells from.\n\
1504 Initialized from the SHELL environment variable.");
1506 DEFVAR_LISP ("exec-path", &Vexec_path,
1507 "*List of directories to search programs to run in subprocesses.\n\
1508 Each element is a string (directory name) or nil (try default directory).");
1510 DEFVAR_LISP ("exec-directory", &Vexec_directory,
1511 "Directory for executables for Emacs to invoke.\n\
1512 More generally, this includes any architecture-dependent files\n\
1513 that are built and installed from the Emacs distribution.");
1515 DEFVAR_LISP ("data-directory", &Vdata_directory,
1516 "Directory of machine-independent files that come with GNU Emacs.\n\
1517 These are files intended for Emacs to use while it runs.");
1519 DEFVAR_LISP ("doc-directory", &Vdoc_directory,
1520 "Directory containing the DOC file that comes with GNU Emacs.\n\
1521 This is usually the same as data-directory.");
1523 DEFVAR_LISP ("configure-info-directory", &Vconfigure_info_directory,
1524 "For internal use by the build procedure only.\n\
1525 This is the name of the directory in which the build procedure installed\n\
1526 Emacs's info files; the default value for Info-default-directory-list\n\
1527 includes this.");
1528 Vconfigure_info_directory = build_string (PATH_INFO);
1530 DEFVAR_LISP ("temp-file-name-pattern", &Vtemp_file_name_pattern,
1531 "Pattern for making names for temporary files.\n\
1532 This is used by `call-process-region'.");
1533 /* This variable is initialized in init_callproc. */
1535 DEFVAR_LISP ("process-environment", &Vprocess_environment,
1536 "List of environment variables for subprocesses to inherit.\n\
1537 Each element should be a string of the form ENVVARNAME=VALUE.\n\
1538 The environment which Emacs inherits is placed in this variable\n\
1539 when Emacs starts.");
1541 #ifndef VMS
1542 defsubr (&Scall_process);
1543 defsubr (&Sgetenv_internal);
1544 #endif
1545 defsubr (&Scall_process_region);