1 /* Synchronous subprocess invocation for GNU Emacs.
2 Copyright (C) 1985-1988, 1993-1995, 1999-2013
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
24 #include <sys/types.h>
34 #include <sys/socket.h> /* for fcntl */
37 #define _P_NOWAIT 1 /* from process.h */
40 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
42 #include <sys/param.h>
46 #include "character.h"
50 #include "composite.h"
53 #include "syssignal.h"
56 #include "blockinput.h"
58 #include "termhooks.h"
68 /* Pattern used by call-process-region to make temp files. */
69 static Lisp_Object Vtemp_file_name_pattern
;
71 /* The next two variables are valid only while record-unwind-protect
72 is in place during call-process for a synchronous subprocess. At
73 other times, their contents are irrelevant. Doing this via static
74 C variables is more convenient than putting them into the arguments
75 of record-unwind-protect, as they need to be updated at randomish
76 times in the code, and Lisp cannot always store these values as
77 Emacs integers. It's safe to use static variables here, as the
78 code is never invoked reentrantly. */
80 /* If nonzero, a process-ID that has not been reaped. */
81 static pid_t synch_process_pid
;
83 /* If nonnegative, a file descriptor that has not been closed. */
84 static int synch_process_fd
;
89 block_child_signal (void)
92 sigemptyset (&blocked
);
93 sigaddset (&blocked
, SIGCHLD
);
94 pthread_sigmask (SIG_BLOCK
, &blocked
, 0);
97 /* Unblock SIGCHLD. */
100 unblock_child_signal (void)
102 pthread_sigmask (SIG_SETMASK
, &empty_mask
, 0);
105 /* If P is reapable, record it as a deleted process and kill it.
106 Do this in a critical section. Unless PID is wedged it will be
107 reaped on receipt of the first SIGCHLD after the critical section. */
110 record_kill_process (struct Lisp_Process
*p
)
112 block_child_signal ();
117 record_deleted_pid (p
->pid
);
118 kill (- p
->pid
, SIGKILL
);
121 unblock_child_signal ();
124 /* Clean up when exiting call_process_cleanup. */
127 call_process_kill (Lisp_Object ignored
)
129 if (synch_process_fd
>= 0)
130 emacs_close (synch_process_fd
);
132 if (synch_process_pid
)
134 struct Lisp_Process proc
;
136 proc
.pid
= synch_process_pid
;
137 record_kill_process (&proc
);
143 /* Clean up when exiting Fcall_process.
144 On MSDOS, delete the temporary file on any kind of termination.
145 On Unix, kill the process and any children on termination by signal. */
148 call_process_cleanup (Lisp_Object arg
)
151 Lisp_Object buffer
= Fcar (arg
);
152 Lisp_Object file
= Fcdr (arg
);
154 Lisp_Object buffer
= arg
;
157 Fset_buffer (buffer
);
160 /* If the process still exists, kill its process group. */
161 if (synch_process_pid
)
163 ptrdiff_t count
= SPECPDL_INDEX ();
164 kill (-synch_process_pid
, SIGINT
);
165 record_unwind_protect (call_process_kill
, make_number (0));
166 message1 ("Waiting for process to die...(type C-g again to kill it instantly)");
169 wait_for_termination (synch_process_pid
, 0, 1);
170 synch_process_pid
= 0;
172 specpdl_ptr
= specpdl
+ count
; /* Discard the unwind protect. */
173 message1 ("Waiting for process to die...done");
177 if (synch_process_fd
>= 0)
178 emacs_close (synch_process_fd
);
181 /* FILE is "" when we didn't actually create a temporary file in
183 if (!(strcmp (SDATA (file
), NULL_DEVICE
) == 0 || SREF (file
, 0) == '\0'))
184 unlink (SDATA (file
));
191 static mode_t
const default_output_mode
= S_IREAD
| S_IWRITE
;
193 static mode_t
const default_output_mode
= 0666;
196 DEFUN ("call-process", Fcall_process
, Scall_process
, 1, MANY
, 0,
197 doc
: /* Call PROGRAM synchronously in separate process.
198 The remaining arguments are optional.
199 The program's input comes from file INFILE (nil means `/dev/null').
200 Insert output in DESTINATION before point; t means current buffer; nil for DESTINATION
201 means discard it; 0 means discard and don't wait; and `(:file FILE)', where
202 FILE is a file name string, means that it should be written to that file
203 \(if the file already exists it is overwritten).
204 DESTINATION can also have the form (REAL-BUFFER STDERR-FILE); in that case,
205 REAL-BUFFER says what to do with standard output, as above,
206 while STDERR-FILE says what to do with standard error in the child.
207 STDERR-FILE may be nil (discard standard error output),
208 t (mix it with ordinary output), or a file name string.
210 Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted.
211 Remaining arguments are strings passed as command arguments to PROGRAM.
213 If executable PROGRAM can't be found as an executable, `call-process'
214 signals a Lisp error. `call-process' reports errors in execution of
215 the program only through its return and output.
217 If DESTINATION is 0, `call-process' returns immediately with value nil.
218 Otherwise it waits for PROGRAM to terminate
219 and returns a numeric exit status or a signal description string.
220 If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.
222 usage: (call-process PROGRAM &optional INFILE DESTINATION DISPLAY &rest ARGS) */)
223 (ptrdiff_t nargs
, Lisp_Object
*args
)
225 Lisp_Object infile
, buffer
, current_dir
, path
;
227 int fd0
, fd1
, filefd
;
229 ptrdiff_t count
= SPECPDL_INDEX ();
233 /* File to use for stderr in the child.
234 t means use same as standard output. */
235 Lisp_Object error_file
;
236 Lisp_Object output_file
= Qnil
;
237 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
238 char *outf
, *tempfile
= NULL
;
246 struct coding_system process_coding
; /* coding-system of process output */
247 struct coding_system argument_coding
; /* coding-system of arguments */
248 /* Set to the return value of Ffind_operation_coding_system. */
249 Lisp_Object coding_systems
;
250 bool output_to_buffer
= 1;
252 /* Qt denotes that Ffind_operation_coding_system is not yet called. */
255 CHECK_STRING (args
[0]);
260 /* Without asynchronous processes we cannot have BUFFER == 0. */
262 && (INTEGERP (CONSP (args
[2]) ? XCAR (args
[2]) : args
[2])))
263 error ("Operating system cannot handle asynchronous subprocesses");
264 #endif /* subprocesses */
266 /* Decide the coding-system for giving arguments. */
268 Lisp_Object val
, *args2
;
271 /* If arguments are supplied, we may have to encode them. */
274 bool must_encode
= 0;
275 Lisp_Object coding_attrs
;
277 for (i
= 4; i
< nargs
; i
++)
278 CHECK_STRING (args
[i
]);
280 for (i
= 4; i
< nargs
; i
++)
281 if (STRING_MULTIBYTE (args
[i
]))
284 if (!NILP (Vcoding_system_for_write
))
285 val
= Vcoding_system_for_write
;
286 else if (! must_encode
)
290 SAFE_NALLOCA (args2
, 1, nargs
+ 1);
291 args2
[0] = Qcall_process
;
292 for (i
= 0; i
< nargs
; i
++) args2
[i
+ 1] = args
[i
];
293 coding_systems
= Ffind_operation_coding_system (nargs
+ 1, args2
);
294 val
= CONSP (coding_systems
) ? XCDR (coding_systems
) : Qnil
;
296 val
= complement_process_encoding_system (val
);
297 setup_coding_system (Fcheck_coding_system (val
), &argument_coding
);
298 coding_attrs
= CODING_ID_ATTRS (argument_coding
.id
);
299 if (NILP (CODING_ATTR_ASCII_COMPAT (coding_attrs
)))
301 /* We should not use an ASCII incompatible coding system. */
302 val
= raw_text_coding_system (val
);
303 setup_coding_system (val
, &argument_coding
);
308 if (nargs
>= 2 && ! NILP (args
[1]))
310 infile
= Fexpand_file_name (args
[1], BVAR (current_buffer
, directory
));
311 CHECK_STRING (infile
);
314 infile
= build_string (NULL_DEVICE
);
320 /* If BUFFER is a list, its meaning is (BUFFER-FOR-STDOUT
321 FILE-FOR-STDERR), unless the first element is :file, in which case see
322 the next paragraph. */
324 && (! SYMBOLP (XCAR (buffer
))
325 || strcmp (SSDATA (SYMBOL_NAME (XCAR (buffer
))), ":file")))
327 if (CONSP (XCDR (buffer
)))
329 Lisp_Object stderr_file
;
330 stderr_file
= XCAR (XCDR (buffer
));
332 if (NILP (stderr_file
) || EQ (Qt
, stderr_file
))
333 error_file
= stderr_file
;
335 error_file
= Fexpand_file_name (stderr_file
, Qnil
);
338 buffer
= XCAR (buffer
);
341 /* If the buffer is (still) a list, it might be a (:file "file") spec. */
343 && SYMBOLP (XCAR (buffer
))
344 && ! strcmp (SSDATA (SYMBOL_NAME (XCAR (buffer
))), ":file"))
346 output_file
= Fexpand_file_name (XCAR (XCDR (buffer
)),
347 BVAR (current_buffer
, directory
));
348 CHECK_STRING (output_file
);
352 if (!(EQ (buffer
, Qnil
)
354 || INTEGERP (buffer
)))
356 Lisp_Object spec_buffer
;
357 spec_buffer
= buffer
;
358 buffer
= Fget_buffer_create (buffer
);
359 /* Mention the buffer name for a better error message. */
361 CHECK_BUFFER (spec_buffer
);
362 CHECK_BUFFER (buffer
);
368 /* Make sure that the child will be able to chdir to the current
369 buffer's current directory, or its unhandled equivalent. We
370 can't just have the child check for an error when it does the
371 chdir, since it's in a vfork.
373 We have to GCPRO around this because Fexpand_file_name,
374 Funhandled_file_name_directory, and Ffile_accessible_directory_p
375 might call a file name handling function. The argument list is
376 protected by the caller, so all we really have to worry about is
379 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
381 current_dir
= BVAR (current_buffer
, directory
);
383 GCPRO5 (infile
, buffer
, current_dir
, error_file
, output_file
);
385 current_dir
= Funhandled_file_name_directory (current_dir
);
386 if (NILP (current_dir
))
387 /* If the file name handler says that current_dir is unreachable, use
388 a sensible default. */
389 current_dir
= build_string ("~/");
390 current_dir
= expand_and_dir_to_file (current_dir
, Qnil
);
391 current_dir
= Ffile_name_as_directory (current_dir
);
393 if (NILP (Ffile_accessible_directory_p (current_dir
)))
394 report_file_error ("Setting current directory",
395 BVAR (current_buffer
, directory
));
397 if (STRING_MULTIBYTE (infile
))
398 infile
= ENCODE_FILE (infile
);
399 if (STRING_MULTIBYTE (current_dir
))
400 current_dir
= ENCODE_FILE (current_dir
);
401 if (STRINGP (error_file
) && STRING_MULTIBYTE (error_file
))
402 error_file
= ENCODE_FILE (error_file
);
403 if (STRINGP (output_file
) && STRING_MULTIBYTE (output_file
))
404 output_file
= ENCODE_FILE (output_file
);
408 display_p
= INTERACTIVE
&& nargs
>= 4 && !NILP (args
[3]);
410 filefd
= emacs_open (SSDATA (infile
), O_RDONLY
, 0);
412 report_file_error ("Opening process input file", DECODE_FILE (infile
));
414 if (STRINGP (output_file
))
416 fd_output
= emacs_open (SSDATA (output_file
),
417 O_WRONLY
| O_CREAT
| O_TRUNC
| O_TEXT
,
418 default_output_mode
);
421 int open_errno
= errno
;
422 output_file
= DECODE_FILE (output_file
);
423 report_file_errno ("Opening process output file",
424 output_file
, open_errno
);
426 if (STRINGP (error_file
) || NILP (error_file
))
427 output_to_buffer
= 0;
430 /* Search for program; barf if not found. */
432 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
435 GCPRO4 (infile
, buffer
, current_dir
, error_file
);
436 ok
= openp (Vexec_path
, args
[0], Vexec_suffixes
, &path
, make_number (X_OK
));
440 int openp_errno
= errno
;
441 emacs_close (filefd
);
442 report_file_errno ("Searching for program", args
[0], openp_errno
);
446 /* If program file name starts with /: for quoting a magic name,
448 if (SBYTES (path
) > 2 && SREF (path
, 0) == '/'
449 && SREF (path
, 1) == ':')
450 path
= Fsubstring (path
, make_number (2), Qnil
);
452 new_argv
= SAFE_ALLOCA ((nargs
> 4 ? nargs
- 2 : 2) * sizeof *new_argv
);
455 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
457 GCPRO5 (infile
, buffer
, current_dir
, path
, error_file
);
462 argument_coding
.dst_multibyte
= 0;
463 for (i
= 4; i
< nargs
; i
++)
465 argument_coding
.src_multibyte
= STRING_MULTIBYTE (args
[i
]);
466 if (CODING_REQUIRE_ENCODING (&argument_coding
))
467 /* We must encode this argument. */
468 args
[i
] = encode_coding_string (&argument_coding
, args
[i
], 1);
470 for (i
= 4; i
< nargs
; i
++)
471 new_argv
[i
- 3] = SSDATA (args
[i
]);
476 if (STRING_MULTIBYTE (path
))
477 path
= ENCODE_FILE (path
);
478 new_argv
[0] = SSDATA (path
);
482 #ifdef MSDOS /* MW, July 1993 */
484 /* If we're redirecting STDOUT to a file, that file is already open
488 if ((outf
= egetenv ("TMPDIR")))
489 strcpy (tempfile
= alloca (strlen (outf
) + 20), outf
);
492 tempfile
= alloca (20);
495 dostounix_filename (tempfile
, 0);
496 if (*tempfile
== '\0' || tempfile
[strlen (tempfile
) - 1] != '/')
497 strcat (tempfile
, "/");
498 strcat (tempfile
, "detmp.XXX");
500 outfilefd
= emacs_open (tempfile
, O_WRONLY
| O_CREAT
| O_TRUNC
,
504 int open_errno
= errno
;
505 emacs_close (filefd
);
506 report_file_errno ("Opening process output file",
507 build_string (tempfile
), open_errno
);
511 outfilefd
= fd_output
;
516 if (INTEGERP (buffer
))
519 fd1
= emacs_open (NULL_DEVICE
, O_WRONLY
, 0);
525 if (emacs_pipe (fd
) != 0)
527 int pipe_errno
= errno
;
528 emacs_close (filefd
);
529 report_file_errno ("Creating process pipe", Qnil
, pipe_errno
);
542 if (NILP (error_file
))
543 fd_error
= emacs_open (NULL_DEVICE
, O_WRONLY
, 0);
544 else if (STRINGP (error_file
))
545 fd_error
= emacs_open (SSDATA (error_file
),
546 O_WRONLY
| O_CREAT
| O_TRUNC
| O_TEXT
,
547 default_output_mode
);
551 int open_errno
= errno
;
552 emacs_close (filefd
);
560 if (NILP (error_file
))
561 error_file
= build_string (NULL_DEVICE
);
562 else if (STRINGP (error_file
))
563 error_file
= DECODE_FILE (error_file
);
564 report_file_errno ("Cannot redirect stderr", error_file
, open_errno
);
567 #ifdef MSDOS /* MW, July 1993 */
568 /* Note that on MSDOS `child_setup' actually returns the child process
569 exit status, not its PID, so assign it to status below. */
570 pid
= child_setup (filefd
, outfilefd
, fd_error
, new_argv
, 0, current_dir
);
573 emacs_close (outfilefd
);
574 if (fd_error
!= outfilefd
)
575 emacs_close (fd_error
);
578 synchronize_system_messages_locale ();
580 code_convert_string_norecord (build_string (strerror (child_errno
)),
581 Vlocale_coding_system
, 0);
584 fd1
= -1; /* No harm in closing that one! */
587 /* Since CRLF is converted to LF within `decode_coding', we
588 can always open a file with binary mode. */
589 fd0
= emacs_open (tempfile
, O_RDONLY
| O_BINARY
, 0);
592 int open_errno
= errno
;
594 emacs_close (filefd
);
595 report_file_errno ("Cannot re-open temporary file",
596 build_string (tempfile
), open_errno
);
600 fd0
= -1; /* We are not going to read from tempfile. */
603 /* Do the unwind-protect now, even though the pid is not known, so
604 that no storage allocation is done in the critical section.
605 The actual PID will be filled in during the critical section. */
606 synch_process_pid
= 0;
607 synch_process_fd
= fd0
;
610 /* MSDOS needs different cleanup information. */
611 record_unwind_protect (call_process_cleanup
,
612 Fcons (Fcurrent_buffer (),
613 build_string (tempfile
? tempfile
: "")));
615 record_unwind_protect (call_process_cleanup
, Fcurrent_buffer ());
618 block_child_signal ();
621 pid
= child_setup (filefd
, fd1
, fd_error
, new_argv
, 0, current_dir
);
622 /* We need to record the input file of this child, for when we are
623 called from call-process-region to create an async subprocess.
624 That's because call-process-region's unwind procedure will
625 attempt to delete the temporary input file, which will fail
626 because that file is still in use. Recording it with the child
627 will allow us to delete the file when the subprocess exits.
628 The second part of this is in delete_temp_file, q.v. */
629 if (pid
> 0 && INTEGERP (buffer
) && nargs
>= 2 && !NILP (args
[1]))
630 record_infile (pid
, xstrdup (SSDATA (infile
)));
631 #else /* not WINDOWSNT */
633 /* vfork, and prevent local vars from being clobbered by the vfork. */
635 Lisp_Object
volatile buffer_volatile
= buffer
;
636 Lisp_Object
volatile coding_systems_volatile
= coding_systems
;
637 Lisp_Object
volatile current_dir_volatile
= current_dir
;
638 bool volatile display_p_volatile
= display_p
;
639 bool volatile output_to_buffer_volatile
= output_to_buffer
;
640 bool volatile sa_must_free_volatile
= sa_must_free
;
641 int volatile fd1_volatile
= fd1
;
642 int volatile fd_error_volatile
= fd_error
;
643 int volatile fd_output_volatile
= fd_output
;
644 int volatile filefd_volatile
= filefd
;
645 ptrdiff_t volatile count_volatile
= count
;
646 ptrdiff_t volatile sa_count_volatile
= sa_count
;
647 char **volatile new_argv_volatile
= new_argv
;
652 buffer
= buffer_volatile
;
653 coding_systems
= coding_systems_volatile
;
654 current_dir
= current_dir_volatile
;
655 display_p
= display_p_volatile
;
656 output_to_buffer
= output_to_buffer_volatile
;
657 sa_must_free
= sa_must_free_volatile
;
659 fd_error
= fd_error_volatile
;
660 fd_output
= fd_output_volatile
;
661 filefd
= filefd_volatile
;
662 count
= count_volatile
;
663 sa_count
= sa_count_volatile
;
664 new_argv
= new_argv_volatile
;
666 fd0
= synch_process_fd
;
671 unblock_child_signal ();
678 /* Emacs ignores SIGPIPE, but the child should not. */
679 signal (SIGPIPE
, SIG_DFL
);
681 child_setup (filefd
, fd1
, fd_error
, new_argv
, 0, current_dir
);
684 #endif /* not WINDOWSNT */
690 if (INTEGERP (buffer
))
691 record_deleted_pid (pid
);
693 synch_process_pid
= pid
;
696 unblock_child_signal ();
699 /* The MSDOS case did this already. */
701 emacs_close (fd_error
);
702 #endif /* not MSDOS */
704 /* Close most of our file descriptors, but not fd0
705 since we will use that to read input from. */
706 emacs_close (filefd
);
708 emacs_close (fd_output
);
709 if (fd1
>= 0 && fd1
!= fd_error
)
714 report_file_errno ("Doing vfork", Qnil
, child_errno
);
716 if (INTEGERP (buffer
))
717 return unbind_to (count
, Qnil
);
719 if (BUFFERP (buffer
))
720 Fset_buffer (buffer
);
724 /* If BUFFER is nil, we must read process output once and then
725 discard it, so setup coding system but with nil. */
726 setup_coding_system (Qnil
, &process_coding
);
727 process_coding
.dst_multibyte
= 0;
731 Lisp_Object val
, *args2
;
734 if (!NILP (Vcoding_system_for_read
))
735 val
= Vcoding_system_for_read
;
738 if (EQ (coding_systems
, Qt
))
742 SAFE_NALLOCA (args2
, 1, nargs
+ 1);
743 args2
[0] = Qcall_process
;
744 for (i
= 0; i
< nargs
; i
++) args2
[i
+ 1] = args
[i
];
746 = Ffind_operation_coding_system (nargs
+ 1, args2
);
748 if (CONSP (coding_systems
))
749 val
= XCAR (coding_systems
);
750 else if (CONSP (Vdefault_process_coding_system
))
751 val
= XCAR (Vdefault_process_coding_system
);
755 Fcheck_coding_system (val
);
756 /* In unibyte mode, character code conversion should not take
757 place but EOL conversion should. So, setup raw-text or one
758 of the subsidiary according to the information just setup. */
759 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
))
761 val
= raw_text_coding_system (val
);
762 setup_coding_system (val
, &process_coding
);
763 process_coding
.dst_multibyte
764 = ! NILP (BVAR (current_buffer
, enable_multibyte_characters
));
766 process_coding
.src_multibyte
= 0;
771 if (output_to_buffer
)
773 enum { CALLPROC_BUFFER_SIZE_MIN
= 16 * 1024 };
774 enum { CALLPROC_BUFFER_SIZE_MAX
= 4 * CALLPROC_BUFFER_SIZE_MIN
};
775 char buf
[CALLPROC_BUFFER_SIZE_MAX
];
776 int bufsize
= CALLPROC_BUFFER_SIZE_MIN
;
779 EMACS_INT total_read
= 0;
781 bool display_on_the_fly
= display_p
;
782 struct coding_system saved_coding
;
784 saved_coding
= process_coding
;
787 /* Repeatedly read until we've filled as much as possible
788 of the buffer size we have. But don't read
789 less than 1024--save that for the next bufferful. */
791 while (nread
< bufsize
- 1024)
793 int this_read
= emacs_read (fd0
, buf
+ nread
,
801 process_coding
.mode
|= CODING_MODE_LAST_BLOCK
;
806 total_read
+= this_read
;
808 if (display_on_the_fly
)
812 /* Now NREAD is the total amount of data in the buffer. */
817 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
))
818 && ! CODING_MAY_REQUIRE_DECODING (&process_coding
))
819 insert_1_both (buf
, nread
, nread
, 0, 1, 0);
821 { /* We have to decode the input. */
823 ptrdiff_t count1
= SPECPDL_INDEX ();
825 XSETBUFFER (curbuf
, current_buffer
);
826 /* We cannot allow after-change-functions be run
827 during decoding, because that might modify the
828 buffer, while we rely on process_coding.produced to
829 faithfully reflect inserted text until we
830 TEMP_SET_PT_BOTH below. */
831 specbind (Qinhibit_modification_hooks
, Qt
);
832 decode_coding_c_string (&process_coding
,
833 (unsigned char *) buf
, nread
, curbuf
);
834 unbind_to (count1
, Qnil
);
835 if (display_on_the_fly
836 && CODING_REQUIRE_DETECTION (&saved_coding
)
837 && ! CODING_REQUIRE_DETECTION (&process_coding
))
839 /* We have detected some coding system. But,
840 there's a possibility that the detection was
841 done by insufficient data. So, we give up
842 displaying on the fly. */
843 if (process_coding
.produced
> 0)
844 del_range_2 (process_coding
.dst_pos
,
845 process_coding
.dst_pos_byte
,
846 process_coding
.dst_pos
847 + process_coding
.produced_char
,
848 process_coding
.dst_pos_byte
849 + process_coding
.produced
, 0);
850 display_on_the_fly
= 0;
851 process_coding
= saved_coding
;
853 /* This is to make the above condition always
854 fails in the future. */
855 saved_coding
.common_flags
856 &= ~CODING_REQUIRE_DETECTION_MASK
;
860 TEMP_SET_PT_BOTH (PT
+ process_coding
.produced_char
,
861 PT_BYTE
+ process_coding
.produced
);
862 carryover
= process_coding
.carryover_bytes
;
864 memcpy (buf
, process_coding
.carryover
,
865 process_coding
.carryover_bytes
);
869 if (process_coding
.mode
& CODING_MODE_LAST_BLOCK
)
872 /* Make the buffer bigger as we continue to read more data,
873 but not past CALLPROC_BUFFER_SIZE_MAX. */
874 if (bufsize
< CALLPROC_BUFFER_SIZE_MAX
&& total_read
> 32 * bufsize
)
875 if ((bufsize
*= 2) > CALLPROC_BUFFER_SIZE_MAX
)
876 bufsize
= CALLPROC_BUFFER_SIZE_MAX
;
881 prepare_menu_bars ();
883 redisplay_preserve_echo_area (1);
884 /* This variable might have been set to 0 for code
885 detection. In that case, we set it back to 1 because
886 we should have already detected a coding system. */
887 display_on_the_fly
= 1;
894 Vlast_coding_system_used
= CODING_ID_NAME (process_coding
.id
);
895 /* If the caller required, let the buffer inherit the
896 coding-system used to decode the process output. */
897 if (inherit_process_coding_system
)
898 call1 (intern ("after-insert-file-set-buffer-file-coding-system"),
899 make_number (total_read
));
903 /* Wait for it to terminate, unless it already has. */
904 wait_for_termination (pid
, &status
, !output_to_buffer
);
909 /* Don't kill any children that the subprocess may have left behind
911 synch_process_pid
= 0;
914 unbind_to (count
, Qnil
);
916 if (WIFSIGNALED (status
))
920 synchronize_system_messages_locale ();
921 signame
= strsignal (WTERMSIG (status
));
926 return code_convert_string_norecord (build_string (signame
),
927 Vlocale_coding_system
, 0);
930 eassert (WIFEXITED (status
));
931 return make_number (WEXITSTATUS (status
));
935 delete_temp_file (Lisp_Object name
)
937 /* Suppress jka-compr handling, etc. */
938 ptrdiff_t count
= SPECPDL_INDEX ();
939 specbind (intern ("file-name-handler-alist"), Qnil
);
941 /* If this is called when the subprocess didn't exit yet, the
942 attempt to delete its input file will fail. In that case, we
943 schedule the file for deletion when the subprocess exits. This
944 is the 2nd part of handling this situation; see the call to
945 record_infile in call-process above, for the first part. */
946 if (!internal_delete_file (name
))
948 Lisp_Object encoded_file
= ENCODE_FILE (name
);
950 record_pending_deletion (SSDATA (encoded_file
));
953 internal_delete_file (name
);
955 unbind_to (count
, Qnil
);
959 /* Create a temporary file suitable for storing the input data of
960 call-process-region. NARGS and ARGS are the same as for
961 call-process-region. */
964 create_temp_file (ptrdiff_t nargs
, Lisp_Object
*args
)
967 Lisp_Object filename_string
;
968 Lisp_Object val
, start
, end
;
971 if (STRINGP (Vtemporary_file_directory
))
972 tmpdir
= Vtemporary_file_directory
;
977 outf
= getenv ("TMPDIR");
978 tmpdir
= build_string (outf
? outf
: "/tmp/");
980 if ((outf
= egetenv ("TMPDIR"))
981 || (outf
= egetenv ("TMP"))
982 || (outf
= egetenv ("TEMP")))
983 tmpdir
= build_string (outf
);
985 tmpdir
= Ffile_name_as_directory (build_string ("c:/temp"));
990 Lisp_Object pattern
= Fexpand_file_name (Vtemp_file_name_pattern
, tmpdir
);
994 /* Cannot use the result of Fexpand_file_name, because it
995 downcases the XXXXXX part of the pattern, and mktemp then
996 doesn't recognize it. */
997 if (!NILP (Vw32_downcase_file_names
))
999 Lisp_Object dirname
= Ffile_name_directory (pattern
);
1002 pattern
= Vtemp_file_name_pattern
;
1004 pattern
= concat2 (dirname
, Vtemp_file_name_pattern
);
1008 filename_string
= Fcopy_sequence (ENCODE_FILE (pattern
));
1009 GCPRO1 (filename_string
);
1010 tempfile
= SSDATA (filename_string
);
1015 #ifdef HAVE_MKOSTEMP
1016 fd
= mkostemp (tempfile
, O_CLOEXEC
);
1017 #elif defined HAVE_MKSTEMP
1018 fd
= mkstemp (tempfile
);
1022 /* INT_MAX denotes success, because close (INT_MAX) does nothing. */
1023 fd
= *tempfile
? INT_MAX
: -1;
1026 report_file_error ("Failed to open temporary file using pattern",
1031 record_unwind_protect (delete_temp_file
, filename_string
);
1036 /* Decide coding-system of the contents of the temporary file. */
1037 if (!NILP (Vcoding_system_for_write
))
1038 val
= Vcoding_system_for_write
;
1039 else if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
1043 Lisp_Object coding_systems
;
1046 SAFE_NALLOCA (args2
, 1, nargs
+ 1);
1047 args2
[0] = Qcall_process_region
;
1048 memcpy (args2
+ 1, args
, nargs
* sizeof *args
);
1049 coding_systems
= Ffind_operation_coding_system (nargs
+ 1, args2
);
1050 val
= CONSP (coding_systems
) ? XCDR (coding_systems
) : Qnil
;
1053 val
= complement_process_encoding_system (val
);
1056 ptrdiff_t count1
= SPECPDL_INDEX ();
1058 specbind (intern ("coding-system-for-write"), val
);
1059 /* POSIX lets mk[s]temp use "."; don't invoke jka-compr if we
1060 happen to get a ".Z" suffix. */
1061 specbind (intern ("file-name-handler-alist"), Qnil
);
1062 Fwrite_region (start
, end
, filename_string
, Qnil
, Qlambda
, Qnil
, Qnil
);
1064 unbind_to (count1
, Qnil
);
1067 /* Note that Fcall_process takes care of binding
1068 coding-system-for-read. */
1070 RETURN_UNGCPRO (filename_string
);
1073 DEFUN ("call-process-region", Fcall_process_region
, Scall_process_region
,
1075 doc
: /* Send text from START to END to a synchronous process running PROGRAM.
1076 The remaining arguments are optional.
1077 Delete the text if fourth arg DELETE is non-nil.
1079 Insert output in BUFFER before point; t means current buffer; nil for
1080 BUFFER means discard it; 0 means discard and don't wait; and `(:file
1081 FILE)', where FILE is a file name string, means that it should be
1082 written to that file (if the file already exists it is overwritten).
1083 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,
1084 REAL-BUFFER says what to do with standard output, as above,
1085 while STDERR-FILE says what to do with standard error in the child.
1086 STDERR-FILE may be nil (discard standard error output),
1087 t (mix it with ordinary output), or a file name string.
1089 Sixth arg DISPLAY non-nil means redisplay buffer as output is inserted.
1090 Remaining args are passed to PROGRAM at startup as command args.
1092 If BUFFER is 0, `call-process-region' returns immediately with value nil.
1093 Otherwise it waits for PROGRAM to terminate
1094 and returns a numeric exit status or a signal description string.
1095 If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.
1097 usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &rest ARGS) */)
1098 (ptrdiff_t nargs
, Lisp_Object
*args
)
1100 struct gcpro gcpro1
;
1101 Lisp_Object filename_string
;
1102 ptrdiff_t count
= SPECPDL_INDEX ();
1103 Lisp_Object start
= args
[0];
1104 Lisp_Object end
= args
[1];
1107 if (STRINGP (start
))
1108 empty_input
= SCHARS (start
) == 0;
1109 else if (NILP (start
))
1110 empty_input
= BEG
== Z
;
1113 validate_region (&args
[0], &args
[1]);
1116 empty_input
= XINT (start
) == XINT (end
);
1119 filename_string
= (empty_input
1120 ? build_string (NULL_DEVICE
)
1121 : create_temp_file (nargs
, args
));
1122 GCPRO1 (filename_string
);
1124 if (nargs
> 3 && !NILP (args
[3]))
1125 Fdelete_region (start
, end
);
1137 args
[1] = filename_string
;
1139 RETURN_UNGCPRO (unbind_to (count
, Fcall_process (nargs
, args
)));
1143 static int relocate_fd (int fd
, int minfd
);
1147 add_env (char **env
, char **new_env
, char *string
)
1154 /* See if this string duplicates any string already in the env.
1155 If so, don't put it in.
1156 When an env var has multiple definitions,
1157 we keep the definition that comes first in process-environment. */
1158 for (ep
= env
; ok
&& ep
!= new_env
; ep
++)
1160 char *p
= *ep
, *q
= string
;
1166 /* The string is a lone variable name; keep it for now, we
1167 will remove it later. It is a placeholder for a
1168 variable that is not to be included in the environment. */
1176 *new_env
++ = string
;
1180 /* This is the last thing run in a newly forked inferior
1181 either synchronous or asynchronous.
1182 Copy descriptors IN, OUT and ERR as descriptors 0, 1 and 2.
1183 Initialize inferior's priority, pgrp, connected dir and environment.
1184 then exec another program based on new_argv.
1186 If SET_PGRP, put the subprocess into a separate process group.
1188 CURRENT_DIR is an elisp string giving the path of the current
1189 directory the subprocess should have. Since we can't really signal
1190 a decent error from within the child, this should be verified as an
1191 executable directory by the parent. */
1194 child_setup (int in
, int out
, int err
, char **new_argv
, bool set_pgrp
,
1195 Lisp_Object current_dir
)
1202 #endif /* WINDOWSNT */
1204 pid_t pid
= getpid ();
1206 /* Note that use of alloca is always safe here. It's obvious for systems
1207 that do not have true vfork or that have true (stack) alloca.
1208 If using vfork and C_ALLOCA (when Emacs used to include
1209 src/alloca.c) it is safe because that changes the superior's
1210 static variables as if the superior had done alloca and will be
1211 cleaned up in the usual way. */
1213 register char *temp
;
1214 size_t i
; /* size_t, because ptrdiff_t might overflow here! */
1216 i
= SBYTES (current_dir
);
1218 /* MSDOS must have all environment variables malloc'ed, because
1219 low-level libc functions that launch subsidiary processes rely
1221 pwd_var
= xmalloc (i
+ 6);
1223 pwd_var
= alloca (i
+ 6);
1226 memcpy (pwd_var
, "PWD=", 4);
1227 memcpy (temp
, SDATA (current_dir
), i
);
1228 if (!IS_DIRECTORY_SEP (temp
[i
- 1])) temp
[i
++] = DIRECTORY_SEP
;
1232 /* We can't signal an Elisp error here; we're in a vfork. Since
1233 the callers check the current directory before forking, this
1234 should only return an error if the directory's permissions
1235 are changed between the check and this chdir, but we should
1237 if (chdir (temp
) < 0)
1238 _exit (EXIT_CANCELED
);
1240 /* Get past the drive letter, so that d:/ is left alone. */
1241 if (i
> 2 && IS_DEVICE_SEP (temp
[1]) && IS_DIRECTORY_SEP (temp
[2]))
1248 /* Strip trailing slashes for PWD, but leave "/" and "//" alone. */
1249 while (i
> 2 && IS_DIRECTORY_SEP (temp
[i
- 1]))
1253 /* Set `env' to a vector of the strings in the environment. */
1255 register Lisp_Object tem
;
1256 register char **new_env
;
1258 register int new_length
;
1259 Lisp_Object display
= Qnil
;
1263 for (tem
= Vprocess_environment
;
1264 CONSP (tem
) && STRINGP (XCAR (tem
));
1267 if (strncmp (SSDATA (XCAR (tem
)), "DISPLAY", 7) == 0
1268 && (SDATA (XCAR (tem
)) [7] == '\0'
1269 || SDATA (XCAR (tem
)) [7] == '='))
1270 /* DISPLAY is specified in process-environment. */
1275 /* If not provided yet, use the frame's DISPLAY. */
1278 Lisp_Object tmp
= Fframe_parameter (selected_frame
, Qdisplay
);
1279 if (!STRINGP (tmp
) && CONSP (Vinitial_environment
))
1280 /* If still not found, Look for DISPLAY in Vinitial_environment. */
1281 tmp
= Fgetenv_internal (build_string ("DISPLAY"),
1282 Vinitial_environment
);
1290 /* new_length + 2 to include PWD and terminating 0. */
1291 env
= new_env
= alloca ((new_length
+ 2) * sizeof *env
);
1292 /* If we have a PWD envvar, pass one down,
1293 but with corrected value. */
1294 if (egetenv ("PWD"))
1295 *new_env
++ = pwd_var
;
1297 if (STRINGP (display
))
1299 char *vdata
= alloca (sizeof "DISPLAY=" + SBYTES (display
));
1300 strcpy (vdata
, "DISPLAY=");
1301 strcat (vdata
, SSDATA (display
));
1302 new_env
= add_env (env
, new_env
, vdata
);
1306 for (tem
= Vprocess_environment
;
1307 CONSP (tem
) && STRINGP (XCAR (tem
));
1309 new_env
= add_env (env
, new_env
, SSDATA (XCAR (tem
)));
1313 /* Remove variable names without values. */
1317 while (*q
!= 0 && strchr (*q
, '=') == NULL
)
1327 prepare_standard_handles (in
, out
, err
, handles
);
1328 set_process_dir (SDATA (current_dir
));
1329 /* Spawn the child. (See w32proc.c:sys_spawnve). */
1330 cpid
= spawnve (_P_NOWAIT
, new_argv
[0], new_argv
, env
);
1331 reset_standard_handles (in
, out
, err
, handles
);
1333 /* An error occurred while trying to spawn the process. */
1334 report_file_error ("Spawning child process", Qnil
);
1337 #else /* not WINDOWSNT */
1338 /* Make sure that in, out, and err are not actually already in
1339 descriptors zero, one, or two; this could happen if Emacs is
1340 started with its standard in, out, or error closed, as might
1343 int oin
= in
, oout
= out
;
1345 /* We have to avoid relocating the same descriptor twice! */
1347 in
= relocate_fd (in
, 3);
1352 out
= relocate_fd (out
, 3);
1356 else if (err
== oout
)
1359 err
= relocate_fd (err
, 3);
1363 /* Redirect file descriptors and clear the close-on-exec flag on the
1364 redirected ones. IN, OUT, and ERR are close-on-exec so they
1365 need not be closed explicitly. */
1373 execve (new_argv
[0], new_argv
, env
);
1375 /* Don't output the program name here, as it can be arbitrarily long,
1376 and a long write from a vforked child to its parent can cause a
1378 emacs_perror ("child process");
1380 _exit (errno
== ENOENT
? EXIT_ENOENT
: EXIT_CANNOT_INVOKE
);
1383 pid
= run_msdos_command (new_argv
, pwd_var
+ 4, in
, out
, err
, env
);
1386 /* An error occurred while trying to run the subprocess. */
1387 report_file_error ("Spawning child process", Qnil
);
1390 #endif /* not WINDOWSNT */
1394 /* Move the file descriptor FD so that its number is not less than MINFD.
1395 If the file descriptor is moved at all, the original is closed on MSDOS,
1396 but not elsewhere as the caller will close it anyway. */
1398 relocate_fd (int fd
, int minfd
)
1404 int new = fcntl (fd
, F_DUPFD_CLOEXEC
, minfd
);
1407 emacs_perror ("while setting up child");
1408 _exit (EXIT_CANCELED
);
1416 #endif /* not WINDOWSNT */
1419 getenv_internal_1 (const char *var
, ptrdiff_t varlen
, char **value
,
1420 ptrdiff_t *valuelen
, Lisp_Object env
)
1422 for (; CONSP (env
); env
= XCDR (env
))
1424 Lisp_Object entry
= XCAR (env
);
1426 && SBYTES (entry
) >= varlen
1428 /* NT environment variables are case insensitive. */
1429 && ! strnicmp (SDATA (entry
), var
, varlen
)
1430 #else /* not WINDOWSNT */
1431 && ! memcmp (SDATA (entry
), var
, varlen
)
1432 #endif /* not WINDOWSNT */
1435 if (SBYTES (entry
) > varlen
&& SREF (entry
, varlen
) == '=')
1437 *value
= SSDATA (entry
) + (varlen
+ 1);
1438 *valuelen
= SBYTES (entry
) - (varlen
+ 1);
1441 else if (SBYTES (entry
) == varlen
)
1443 /* Lone variable names in Vprocess_environment mean that
1444 variable should be removed from the environment. */
1454 getenv_internal (const char *var
, ptrdiff_t varlen
, char **value
,
1455 ptrdiff_t *valuelen
, Lisp_Object frame
)
1457 /* Try to find VAR in Vprocess_environment first. */
1458 if (getenv_internal_1 (var
, varlen
, value
, valuelen
,
1459 Vprocess_environment
))
1460 return *value
? 1 : 0;
1462 /* For DISPLAY try to get the values from the frame or the initial env. */
1463 if (strcmp (var
, "DISPLAY") == 0)
1466 = Fframe_parameter (NILP (frame
) ? selected_frame
: frame
, Qdisplay
);
1467 if (STRINGP (display
))
1469 *value
= SSDATA (display
);
1470 *valuelen
= SBYTES (display
);
1473 /* If still not found, Look for DISPLAY in Vinitial_environment. */
1474 if (getenv_internal_1 (var
, varlen
, value
, valuelen
,
1475 Vinitial_environment
))
1476 return *value
? 1 : 0;
1482 DEFUN ("getenv-internal", Fgetenv_internal
, Sgetenv_internal
, 1, 2, 0,
1483 doc
: /* Get the value of environment variable VARIABLE.
1484 VARIABLE should be a string. Value is nil if VARIABLE is undefined in
1485 the environment. Otherwise, value is a string.
1487 This function searches `process-environment' for VARIABLE.
1489 If optional parameter ENV is a list, then search this list instead of
1490 `process-environment', and return t when encountering a negative entry
1491 \(an entry for a variable with no value). */)
1492 (Lisp_Object variable
, Lisp_Object env
)
1497 CHECK_STRING (variable
);
1500 if (getenv_internal_1 (SSDATA (variable
), SBYTES (variable
),
1501 &value
, &valuelen
, env
))
1502 return value
? make_string (value
, valuelen
) : Qt
;
1506 else if (getenv_internal (SSDATA (variable
), SBYTES (variable
),
1507 &value
, &valuelen
, env
))
1508 return make_string (value
, valuelen
);
1513 /* A version of getenv that consults the Lisp environment lists,
1514 easily callable from C. */
1516 egetenv (const char *var
)
1521 if (getenv_internal (var
, strlen (var
), &value
, &valuelen
, Qnil
))
1528 /* This is run before init_cmdargs. */
1531 init_callproc_1 (void)
1534 const char *etc_dir
= ns_etc_directory ();
1535 const char *path_exec
= ns_exec_path ();
1538 Vdata_directory
= decode_env_path ("EMACSDATA",
1543 Vdata_directory
= Ffile_name_as_directory (Fcar (Vdata_directory
));
1545 Vdoc_directory
= decode_env_path ("EMACSDOC",
1550 Vdoc_directory
= Ffile_name_as_directory (Fcar (Vdoc_directory
));
1552 /* Check the EMACSPATH environment variable, defaulting to the
1553 PATH_EXEC path from epaths.h. */
1554 Vexec_path
= decode_env_path ("EMACSPATH",
1556 path_exec
? path_exec
:
1559 Vexec_directory
= Ffile_name_as_directory (Fcar (Vexec_path
));
1560 /* FIXME? For ns, path_exec should go at the front? */
1561 Vexec_path
= nconc2 (decode_env_path ("PATH", ""), Vexec_path
);
1564 /* This is run after init_cmdargs, when Vinstallation_directory is valid. */
1567 init_callproc (void)
1569 char *data_dir
= egetenv ("EMACSDATA");
1572 Lisp_Object tempdir
;
1576 const char *etc_dir
= ns_etc_directory ();
1579 data_dir
= alloca (strlen (etc_dir
) + 1);
1580 strcpy (data_dir
, etc_dir
);
1585 if (!NILP (Vinstallation_directory
))
1587 /* Add to the path the lib-src subdir of the installation dir. */
1589 tem
= Fexpand_file_name (build_string ("lib-src"),
1590 Vinstallation_directory
);
1592 /* MSDOS uses wrapped binaries, so don't do this. */
1593 if (NILP (Fmember (tem
, Vexec_path
)))
1596 const char *path_exec
= ns_exec_path ();
1598 Vexec_path
= decode_env_path ("EMACSPATH",
1600 path_exec
? path_exec
:
1603 Vexec_path
= Fcons (tem
, Vexec_path
);
1604 Vexec_path
= nconc2 (decode_env_path ("PATH", ""), Vexec_path
);
1607 Vexec_directory
= Ffile_name_as_directory (tem
);
1608 #endif /* not MSDOS */
1610 /* Maybe use ../etc as well as ../lib-src. */
1613 tem
= Fexpand_file_name (build_string ("etc"),
1614 Vinstallation_directory
);
1615 Vdoc_directory
= Ffile_name_as_directory (tem
);
1619 /* Look for the files that should be in etc. We don't use
1620 Vinstallation_directory, because these files are never installed
1621 near the executable, and they are never in the build
1622 directory when that's different from the source directory.
1624 Instead, if these files are not in the nominal place, we try the
1625 source directory. */
1628 Lisp_Object tem
, tem1
, srcdir
;
1630 srcdir
= Fexpand_file_name (build_string ("../src/"),
1631 build_string (PATH_DUMPLOADSEARCH
));
1632 tem
= Fexpand_file_name (build_string ("GNU"), Vdata_directory
);
1633 tem1
= Ffile_exists_p (tem
);
1634 if (!NILP (Fequal (srcdir
, Vinvocation_directory
)) || NILP (tem1
))
1637 newdir
= Fexpand_file_name (build_string ("../etc/"),
1638 build_string (PATH_DUMPLOADSEARCH
));
1639 tem
= Fexpand_file_name (build_string ("GNU"), newdir
);
1640 tem1
= Ffile_exists_p (tem
);
1642 Vdata_directory
= newdir
;
1650 tempdir
= Fdirectory_file_name (Vexec_directory
);
1651 if (! file_accessible_directory_p (SSDATA (tempdir
)))
1652 dir_warning ("arch-dependent data dir", Vexec_directory
);
1655 tempdir
= Fdirectory_file_name (Vdata_directory
);
1656 if (! file_accessible_directory_p (SSDATA (tempdir
)))
1657 dir_warning ("arch-independent data dir", Vdata_directory
);
1659 sh
= getenv ("SHELL");
1660 Vshell_file_name
= build_string (sh
? sh
: "/bin/sh");
1663 Vshared_game_score_directory
= Qnil
;
1665 Vshared_game_score_directory
= build_string (PATH_GAME
);
1666 if (NILP (Ffile_accessible_directory_p (Vshared_game_score_directory
)))
1667 Vshared_game_score_directory
= Qnil
;
1672 set_initial_environment (void)
1675 for (envp
= environ
; *envp
; envp
++)
1676 Vprocess_environment
= Fcons (build_string (*envp
),
1677 Vprocess_environment
);
1678 /* Ideally, the `copy' shouldn't be necessary, but it seems it's frequent
1679 to use `delete' and friends on process-environment. */
1680 Vinitial_environment
= Fcopy_sequence (Vprocess_environment
);
1684 syms_of_callproc (void)
1687 Vtemp_file_name_pattern
= build_string ("emacsXXXXXX");
1688 #elif defined (WINDOWSNT)
1689 Vtemp_file_name_pattern
= build_string ("emXXXXXX");
1691 Vtemp_file_name_pattern
= build_string ("detmp.XXX");
1693 staticpro (&Vtemp_file_name_pattern
);
1695 DEFVAR_LISP ("shell-file-name", Vshell_file_name
,
1696 doc
: /* File name to load inferior shells from.
1697 Initialized from the SHELL environment variable, or to a system-dependent
1698 default if SHELL is not set. */);
1700 DEFVAR_LISP ("exec-path", Vexec_path
,
1701 doc
: /* List of directories to search programs to run in subprocesses.
1702 Each element is a string (directory name) or nil (try default directory). */);
1704 DEFVAR_LISP ("exec-suffixes", Vexec_suffixes
,
1705 doc
: /* List of suffixes to try to find executable file names.
1706 Each element is a string. */);
1707 Vexec_suffixes
= Qnil
;
1709 DEFVAR_LISP ("exec-directory", Vexec_directory
,
1710 doc
: /* Directory for executables for Emacs to invoke.
1711 More generally, this includes any architecture-dependent files
1712 that are built and installed from the Emacs distribution. */);
1714 DEFVAR_LISP ("data-directory", Vdata_directory
,
1715 doc
: /* Directory of machine-independent files that come with GNU Emacs.
1716 These are files intended for Emacs to use while it runs. */);
1718 DEFVAR_LISP ("doc-directory", Vdoc_directory
,
1719 doc
: /* Directory containing the DOC file that comes with GNU Emacs.
1720 This is usually the same as `data-directory'. */);
1722 DEFVAR_LISP ("configure-info-directory", Vconfigure_info_directory
,
1723 doc
: /* For internal use by the build procedure only.
1724 This is the name of the directory in which the build procedure installed
1725 Emacs's info files; the default value for `Info-default-directory-list'
1727 Vconfigure_info_directory
= build_string (PATH_INFO
);
1729 DEFVAR_LISP ("shared-game-score-directory", Vshared_game_score_directory
,
1730 doc
: /* Directory of score files for games which come with GNU Emacs.
1731 If this variable is nil, then Emacs is unable to use a shared directory. */);
1733 Vshared_game_score_directory
= Qnil
;
1735 Vshared_game_score_directory
= build_string (PATH_GAME
);
1738 DEFVAR_LISP ("initial-environment", Vinitial_environment
,
1739 doc
: /* List of environment variables inherited from the parent process.
1740 Each element should be a string of the form ENVVARNAME=VALUE.
1741 The elements must normally be decoded (using `locale-coding-system') for use. */);
1742 Vinitial_environment
= Qnil
;
1744 DEFVAR_LISP ("process-environment", Vprocess_environment
,
1745 doc
: /* List of overridden environment variables for subprocesses to inherit.
1746 Each element should be a string of the form ENVVARNAME=VALUE.
1748 Entries in this list take precedence to those in the frame-local
1749 environments. Therefore, let-binding `process-environment' is an easy
1750 way to temporarily change the value of an environment variable,
1751 irrespective of where it comes from. To use `process-environment' to
1752 remove an environment variable, include only its name in the list,
1755 This variable is set to nil when Emacs starts.
1757 If multiple entries define the same variable, the first one always
1760 Non-ASCII characters are encoded according to the initial value of
1761 `locale-coding-system', i.e. the elements must normally be decoded for
1764 See `setenv' and `getenv'. */);
1765 Vprocess_environment
= Qnil
;
1767 defsubr (&Scall_process
);
1768 defsubr (&Sgetenv_internal
);
1769 defsubr (&Scall_process_region
);