1 /* Synchronous subprocess invocation for GNU Emacs.
2 Copyright (C) 1985-1988, 1993-1995, 1999-2012
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>
36 #define _P_NOWAIT 1 /* from process.h */
39 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
41 #include <sys/param.h>
45 #include "character.h"
49 #include "composite.h"
52 #include "syssignal.h"
55 #include "blockinput.h"
57 #include "termhooks.h"
67 /* Pattern used by call-process-region to make temp files. */
68 static Lisp_Object Vtemp_file_name_pattern
;
70 /* The next two variables are valid only while record-unwind-protect
71 is in place during call-process for a synchronous subprocess. At
72 other times, their contents are irrelevant. Doing this via static
73 C variables is more convenient than putting them into the arguments
74 of record-unwind-protect, as they need to be updated at randomish
75 times in the code, and Lisp cannot always store these values as
76 Emacs integers. It's safe to use static variables here, as the
77 code is never invoked reentrantly. */
79 /* If nonzero, a process-ID that has not been reaped. */
80 static pid_t synch_process_pid
;
82 /* If nonnegative, a file descriptor that has not been closed. */
83 static int synch_process_fd
;
88 block_child_signal (void)
91 sigemptyset (&blocked
);
92 sigaddset (&blocked
, SIGCHLD
);
93 pthread_sigmask (SIG_BLOCK
, &blocked
, 0);
96 /* Unblock SIGCHLD. */
99 unblock_child_signal (void)
101 pthread_sigmask (SIG_SETMASK
, &empty_mask
, 0);
104 /* If P is reapable, record it as a deleted process and kill it.
105 Do this in a critical section. Unless PID is wedged it will be
106 reaped on receipt of the first SIGCHLD after the critical section. */
109 record_kill_process (struct Lisp_Process
*p
)
111 block_child_signal ();
116 record_deleted_pid (p
->pid
);
117 kill (- p
->pid
, SIGKILL
);
120 unblock_child_signal ();
123 /* Clean up when exiting call_process_cleanup. */
126 call_process_kill (Lisp_Object ignored
)
128 if (0 <= synch_process_fd
)
129 emacs_close (synch_process_fd
);
131 if (synch_process_pid
)
133 struct Lisp_Process proc
;
135 proc
.pid
= synch_process_pid
;
136 record_kill_process (&proc
);
142 /* Clean up when exiting Fcall_process.
143 On MSDOS, delete the temporary file on any kind of termination.
144 On Unix, kill the process and any children on termination by signal. */
147 call_process_cleanup (Lisp_Object arg
)
150 Lisp_Object buffer
= Fcar (arg
);
151 Lisp_Object file
= Fcdr (arg
);
153 Lisp_Object buffer
= arg
;
156 Fset_buffer (buffer
);
159 /* If the process still exists, kill its process group. */
160 if (synch_process_pid
)
162 ptrdiff_t count
= SPECPDL_INDEX ();
163 kill (-synch_process_pid
, SIGINT
);
164 record_unwind_protect (call_process_kill
, make_number (0));
165 message1 ("Waiting for process to die...(type C-g again to kill it instantly)");
168 wait_for_termination (synch_process_pid
, 0, 1);
169 synch_process_pid
= 0;
171 specpdl_ptr
= specpdl
+ count
; /* Discard the unwind protect. */
172 message1 ("Waiting for process to die...done");
176 if (0 <= synch_process_fd
)
177 emacs_close (synch_process_fd
);
180 /* FILE is "" when we didn't actually create a temporary file in
182 if (!(strcmp (SDATA (file
), NULL_DEVICE
) == 0 || SREF (file
, 0) == '\0'))
183 unlink (SDATA (file
));
189 DEFUN ("call-process", Fcall_process
, Scall_process
, 1, MANY
, 0,
190 doc
: /* Call PROGRAM synchronously in separate process.
191 The remaining arguments are optional.
192 The program's input comes from file INFILE (nil means `/dev/null').
193 Insert output in BUFFER before point; t means current buffer; nil for BUFFER
194 means discard it; 0 means discard and don't wait; and `(:file FILE)', where
195 FILE is a file name string, means that it should be written to that file
196 \(if the file already exists it is overwritten).
197 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,
198 REAL-BUFFER says what to do with standard output, as above,
199 while STDERR-FILE says what to do with standard error in the child.
200 STDERR-FILE may be nil (discard standard error output),
201 t (mix it with ordinary output), or a file name string.
203 Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted.
204 Remaining arguments are strings passed as command arguments to PROGRAM.
206 If executable PROGRAM can't be found as an executable, `call-process'
207 signals a Lisp error. `call-process' reports errors in execution of
208 the program only through its return and output.
210 If BUFFER is 0, `call-process' returns immediately with value nil.
211 Otherwise it waits for PROGRAM to terminate
212 and returns a numeric exit status or a signal description string.
213 If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.
215 usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
216 (ptrdiff_t nargs
, Lisp_Object
*args
)
218 Lisp_Object infile
, buffer
, current_dir
, path
;
220 int fd0
, fd1
, filefd
;
222 ptrdiff_t count
= SPECPDL_INDEX ();
226 /* File to use for stderr in the child.
227 t means use same as standard output. */
228 Lisp_Object error_file
;
229 Lisp_Object output_file
= Qnil
;
230 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
231 char *outf
, *tempfile
= NULL
;
239 struct coding_system process_coding
; /* coding-system of process output */
240 struct coding_system argument_coding
; /* coding-system of arguments */
241 /* Set to the return value of Ffind_operation_coding_system. */
242 Lisp_Object coding_systems
;
243 bool output_to_buffer
= 1;
245 /* Qt denotes that Ffind_operation_coding_system is not yet called. */
248 CHECK_STRING (args
[0]);
253 /* Without asynchronous processes we cannot have BUFFER == 0. */
255 && (INTEGERP (CONSP (args
[2]) ? XCAR (args
[2]) : args
[2])))
256 error ("Operating system cannot handle asynchronous subprocesses");
257 #endif /* subprocesses */
259 /* Decide the coding-system for giving arguments. */
261 Lisp_Object val
, *args2
;
264 /* If arguments are supplied, we may have to encode them. */
267 bool must_encode
= 0;
268 Lisp_Object coding_attrs
;
270 for (i
= 4; i
< nargs
; i
++)
271 CHECK_STRING (args
[i
]);
273 for (i
= 4; i
< nargs
; i
++)
274 if (STRING_MULTIBYTE (args
[i
]))
277 if (!NILP (Vcoding_system_for_write
))
278 val
= Vcoding_system_for_write
;
279 else if (! must_encode
)
283 SAFE_NALLOCA (args2
, 1, nargs
+ 1);
284 args2
[0] = Qcall_process
;
285 for (i
= 0; i
< nargs
; i
++) args2
[i
+ 1] = args
[i
];
286 coding_systems
= Ffind_operation_coding_system (nargs
+ 1, args2
);
287 val
= CONSP (coding_systems
) ? XCDR (coding_systems
) : Qnil
;
289 val
= complement_process_encoding_system (val
);
290 setup_coding_system (Fcheck_coding_system (val
), &argument_coding
);
291 coding_attrs
= CODING_ID_ATTRS (argument_coding
.id
);
292 if (NILP (CODING_ATTR_ASCII_COMPAT (coding_attrs
)))
294 /* We should not use an ASCII incompatible coding system. */
295 val
= raw_text_coding_system (val
);
296 setup_coding_system (val
, &argument_coding
);
301 if (nargs
>= 2 && ! NILP (args
[1]))
303 infile
= Fexpand_file_name (args
[1], BVAR (current_buffer
, directory
));
304 CHECK_STRING (infile
);
307 infile
= build_string (NULL_DEVICE
);
313 /* If BUFFER is a list, its meaning is (BUFFER-FOR-STDOUT
314 FILE-FOR-STDERR), unless the first element is :file, in which case see
315 the next paragraph. */
317 && (! SYMBOLP (XCAR (buffer
))
318 || strcmp (SSDATA (SYMBOL_NAME (XCAR (buffer
))), ":file")))
320 if (CONSP (XCDR (buffer
)))
322 Lisp_Object stderr_file
;
323 stderr_file
= XCAR (XCDR (buffer
));
325 if (NILP (stderr_file
) || EQ (Qt
, stderr_file
))
326 error_file
= stderr_file
;
328 error_file
= Fexpand_file_name (stderr_file
, Qnil
);
331 buffer
= XCAR (buffer
);
334 /* If the buffer is (still) a list, it might be a (:file "file") spec. */
336 && SYMBOLP (XCAR (buffer
))
337 && ! strcmp (SSDATA (SYMBOL_NAME (XCAR (buffer
))), ":file"))
339 output_file
= Fexpand_file_name (XCAR (XCDR (buffer
)),
340 BVAR (current_buffer
, directory
));
341 CHECK_STRING (output_file
);
345 if (!(EQ (buffer
, Qnil
)
347 || INTEGERP (buffer
)))
349 Lisp_Object spec_buffer
;
350 spec_buffer
= buffer
;
351 buffer
= Fget_buffer_create (buffer
);
352 /* Mention the buffer name for a better error message. */
354 CHECK_BUFFER (spec_buffer
);
355 CHECK_BUFFER (buffer
);
361 /* Make sure that the child will be able to chdir to the current
362 buffer's current directory, or its unhandled equivalent. We
363 can't just have the child check for an error when it does the
364 chdir, since it's in a vfork.
366 We have to GCPRO around this because Fexpand_file_name,
367 Funhandled_file_name_directory, and Ffile_accessible_directory_p
368 might call a file name handling function. The argument list is
369 protected by the caller, so all we really have to worry about is
372 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
374 current_dir
= BVAR (current_buffer
, directory
);
376 GCPRO5 (infile
, buffer
, current_dir
, error_file
, output_file
);
378 current_dir
= Funhandled_file_name_directory (current_dir
);
379 if (NILP (current_dir
))
380 /* If the file name handler says that current_dir is unreachable, use
381 a sensible default. */
382 current_dir
= build_string ("~/");
383 current_dir
= expand_and_dir_to_file (current_dir
, Qnil
);
384 current_dir
= Ffile_name_as_directory (current_dir
);
386 if (NILP (Ffile_accessible_directory_p (current_dir
)))
387 report_file_error ("Setting current directory",
388 Fcons (BVAR (current_buffer
, directory
), Qnil
));
390 if (STRING_MULTIBYTE (infile
))
391 infile
= ENCODE_FILE (infile
);
392 if (STRING_MULTIBYTE (current_dir
))
393 current_dir
= ENCODE_FILE (current_dir
);
394 if (STRINGP (error_file
) && STRING_MULTIBYTE (error_file
))
395 error_file
= ENCODE_FILE (error_file
);
396 if (STRINGP (output_file
) && STRING_MULTIBYTE (output_file
))
397 output_file
= ENCODE_FILE (output_file
);
401 display_p
= INTERACTIVE
&& nargs
>= 4 && !NILP (args
[3]);
403 filefd
= emacs_open (SSDATA (infile
), O_RDONLY
, 0);
406 infile
= DECODE_FILE (infile
);
407 report_file_error ("Opening process input file", Fcons (infile
, Qnil
));
410 if (STRINGP (output_file
))
413 fd_output
= emacs_open (SSDATA (output_file
),
414 O_WRONLY
| O_TRUNC
| O_CREAT
| O_TEXT
,
416 #else /* not DOS_NT */
417 fd_output
= creat (SSDATA (output_file
), 0666);
418 #endif /* not DOS_NT */
421 output_file
= DECODE_FILE (output_file
);
422 report_file_error ("Opening process output file",
423 Fcons (output_file
, Qnil
));
425 if (STRINGP (error_file
) || NILP (error_file
))
426 output_to_buffer
= 0;
429 /* Search for program; barf if not found. */
431 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
433 GCPRO4 (infile
, buffer
, current_dir
, error_file
);
434 openp (Vexec_path
, args
[0], Vexec_suffixes
, &path
, make_number (X_OK
));
439 emacs_close (filefd
);
440 report_file_error ("Searching for program", Fcons (args
[0], Qnil
));
443 /* If program file name starts with /: for quoting a magic name,
445 if (SBYTES (path
) > 2 && SREF (path
, 0) == '/'
446 && SREF (path
, 1) == ':')
447 path
= Fsubstring (path
, make_number (2), Qnil
);
449 new_argv
= SAFE_ALLOCA ((nargs
> 4 ? nargs
- 2 : 2) * sizeof *new_argv
);
453 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
455 GCPRO5 (infile
, buffer
, current_dir
, path
, error_file
);
456 argument_coding
.dst_multibyte
= 0;
457 for (i
= 4; i
< nargs
; i
++)
459 argument_coding
.src_multibyte
= STRING_MULTIBYTE (args
[i
]);
460 if (CODING_REQUIRE_ENCODING (&argument_coding
))
461 /* We must encode this argument. */
462 args
[i
] = encode_coding_string (&argument_coding
, args
[i
], 1);
465 for (i
= 4; i
< nargs
; i
++)
466 new_argv
[i
- 3] = SSDATA (args
[i
]);
471 new_argv
[0] = SSDATA (path
);
473 #ifdef MSDOS /* MW, July 1993 */
475 /* If we're redirecting STDOUT to a file, that file is already open
479 if ((outf
= egetenv ("TMPDIR")))
480 strcpy (tempfile
= alloca (strlen (outf
) + 20), outf
);
483 tempfile
= alloca (20);
486 dostounix_filename (tempfile
);
487 if (*tempfile
== '\0' || tempfile
[strlen (tempfile
) - 1] != '/')
488 strcat (tempfile
, "/");
489 strcat (tempfile
, "detmp.XXX");
491 outfilefd
= creat (tempfile
, S_IREAD
| S_IWRITE
);
493 emacs_close (filefd
);
494 report_file_error ("Opening process output file",
495 Fcons (build_string (tempfile
), Qnil
));
499 outfilefd
= fd_output
;
504 if (INTEGERP (buffer
))
507 fd1
= emacs_open (NULL_DEVICE
, O_WRONLY
, 0);
515 int pipe_errno
= errno
;
516 emacs_close (filefd
);
518 report_file_error ("Creating process pipe", Qnil
);
531 if (NILP (error_file
))
532 fd_error
= emacs_open (NULL_DEVICE
, O_WRONLY
, 0);
533 else if (STRINGP (error_file
))
536 fd_error
= emacs_open (SSDATA (error_file
),
537 O_WRONLY
| O_TRUNC
| O_CREAT
| O_TEXT
,
539 #else /* not DOS_NT */
540 fd_error
= creat (SSDATA (error_file
), 0666);
541 #endif /* not DOS_NT */
546 emacs_close (filefd
);
554 if (NILP (error_file
))
555 error_file
= build_string (NULL_DEVICE
);
556 else if (STRINGP (error_file
))
557 error_file
= DECODE_FILE (error_file
);
558 report_file_error ("Cannot redirect stderr", Fcons (error_file
, Qnil
));
561 #ifdef MSDOS /* MW, July 1993 */
562 /* Note that on MSDOS `child_setup' actually returns the child process
563 exit status, not its PID, so assign it to status below. */
564 pid
= child_setup (filefd
, outfilefd
, fd_error
, new_argv
, 0, current_dir
);
567 emacs_close (outfilefd
);
568 if (fd_error
!= outfilefd
)
569 emacs_close (fd_error
);
572 synchronize_system_messages_locale ();
574 code_convert_string_norecord (build_string (strerror (child_errno
)),
575 Vlocale_coding_system
, 0);
578 fd1
= -1; /* No harm in closing that one! */
581 /* Since CRLF is converted to LF within `decode_coding', we
582 can always open a file with binary mode. */
583 fd0
= emacs_open (tempfile
, O_RDONLY
| O_BINARY
, 0);
587 emacs_close (filefd
);
588 report_file_error ("Cannot re-open temporary file",
589 Fcons (build_string (tempfile
), Qnil
));
593 fd0
= -1; /* We are not going to read from tempfile. */
596 /* Do the unwind-protect now, even though the pid is not known, so
597 that no storage allocation is done in the critical section.
598 The actual PID will be filled in during the critical section. */
599 synch_process_pid
= 0;
600 synch_process_fd
= fd0
;
603 /* MSDOS needs different cleanup information. */
604 record_unwind_protect (call_process_cleanup
,
605 Fcons (Fcurrent_buffer (),
606 build_string (tempfile
? tempfile
: "")));
608 record_unwind_protect (call_process_cleanup
, Fcurrent_buffer ());
611 block_child_signal ();
614 pid
= child_setup (filefd
, fd1
, fd_error
, new_argv
, 0, current_dir
);
615 #else /* not WINDOWSNT */
617 /* vfork, and prevent local vars from being clobbered by the vfork. */
619 Lisp_Object
volatile buffer_volatile
= buffer
;
620 Lisp_Object
volatile coding_systems_volatile
= coding_systems
;
621 Lisp_Object
volatile current_dir_volatile
= current_dir
;
622 bool volatile display_p_volatile
= display_p
;
623 bool volatile output_to_buffer_volatile
= output_to_buffer
;
624 bool volatile sa_must_free_volatile
= sa_must_free
;
625 int volatile fd1_volatile
= fd1
;
626 int volatile fd_error_volatile
= fd_error
;
627 int volatile fd_output_volatile
= fd_output
;
628 int volatile filefd_volatile
= filefd
;
629 ptrdiff_t volatile count_volatile
= count
;
630 ptrdiff_t volatile sa_count_volatile
= sa_count
;
631 char **volatile new_argv_volatile
= new_argv
;
636 buffer
= buffer_volatile
;
637 coding_systems
= coding_systems_volatile
;
638 current_dir
= current_dir_volatile
;
639 display_p
= display_p_volatile
;
640 output_to_buffer
= output_to_buffer_volatile
;
641 sa_must_free
= sa_must_free_volatile
;
643 fd_error
= fd_error_volatile
;
644 fd_output
= fd_output_volatile
;
645 filefd
= filefd_volatile
;
646 count
= count_volatile
;
647 sa_count
= sa_count_volatile
;
648 new_argv
= new_argv_volatile
;
650 fd0
= synch_process_fd
;
655 unblock_child_signal ();
662 /* Emacs ignores SIGPIPE, but the child should not. */
663 signal (SIGPIPE
, SIG_DFL
);
665 child_setup (filefd
, fd1
, fd_error
, new_argv
, 0, current_dir
);
668 #endif /* not WINDOWSNT */
674 if (INTEGERP (buffer
))
675 record_deleted_pid (pid
);
677 synch_process_pid
= pid
;
680 unblock_child_signal ();
683 /* The MSDOS case did this already. */
685 emacs_close (fd_error
);
686 #endif /* not MSDOS */
688 /* Close most of our file descriptors, but not fd0
689 since we will use that to read input from. */
690 emacs_close (filefd
);
692 emacs_close (fd_output
);
693 if (fd1
>= 0 && fd1
!= fd_error
)
700 report_file_error ("Doing vfork", Qnil
);
703 if (INTEGERP (buffer
))
704 return unbind_to (count
, Qnil
);
706 if (BUFFERP (buffer
))
707 Fset_buffer (buffer
);
711 /* If BUFFER is nil, we must read process output once and then
712 discard it, so setup coding system but with nil. */
713 setup_coding_system (Qnil
, &process_coding
);
714 process_coding
.dst_multibyte
= 0;
718 Lisp_Object val
, *args2
;
721 if (!NILP (Vcoding_system_for_read
))
722 val
= Vcoding_system_for_read
;
725 if (EQ (coding_systems
, Qt
))
729 SAFE_NALLOCA (args2
, 1, nargs
+ 1);
730 args2
[0] = Qcall_process
;
731 for (i
= 0; i
< nargs
; i
++) args2
[i
+ 1] = args
[i
];
733 = Ffind_operation_coding_system (nargs
+ 1, args2
);
735 if (CONSP (coding_systems
))
736 val
= XCAR (coding_systems
);
737 else if (CONSP (Vdefault_process_coding_system
))
738 val
= XCAR (Vdefault_process_coding_system
);
742 Fcheck_coding_system (val
);
743 /* In unibyte mode, character code conversion should not take
744 place but EOL conversion should. So, setup raw-text or one
745 of the subsidiary according to the information just setup. */
746 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
))
748 val
= raw_text_coding_system (val
);
749 setup_coding_system (val
, &process_coding
);
750 process_coding
.dst_multibyte
751 = ! NILP (BVAR (current_buffer
, enable_multibyte_characters
));
753 process_coding
.src_multibyte
= 0;
758 if (output_to_buffer
)
760 enum { CALLPROC_BUFFER_SIZE_MIN
= 16 * 1024 };
761 enum { CALLPROC_BUFFER_SIZE_MAX
= 4 * CALLPROC_BUFFER_SIZE_MIN
};
762 char buf
[CALLPROC_BUFFER_SIZE_MAX
];
763 int bufsize
= CALLPROC_BUFFER_SIZE_MIN
;
766 EMACS_INT total_read
= 0;
768 bool display_on_the_fly
= display_p
;
769 struct coding_system saved_coding
;
771 saved_coding
= process_coding
;
774 /* Repeatedly read until we've filled as much as possible
775 of the buffer size we have. But don't read
776 less than 1024--save that for the next bufferful. */
778 while (nread
< bufsize
- 1024)
780 int this_read
= emacs_read (fd0
, buf
+ nread
,
788 process_coding
.mode
|= CODING_MODE_LAST_BLOCK
;
793 total_read
+= this_read
;
795 if (display_on_the_fly
)
799 /* Now NREAD is the total amount of data in the buffer. */
804 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
))
805 && ! CODING_MAY_REQUIRE_DECODING (&process_coding
))
806 insert_1_both (buf
, nread
, nread
, 0, 1, 0);
808 { /* We have to decode the input. */
810 ptrdiff_t count1
= SPECPDL_INDEX ();
812 XSETBUFFER (curbuf
, current_buffer
);
813 /* We cannot allow after-change-functions be run
814 during decoding, because that might modify the
815 buffer, while we rely on process_coding.produced to
816 faithfully reflect inserted text until we
817 TEMP_SET_PT_BOTH below. */
818 specbind (Qinhibit_modification_hooks
, Qt
);
819 decode_coding_c_string (&process_coding
,
820 (unsigned char *) buf
, nread
, curbuf
);
821 unbind_to (count1
, Qnil
);
822 if (display_on_the_fly
823 && CODING_REQUIRE_DETECTION (&saved_coding
)
824 && ! CODING_REQUIRE_DETECTION (&process_coding
))
826 /* We have detected some coding system. But,
827 there's a possibility that the detection was
828 done by insufficient data. So, we give up
829 displaying on the fly. */
830 if (process_coding
.produced
> 0)
831 del_range_2 (process_coding
.dst_pos
,
832 process_coding
.dst_pos_byte
,
833 process_coding
.dst_pos
834 + process_coding
.produced_char
,
835 process_coding
.dst_pos_byte
836 + process_coding
.produced
, 0);
837 display_on_the_fly
= 0;
838 process_coding
= saved_coding
;
840 /* This is to make the above condition always
841 fails in the future. */
842 saved_coding
.common_flags
843 &= ~CODING_REQUIRE_DETECTION_MASK
;
847 TEMP_SET_PT_BOTH (PT
+ process_coding
.produced_char
,
848 PT_BYTE
+ process_coding
.produced
);
849 carryover
= process_coding
.carryover_bytes
;
851 memcpy (buf
, process_coding
.carryover
,
852 process_coding
.carryover_bytes
);
856 if (process_coding
.mode
& CODING_MODE_LAST_BLOCK
)
859 /* Make the buffer bigger as we continue to read more data,
860 but not past CALLPROC_BUFFER_SIZE_MAX. */
861 if (bufsize
< CALLPROC_BUFFER_SIZE_MAX
&& total_read
> 32 * bufsize
)
862 if ((bufsize
*= 2) > CALLPROC_BUFFER_SIZE_MAX
)
863 bufsize
= CALLPROC_BUFFER_SIZE_MAX
;
868 prepare_menu_bars ();
870 redisplay_preserve_echo_area (1);
871 /* This variable might have been set to 0 for code
872 detection. In that case, we set it back to 1 because
873 we should have already detected a coding system. */
874 display_on_the_fly
= 1;
881 Vlast_coding_system_used
= CODING_ID_NAME (process_coding
.id
);
882 /* If the caller required, let the buffer inherit the
883 coding-system used to decode the process output. */
884 if (inherit_process_coding_system
)
885 call1 (intern ("after-insert-file-set-buffer-file-coding-system"),
886 make_number (total_read
));
890 /* Wait for it to terminate, unless it already has. */
891 wait_for_termination (pid
, &status
, !output_to_buffer
);
896 /* Don't kill any children that the subprocess may have left behind
898 synch_process_pid
= 0;
901 unbind_to (count
, Qnil
);
903 if (WIFSIGNALED (status
))
907 synchronize_system_messages_locale ();
908 signame
= strsignal (WTERMSIG (status
));
913 return code_convert_string_norecord (build_string (signame
),
914 Vlocale_coding_system
, 0);
917 eassert (WIFEXITED (status
));
918 return make_number (WEXITSTATUS (status
));
922 delete_temp_file (Lisp_Object name
)
924 /* Suppress jka-compr handling, etc. */
925 ptrdiff_t count
= SPECPDL_INDEX ();
926 specbind (intern ("file-name-handler-alist"), Qnil
);
927 internal_delete_file (name
);
928 unbind_to (count
, Qnil
);
932 DEFUN ("call-process-region", Fcall_process_region
, Scall_process_region
,
934 doc
: /* Send text from START to END to a synchronous process running PROGRAM.
935 The remaining arguments are optional.
936 Delete the text if fourth arg DELETE is non-nil.
938 Insert output in BUFFER before point; t means current buffer; nil for
939 BUFFER means discard it; 0 means discard and don't wait; and `(:file
940 FILE)', where FILE is a file name string, means that it should be
941 written to that file (if the file already exists it is overwritten).
942 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,
943 REAL-BUFFER says what to do with standard output, as above,
944 while STDERR-FILE says what to do with standard error in the child.
945 STDERR-FILE may be nil (discard standard error output),
946 t (mix it with ordinary output), or a file name string.
948 Sixth arg DISPLAY non-nil means redisplay buffer as output is inserted.
949 Remaining args are passed to PROGRAM at startup as command args.
951 If BUFFER is 0, `call-process-region' returns immediately with value nil.
952 Otherwise it waits for PROGRAM to terminate
953 and returns a numeric exit status or a signal description string.
954 If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.
956 usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &rest ARGS) */)
957 (ptrdiff_t nargs
, Lisp_Object
*args
)
960 Lisp_Object filename_string
;
961 register Lisp_Object start
, end
;
962 ptrdiff_t count
= SPECPDL_INDEX ();
963 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
964 Lisp_Object coding_systems
;
965 Lisp_Object val
, *args2
;
969 if (STRINGP (Vtemporary_file_directory
))
970 tmpdir
= Vtemporary_file_directory
;
974 if (getenv ("TMPDIR"))
975 tmpdir
= build_string (getenv ("TMPDIR"));
977 tmpdir
= build_string ("/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"));
991 Lisp_Object pattern
= Fexpand_file_name (Vtemp_file_name_pattern
, tmpdir
);
992 Lisp_Object encoded_tem
= ENCODE_FILE (pattern
);
993 char *tempfile
= SAFE_ALLOCA (SBYTES (encoded_tem
) + 1);
994 memcpy (tempfile
, SDATA (encoded_tem
), SBYTES (encoded_tem
) + 1);
1002 fd
= mkstemp (tempfile
);
1005 report_file_error ("Failed to open temporary file",
1006 Fcons (build_string (tempfile
), Qnil
));
1017 report_file_error ("Failed to open temporary file using pattern",
1018 Fcons (pattern
, Qnil
));
1022 filename_string
= build_string (tempfile
);
1023 GCPRO1 (filename_string
);
1029 /* Decide coding-system of the contents of the temporary file. */
1030 if (!NILP (Vcoding_system_for_write
))
1031 val
= Vcoding_system_for_write
;
1032 else if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
1037 SAFE_NALLOCA (args2
, 1, nargs
+ 1);
1038 args2
[0] = Qcall_process_region
;
1039 for (i
= 0; i
< nargs
; i
++) args2
[i
+ 1] = args
[i
];
1040 coding_systems
= Ffind_operation_coding_system (nargs
+ 1, args2
);
1041 val
= CONSP (coding_systems
) ? XCDR (coding_systems
) : Qnil
;
1044 val
= complement_process_encoding_system (val
);
1047 ptrdiff_t count1
= SPECPDL_INDEX ();
1049 specbind (intern ("coding-system-for-write"), val
);
1050 /* POSIX lets mk[s]temp use "."; don't invoke jka-compr if we
1051 happen to get a ".Z" suffix. */
1052 specbind (intern ("file-name-handler-alist"), Qnil
);
1053 Fwrite_region (start
, end
, filename_string
, Qnil
, Qlambda
, Qnil
, Qnil
);
1055 unbind_to (count1
, Qnil
);
1058 /* Note that Fcall_process takes care of binding
1059 coding-system-for-read. */
1061 record_unwind_protect (delete_temp_file
, filename_string
);
1063 if (nargs
> 3 && !NILP (args
[3]))
1064 Fdelete_region (start
, end
);
1076 args
[1] = filename_string
;
1078 RETURN_UNGCPRO (unbind_to (count
, Fcall_process (nargs
, args
)));
1082 static int relocate_fd (int fd
, int minfd
);
1086 add_env (char **env
, char **new_env
, char *string
)
1093 /* See if this string duplicates any string already in the env.
1094 If so, don't put it in.
1095 When an env var has multiple definitions,
1096 we keep the definition that comes first in process-environment. */
1097 for (ep
= env
; ok
&& ep
!= new_env
; ep
++)
1099 char *p
= *ep
, *q
= string
;
1105 /* The string is a lone variable name; keep it for now, we
1106 will remove it later. It is a placeholder for a
1107 variable that is not to be included in the environment. */
1115 *new_env
++ = string
;
1119 /* This is the last thing run in a newly forked inferior
1120 either synchronous or asynchronous.
1121 Copy descriptors IN, OUT and ERR as descriptors 0, 1 and 2.
1122 Initialize inferior's priority, pgrp, connected dir and environment.
1123 then exec another program based on new_argv.
1125 If SET_PGRP, put the subprocess into a separate process group.
1127 CURRENT_DIR is an elisp string giving the path of the current
1128 directory the subprocess should have. Since we can't really signal
1129 a decent error from within the child, this should be verified as an
1130 executable directory by the parent. */
1133 child_setup (int in
, int out
, int err
, char **new_argv
, bool set_pgrp
,
1134 Lisp_Object current_dir
)
1141 #endif /* WINDOWSNT */
1143 pid_t pid
= getpid ();
1145 /* Close Emacs's descriptors that this process should not have. */
1146 close_process_descs ();
1148 /* DOS_NT isn't in a vfork, so if we are in the middle of load-file,
1149 we will lose if we call close_load_descs here. */
1151 close_load_descs ();
1154 /* Note that use of alloca is always safe here. It's obvious for systems
1155 that do not have true vfork or that have true (stack) alloca.
1156 If using vfork and C_ALLOCA (when Emacs used to include
1157 src/alloca.c) it is safe because that changes the superior's
1158 static variables as if the superior had done alloca and will be
1159 cleaned up in the usual way. */
1161 register char *temp
;
1162 size_t i
; /* size_t, because ptrdiff_t might overflow here! */
1164 i
= SBYTES (current_dir
);
1166 /* MSDOS must have all environment variables malloc'ed, because
1167 low-level libc functions that launch subsidiary processes rely
1169 pwd_var
= xmalloc (i
+ 6);
1171 pwd_var
= alloca (i
+ 6);
1174 memcpy (pwd_var
, "PWD=", 4);
1175 memcpy (temp
, SDATA (current_dir
), i
);
1176 if (!IS_DIRECTORY_SEP (temp
[i
- 1])) temp
[i
++] = DIRECTORY_SEP
;
1180 /* We can't signal an Elisp error here; we're in a vfork. Since
1181 the callers check the current directory before forking, this
1182 should only return an error if the directory's permissions
1183 are changed between the check and this chdir, but we should
1185 if (chdir (temp
) < 0)
1188 /* Get past the drive letter, so that d:/ is left alone. */
1189 if (i
> 2 && IS_DEVICE_SEP (temp
[1]) && IS_DIRECTORY_SEP (temp
[2]))
1196 /* Strip trailing slashes for PWD, but leave "/" and "//" alone. */
1197 while (i
> 2 && IS_DIRECTORY_SEP (temp
[i
- 1]))
1201 /* Set `env' to a vector of the strings in the environment. */
1203 register Lisp_Object tem
;
1204 register char **new_env
;
1206 register int new_length
;
1207 Lisp_Object display
= Qnil
;
1211 for (tem
= Vprocess_environment
;
1212 CONSP (tem
) && STRINGP (XCAR (tem
));
1215 if (strncmp (SSDATA (XCAR (tem
)), "DISPLAY", 7) == 0
1216 && (SDATA (XCAR (tem
)) [7] == '\0'
1217 || SDATA (XCAR (tem
)) [7] == '='))
1218 /* DISPLAY is specified in process-environment. */
1223 /* If not provided yet, use the frame's DISPLAY. */
1226 Lisp_Object tmp
= Fframe_parameter (selected_frame
, Qdisplay
);
1227 if (!STRINGP (tmp
) && CONSP (Vinitial_environment
))
1228 /* If still not found, Look for DISPLAY in Vinitial_environment. */
1229 tmp
= Fgetenv_internal (build_string ("DISPLAY"),
1230 Vinitial_environment
);
1238 /* new_length + 2 to include PWD and terminating 0. */
1239 env
= new_env
= alloca ((new_length
+ 2) * sizeof *env
);
1240 /* If we have a PWD envvar, pass one down,
1241 but with corrected value. */
1242 if (egetenv ("PWD"))
1243 *new_env
++ = pwd_var
;
1245 if (STRINGP (display
))
1247 char *vdata
= alloca (sizeof "DISPLAY=" + SBYTES (display
));
1248 strcpy (vdata
, "DISPLAY=");
1249 strcat (vdata
, SSDATA (display
));
1250 new_env
= add_env (env
, new_env
, vdata
);
1254 for (tem
= Vprocess_environment
;
1255 CONSP (tem
) && STRINGP (XCAR (tem
));
1257 new_env
= add_env (env
, new_env
, SSDATA (XCAR (tem
)));
1261 /* Remove variable names without values. */
1265 while (*q
!= 0 && strchr (*q
, '=') == NULL
)
1275 prepare_standard_handles (in
, out
, err
, handles
);
1276 set_process_dir (SDATA (current_dir
));
1277 /* Spawn the child. (See ntproc.c:Spawnve). */
1278 cpid
= spawnve (_P_NOWAIT
, new_argv
[0], new_argv
, env
);
1279 reset_standard_handles (in
, out
, err
, handles
);
1281 /* An error occurred while trying to spawn the process. */
1282 report_file_error ("Spawning child process", Qnil
);
1285 #else /* not WINDOWSNT */
1286 /* Make sure that in, out, and err are not actually already in
1287 descriptors zero, one, or two; this could happen if Emacs is
1288 started with its standard in, out, or error closed, as might
1291 int oin
= in
, oout
= out
;
1293 /* We have to avoid relocating the same descriptor twice! */
1295 in
= relocate_fd (in
, 3);
1300 out
= relocate_fd (out
, 3);
1304 else if (err
== oout
)
1307 err
= relocate_fd (err
, 3);
1321 if (err
!= in
&& err
!= out
)
1327 execve (new_argv
[0], new_argv
, env
);
1329 emacs_write (1, "Can't exec program: ", 20);
1330 emacs_write (1, new_argv
[0], strlen (new_argv
[0]));
1331 emacs_write (1, "\n", 1);
1335 pid
= run_msdos_command (new_argv
, pwd_var
+ 4, in
, out
, err
, env
);
1338 /* An error occurred while trying to run the subprocess. */
1339 report_file_error ("Spawning child process", Qnil
);
1342 #endif /* not WINDOWSNT */
1346 /* Move the file descriptor FD so that its number is not less than MINFD.
1347 If the file descriptor is moved at all, the original is freed. */
1349 relocate_fd (int fd
, int minfd
)
1355 int new = fcntl (fd
, F_DUPFD
, minfd
);
1358 const char *message_1
= "Error while setting up child: ";
1359 const char *errmessage
= strerror (errno
);
1360 const char *message_2
= "\n";
1361 emacs_write (2, message_1
, strlen (message_1
));
1362 emacs_write (2, errmessage
, strlen (errmessage
));
1363 emacs_write (2, message_2
, strlen (message_2
));
1370 #endif /* not WINDOWSNT */
1373 getenv_internal_1 (const char *var
, ptrdiff_t varlen
, char **value
,
1374 ptrdiff_t *valuelen
, Lisp_Object env
)
1376 for (; CONSP (env
); env
= XCDR (env
))
1378 Lisp_Object entry
= XCAR (env
);
1380 && SBYTES (entry
) >= varlen
1382 /* NT environment variables are case insensitive. */
1383 && ! strnicmp (SDATA (entry
), var
, varlen
)
1384 #else /* not WINDOWSNT */
1385 && ! memcmp (SDATA (entry
), var
, varlen
)
1386 #endif /* not WINDOWSNT */
1389 if (SBYTES (entry
) > varlen
&& SREF (entry
, varlen
) == '=')
1391 *value
= SSDATA (entry
) + (varlen
+ 1);
1392 *valuelen
= SBYTES (entry
) - (varlen
+ 1);
1395 else if (SBYTES (entry
) == varlen
)
1397 /* Lone variable names in Vprocess_environment mean that
1398 variable should be removed from the environment. */
1408 getenv_internal (const char *var
, ptrdiff_t varlen
, char **value
,
1409 ptrdiff_t *valuelen
, Lisp_Object frame
)
1411 /* Try to find VAR in Vprocess_environment first. */
1412 if (getenv_internal_1 (var
, varlen
, value
, valuelen
,
1413 Vprocess_environment
))
1414 return *value
? 1 : 0;
1416 /* For DISPLAY try to get the values from the frame or the initial env. */
1417 if (strcmp (var
, "DISPLAY") == 0)
1420 = Fframe_parameter (NILP (frame
) ? selected_frame
: frame
, Qdisplay
);
1421 if (STRINGP (display
))
1423 *value
= SSDATA (display
);
1424 *valuelen
= SBYTES (display
);
1427 /* If still not found, Look for DISPLAY in Vinitial_environment. */
1428 if (getenv_internal_1 (var
, varlen
, value
, valuelen
,
1429 Vinitial_environment
))
1430 return *value
? 1 : 0;
1436 DEFUN ("getenv-internal", Fgetenv_internal
, Sgetenv_internal
, 1, 2, 0,
1437 doc
: /* Get the value of environment variable VARIABLE.
1438 VARIABLE should be a string. Value is nil if VARIABLE is undefined in
1439 the environment. Otherwise, value is a string.
1441 This function searches `process-environment' for VARIABLE.
1443 If optional parameter ENV is a list, then search this list instead of
1444 `process-environment', and return t when encountering a negative entry
1445 \(an entry for a variable with no value). */)
1446 (Lisp_Object variable
, Lisp_Object env
)
1451 CHECK_STRING (variable
);
1454 if (getenv_internal_1 (SSDATA (variable
), SBYTES (variable
),
1455 &value
, &valuelen
, env
))
1456 return value
? make_string (value
, valuelen
) : Qt
;
1460 else if (getenv_internal (SSDATA (variable
), SBYTES (variable
),
1461 &value
, &valuelen
, env
))
1462 return make_string (value
, valuelen
);
1467 /* A version of getenv that consults the Lisp environment lists,
1468 easily callable from C. */
1470 egetenv (const char *var
)
1475 if (getenv_internal (var
, strlen (var
), &value
, &valuelen
, Qnil
))
1482 /* This is run before init_cmdargs. */
1485 init_callproc_1 (void)
1488 const char *etc_dir
= ns_etc_directory ();
1489 const char *path_exec
= ns_exec_path ();
1492 Vdata_directory
= decode_env_path ("EMACSDATA",
1497 Vdata_directory
= Ffile_name_as_directory (Fcar (Vdata_directory
));
1499 Vdoc_directory
= decode_env_path ("EMACSDOC",
1504 Vdoc_directory
= Ffile_name_as_directory (Fcar (Vdoc_directory
));
1506 /* Check the EMACSPATH environment variable, defaulting to the
1507 PATH_EXEC path from epaths.h. */
1508 Vexec_path
= decode_env_path ("EMACSPATH",
1510 path_exec
? path_exec
:
1513 Vexec_directory
= Ffile_name_as_directory (Fcar (Vexec_path
));
1514 /* FIXME? For ns, path_exec should go at the front? */
1515 Vexec_path
= nconc2 (decode_env_path ("PATH", ""), Vexec_path
);
1518 /* This is run after init_cmdargs, when Vinstallation_directory is valid. */
1521 init_callproc (void)
1523 char *data_dir
= egetenv ("EMACSDATA");
1526 Lisp_Object tempdir
;
1530 const char *etc_dir
= ns_etc_directory ();
1533 data_dir
= alloca (strlen (etc_dir
) + 1);
1534 strcpy (data_dir
, etc_dir
);
1539 if (!NILP (Vinstallation_directory
))
1541 /* Add to the path the lib-src subdir of the installation dir. */
1543 tem
= Fexpand_file_name (build_string ("lib-src"),
1544 Vinstallation_directory
);
1546 /* MSDOS uses wrapped binaries, so don't do this. */
1547 if (NILP (Fmember (tem
, Vexec_path
)))
1550 const char *path_exec
= ns_exec_path ();
1552 Vexec_path
= decode_env_path ("EMACSPATH",
1554 path_exec
? path_exec
:
1557 Vexec_path
= Fcons (tem
, Vexec_path
);
1558 Vexec_path
= nconc2 (decode_env_path ("PATH", ""), Vexec_path
);
1561 Vexec_directory
= Ffile_name_as_directory (tem
);
1562 #endif /* not MSDOS */
1564 /* Maybe use ../etc as well as ../lib-src. */
1567 tem
= Fexpand_file_name (build_string ("etc"),
1568 Vinstallation_directory
);
1569 Vdoc_directory
= Ffile_name_as_directory (tem
);
1573 /* Look for the files that should be in etc. We don't use
1574 Vinstallation_directory, because these files are never installed
1575 near the executable, and they are never in the build
1576 directory when that's different from the source directory.
1578 Instead, if these files are not in the nominal place, we try the
1579 source directory. */
1582 Lisp_Object tem
, tem1
, srcdir
;
1584 srcdir
= Fexpand_file_name (build_string ("../src/"),
1585 build_string (PATH_DUMPLOADSEARCH
));
1586 tem
= Fexpand_file_name (build_string ("GNU"), Vdata_directory
);
1587 tem1
= Ffile_exists_p (tem
);
1588 if (!NILP (Fequal (srcdir
, Vinvocation_directory
)) || NILP (tem1
))
1591 newdir
= Fexpand_file_name (build_string ("../etc/"),
1592 build_string (PATH_DUMPLOADSEARCH
));
1593 tem
= Fexpand_file_name (build_string ("GNU"), newdir
);
1594 tem1
= Ffile_exists_p (tem
);
1596 Vdata_directory
= newdir
;
1604 tempdir
= Fdirectory_file_name (Vexec_directory
);
1605 if (! file_accessible_directory_p (SSDATA (tempdir
)))
1606 dir_warning ("arch-dependent data dir", Vexec_directory
);
1609 tempdir
= Fdirectory_file_name (Vdata_directory
);
1610 if (! file_accessible_directory_p (SSDATA (tempdir
)))
1611 dir_warning ("arch-independent data dir", Vdata_directory
);
1613 sh
= (char *) getenv ("SHELL");
1614 Vshell_file_name
= build_string (sh
? sh
: "/bin/sh");
1617 Vshared_game_score_directory
= Qnil
;
1619 Vshared_game_score_directory
= build_string (PATH_GAME
);
1620 if (NILP (Ffile_accessible_directory_p (Vshared_game_score_directory
)))
1621 Vshared_game_score_directory
= Qnil
;
1626 set_initial_environment (void)
1629 for (envp
= environ
; *envp
; envp
++)
1630 Vprocess_environment
= Fcons (build_string (*envp
),
1631 Vprocess_environment
);
1632 /* Ideally, the `copy' shouldn't be necessary, but it seems it's frequent
1633 to use `delete' and friends on process-environment. */
1634 Vinitial_environment
= Fcopy_sequence (Vprocess_environment
);
1638 syms_of_callproc (void)
1641 Vtemp_file_name_pattern
= build_string ("emacsXXXXXX");
1642 #elif defined (WINDOWSNT)
1643 Vtemp_file_name_pattern
= build_string ("emXXXXXX");
1645 Vtemp_file_name_pattern
= build_string ("detmp.XXX");
1647 staticpro (&Vtemp_file_name_pattern
);
1649 DEFVAR_LISP ("shell-file-name", Vshell_file_name
,
1650 doc
: /* File name to load inferior shells from.
1651 Initialized from the SHELL environment variable, or to a system-dependent
1652 default if SHELL is not set. */);
1654 DEFVAR_LISP ("exec-path", Vexec_path
,
1655 doc
: /* List of directories to search programs to run in subprocesses.
1656 Each element is a string (directory name) or nil (try default directory). */);
1658 DEFVAR_LISP ("exec-suffixes", Vexec_suffixes
,
1659 doc
: /* List of suffixes to try to find executable file names.
1660 Each element is a string. */);
1661 Vexec_suffixes
= Qnil
;
1663 DEFVAR_LISP ("exec-directory", Vexec_directory
,
1664 doc
: /* Directory for executables for Emacs to invoke.
1665 More generally, this includes any architecture-dependent files
1666 that are built and installed from the Emacs distribution. */);
1668 DEFVAR_LISP ("data-directory", Vdata_directory
,
1669 doc
: /* Directory of machine-independent files that come with GNU Emacs.
1670 These are files intended for Emacs to use while it runs. */);
1672 DEFVAR_LISP ("doc-directory", Vdoc_directory
,
1673 doc
: /* Directory containing the DOC file that comes with GNU Emacs.
1674 This is usually the same as `data-directory'. */);
1676 DEFVAR_LISP ("configure-info-directory", Vconfigure_info_directory
,
1677 doc
: /* For internal use by the build procedure only.
1678 This is the name of the directory in which the build procedure installed
1679 Emacs's info files; the default value for `Info-default-directory-list'
1681 Vconfigure_info_directory
= build_string (PATH_INFO
);
1683 DEFVAR_LISP ("shared-game-score-directory", Vshared_game_score_directory
,
1684 doc
: /* Directory of score files for games which come with GNU Emacs.
1685 If this variable is nil, then Emacs is unable to use a shared directory. */);
1687 Vshared_game_score_directory
= Qnil
;
1689 Vshared_game_score_directory
= build_string (PATH_GAME
);
1692 DEFVAR_LISP ("initial-environment", Vinitial_environment
,
1693 doc
: /* List of environment variables inherited from the parent process.
1694 Each element should be a string of the form ENVVARNAME=VALUE.
1695 The elements must normally be decoded (using `locale-coding-system') for use. */);
1696 Vinitial_environment
= Qnil
;
1698 DEFVAR_LISP ("process-environment", Vprocess_environment
,
1699 doc
: /* List of overridden environment variables for subprocesses to inherit.
1700 Each element should be a string of the form ENVVARNAME=VALUE.
1702 Entries in this list take precedence to those in the frame-local
1703 environments. Therefore, let-binding `process-environment' is an easy
1704 way to temporarily change the value of an environment variable,
1705 irrespective of where it comes from. To use `process-environment' to
1706 remove an environment variable, include only its name in the list,
1709 This variable is set to nil when Emacs starts.
1711 If multiple entries define the same variable, the first one always
1714 Non-ASCII characters are encoded according to the initial value of
1715 `locale-coding-system', i.e. the elements must normally be decoded for
1718 See `setenv' and `getenv'. */);
1719 Vprocess_environment
= Qnil
;
1721 defsubr (&Scall_process
);
1722 defsubr (&Sgetenv_internal
);
1723 defsubr (&Scall_process_region
);