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)
92 sigemptyset (&blocked
);
93 sigaddset (&blocked
, SIGCHLD
);
94 pthread_sigmask (SIG_BLOCK
, &blocked
, 0);
98 /* Unblock SIGCHLD. */
101 unblock_child_signal (void)
104 pthread_sigmask (SIG_SETMASK
, &empty_mask
, 0);
108 /* Clean up when exiting call_process_cleanup. */
111 call_process_kill (Lisp_Object ignored
)
113 if (0 <= synch_process_fd
)
114 emacs_close (synch_process_fd
);
116 /* If PID is reapable, kill it and record it as a deleted process.
117 Do this in a critical section. Unless PID is wedged it will be
118 reaped on receipt of the first SIGCHLD after the critical section. */
119 if (synch_process_pid
)
121 block_child_signal ();
122 record_deleted_pid (synch_process_pid
);
123 EMACS_KILLPG (synch_process_pid
, SIGKILL
);
124 unblock_child_signal ();
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. */
135 call_process_cleanup (Lisp_Object arg
)
138 Lisp_Object buffer
= Fcar (arg
);
139 Lisp_Object file
= Fcdr (arg
);
141 Lisp_Object buffer
= arg
;
144 Fset_buffer (buffer
);
147 /* If the process still exists, kill its process group. */
148 if (synch_process_pid
)
150 ptrdiff_t count
= SPECPDL_INDEX ();
151 EMACS_KILLPG (synch_process_pid
, SIGINT
);
152 record_unwind_protect (call_process_kill
, make_number (0));
153 message1 ("Waiting for process to die...(type C-g again to kill it instantly)");
156 wait_for_termination (synch_process_pid
, 0, 1);
157 synch_process_pid
= 0;
159 specpdl_ptr
= specpdl
+ count
; /* Discard the unwind protect. */
160 message1 ("Waiting for process to die...done");
164 if (0 <= synch_process_fd
)
165 emacs_close (synch_process_fd
);
168 /* FILE is "" when we didn't actually create a temporary file in
170 if (!(strcmp (SDATA (file
), NULL_DEVICE
) == 0 || SREF (file
, 0) == '\0'))
171 unlink (SDATA (file
));
177 DEFUN ("call-process", Fcall_process
, Scall_process
, 1, MANY
, 0,
178 doc
: /* Call PROGRAM synchronously in separate process.
179 The remaining arguments are optional.
180 The program's input comes from file INFILE (nil means `/dev/null').
181 Insert output in BUFFER before point; t means current buffer; nil for BUFFER
182 means discard it; 0 means discard and don't wait; and `(:file FILE)', where
183 FILE is a file name string, means that it should be written to that file
184 \(if the file already exists it is overwritten).
185 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,
186 REAL-BUFFER says what to do with standard output, as above,
187 while STDERR-FILE says what to do with standard error in the child.
188 STDERR-FILE may be nil (discard standard error output),
189 t (mix it with ordinary output), or a file name string.
191 Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted.
192 Remaining arguments are strings passed as command arguments to PROGRAM.
194 If executable PROGRAM can't be found as an executable, `call-process'
195 signals a Lisp error. `call-process' reports errors in execution of
196 the program only through its return and output.
198 If BUFFER is 0, `call-process' returns immediately with value nil.
199 Otherwise it waits for PROGRAM to terminate
200 and returns a numeric exit status or a signal description string.
201 If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.
203 usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
204 (ptrdiff_t nargs
, Lisp_Object
*args
)
206 Lisp_Object infile
, buffer
, current_dir
, path
;
208 int fd0
, fd1
, filefd
;
210 ptrdiff_t count
= SPECPDL_INDEX ();
214 /* File to use for stderr in the child.
215 t means use same as standard output. */
216 Lisp_Object error_file
;
217 Lisp_Object output_file
= Qnil
;
218 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
219 char *outf
, *tempfile
= NULL
;
227 struct coding_system process_coding
; /* coding-system of process output */
228 struct coding_system argument_coding
; /* coding-system of arguments */
229 /* Set to the return value of Ffind_operation_coding_system. */
230 Lisp_Object coding_systems
;
231 bool output_to_buffer
= 1;
233 /* Qt denotes that Ffind_operation_coding_system is not yet called. */
236 CHECK_STRING (args
[0]);
241 /* Without asynchronous processes we cannot have BUFFER == 0. */
243 && (INTEGERP (CONSP (args
[2]) ? XCAR (args
[2]) : args
[2])))
244 error ("Operating system cannot handle asynchronous subprocesses");
245 #endif /* subprocesses */
247 /* Decide the coding-system for giving arguments. */
249 Lisp_Object val
, *args2
;
252 /* If arguments are supplied, we may have to encode them. */
255 bool must_encode
= 0;
256 Lisp_Object coding_attrs
;
258 for (i
= 4; i
< nargs
; i
++)
259 CHECK_STRING (args
[i
]);
261 for (i
= 4; i
< nargs
; i
++)
262 if (STRING_MULTIBYTE (args
[i
]))
265 if (!NILP (Vcoding_system_for_write
))
266 val
= Vcoding_system_for_write
;
267 else if (! must_encode
)
271 SAFE_NALLOCA (args2
, 1, nargs
+ 1);
272 args2
[0] = Qcall_process
;
273 for (i
= 0; i
< nargs
; i
++) args2
[i
+ 1] = args
[i
];
274 coding_systems
= Ffind_operation_coding_system (nargs
+ 1, args2
);
275 val
= CONSP (coding_systems
) ? XCDR (coding_systems
) : Qnil
;
277 val
= complement_process_encoding_system (val
);
278 setup_coding_system (Fcheck_coding_system (val
), &argument_coding
);
279 coding_attrs
= CODING_ID_ATTRS (argument_coding
.id
);
280 if (NILP (CODING_ATTR_ASCII_COMPAT (coding_attrs
)))
282 /* We should not use an ASCII incompatible coding system. */
283 val
= raw_text_coding_system (val
);
284 setup_coding_system (val
, &argument_coding
);
289 if (nargs
>= 2 && ! NILP (args
[1]))
291 infile
= Fexpand_file_name (args
[1], BVAR (current_buffer
, directory
));
292 CHECK_STRING (infile
);
295 infile
= build_string (NULL_DEVICE
);
301 /* If BUFFER is a list, its meaning is (BUFFER-FOR-STDOUT
302 FILE-FOR-STDERR), unless the first element is :file, in which case see
303 the next paragraph. */
305 && (! SYMBOLP (XCAR (buffer
))
306 || strcmp (SSDATA (SYMBOL_NAME (XCAR (buffer
))), ":file")))
308 if (CONSP (XCDR (buffer
)))
310 Lisp_Object stderr_file
;
311 stderr_file
= XCAR (XCDR (buffer
));
313 if (NILP (stderr_file
) || EQ (Qt
, stderr_file
))
314 error_file
= stderr_file
;
316 error_file
= Fexpand_file_name (stderr_file
, Qnil
);
319 buffer
= XCAR (buffer
);
322 /* If the buffer is (still) a list, it might be a (:file "file") spec. */
324 && SYMBOLP (XCAR (buffer
))
325 && ! strcmp (SSDATA (SYMBOL_NAME (XCAR (buffer
))), ":file"))
327 output_file
= Fexpand_file_name (XCAR (XCDR (buffer
)),
328 BVAR (current_buffer
, directory
));
329 CHECK_STRING (output_file
);
333 if (!(EQ (buffer
, Qnil
)
335 || INTEGERP (buffer
)))
337 Lisp_Object spec_buffer
;
338 spec_buffer
= buffer
;
339 buffer
= Fget_buffer_create (buffer
);
340 /* Mention the buffer name for a better error message. */
342 CHECK_BUFFER (spec_buffer
);
343 CHECK_BUFFER (buffer
);
349 /* Make sure that the child will be able to chdir to the current
350 buffer's current directory, or its unhandled equivalent. We
351 can't just have the child check for an error when it does the
352 chdir, since it's in a vfork.
354 We have to GCPRO around this because Fexpand_file_name,
355 Funhandled_file_name_directory, and Ffile_accessible_directory_p
356 might call a file name handling function. The argument list is
357 protected by the caller, so all we really have to worry about is
360 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
362 current_dir
= BVAR (current_buffer
, directory
);
364 GCPRO5 (infile
, buffer
, current_dir
, error_file
, output_file
);
366 current_dir
= Funhandled_file_name_directory (current_dir
);
367 if (NILP (current_dir
))
368 /* If the file name handler says that current_dir is unreachable, use
369 a sensible default. */
370 current_dir
= build_string ("~/");
371 current_dir
= expand_and_dir_to_file (current_dir
, Qnil
);
372 current_dir
= Ffile_name_as_directory (current_dir
);
374 if (NILP (Ffile_accessible_directory_p (current_dir
)))
375 report_file_error ("Setting current directory",
376 Fcons (BVAR (current_buffer
, directory
), Qnil
));
378 if (STRING_MULTIBYTE (infile
))
379 infile
= ENCODE_FILE (infile
);
380 if (STRING_MULTIBYTE (current_dir
))
381 current_dir
= ENCODE_FILE (current_dir
);
382 if (STRINGP (error_file
) && STRING_MULTIBYTE (error_file
))
383 error_file
= ENCODE_FILE (error_file
);
384 if (STRINGP (output_file
) && STRING_MULTIBYTE (output_file
))
385 output_file
= ENCODE_FILE (output_file
);
389 display_p
= INTERACTIVE
&& nargs
>= 4 && !NILP (args
[3]);
391 filefd
= emacs_open (SSDATA (infile
), O_RDONLY
, 0);
394 infile
= DECODE_FILE (infile
);
395 report_file_error ("Opening process input file", Fcons (infile
, Qnil
));
398 if (STRINGP (output_file
))
401 fd_output
= emacs_open (SSDATA (output_file
),
402 O_WRONLY
| O_TRUNC
| O_CREAT
| O_TEXT
,
404 #else /* not DOS_NT */
405 fd_output
= creat (SSDATA (output_file
), 0666);
406 #endif /* not DOS_NT */
409 output_file
= DECODE_FILE (output_file
);
410 report_file_error ("Opening process output file",
411 Fcons (output_file
, Qnil
));
413 if (STRINGP (error_file
) || NILP (error_file
))
414 output_to_buffer
= 0;
417 /* Search for program; barf if not found. */
419 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
;
421 GCPRO4 (infile
, buffer
, current_dir
, error_file
);
422 openp (Vexec_path
, args
[0], Vexec_suffixes
, &path
, make_number (X_OK
));
427 emacs_close (filefd
);
428 report_file_error ("Searching for program", Fcons (args
[0], Qnil
));
431 /* If program file name starts with /: for quoting a magic name,
433 if (SBYTES (path
) > 2 && SREF (path
, 0) == '/'
434 && SREF (path
, 1) == ':')
435 path
= Fsubstring (path
, make_number (2), Qnil
);
437 new_argv
= SAFE_ALLOCA ((nargs
> 4 ? nargs
- 2 : 2) * sizeof *new_argv
);
441 struct gcpro gcpro1
, gcpro2
, gcpro3
, gcpro4
, gcpro5
;
443 GCPRO5 (infile
, buffer
, current_dir
, path
, error_file
);
444 argument_coding
.dst_multibyte
= 0;
445 for (i
= 4; i
< nargs
; i
++)
447 argument_coding
.src_multibyte
= STRING_MULTIBYTE (args
[i
]);
448 if (CODING_REQUIRE_ENCODING (&argument_coding
))
449 /* We must encode this argument. */
450 args
[i
] = encode_coding_string (&argument_coding
, args
[i
], 1);
453 for (i
= 4; i
< nargs
; i
++)
454 new_argv
[i
- 3] = SSDATA (args
[i
]);
459 new_argv
[0] = SSDATA (path
);
461 #ifdef MSDOS /* MW, July 1993 */
463 /* If we're redirecting STDOUT to a file, that file is already open
467 if ((outf
= egetenv ("TMPDIR")))
468 strcpy (tempfile
= alloca (strlen (outf
) + 20), outf
);
471 tempfile
= alloca (20);
474 dostounix_filename (tempfile
);
475 if (*tempfile
== '\0' || tempfile
[strlen (tempfile
) - 1] != '/')
476 strcat (tempfile
, "/");
477 strcat (tempfile
, "detmp.XXX");
479 outfilefd
= creat (tempfile
, S_IREAD
| S_IWRITE
);
481 emacs_close (filefd
);
482 report_file_error ("Opening process output file",
483 Fcons (build_string (tempfile
), Qnil
));
487 outfilefd
= fd_output
;
492 if (INTEGERP (buffer
))
495 fd1
= emacs_open (NULL_DEVICE
, O_WRONLY
, 0);
503 int pipe_errno
= errno
;
504 emacs_close (filefd
);
506 report_file_error ("Creating process pipe", Qnil
);
519 if (NILP (error_file
))
520 fd_error
= emacs_open (NULL_DEVICE
, O_WRONLY
, 0);
521 else if (STRINGP (error_file
))
524 fd_error
= emacs_open (SSDATA (error_file
),
525 O_WRONLY
| O_TRUNC
| O_CREAT
| O_TEXT
,
527 #else /* not DOS_NT */
528 fd_error
= creat (SSDATA (error_file
), 0666);
529 #endif /* not DOS_NT */
534 emacs_close (filefd
);
542 if (NILP (error_file
))
543 error_file
= build_string (NULL_DEVICE
);
544 else if (STRINGP (error_file
))
545 error_file
= DECODE_FILE (error_file
);
546 report_file_error ("Cannot redirect stderr", Fcons (error_file
, Qnil
));
549 #ifdef MSDOS /* MW, July 1993 */
550 /* Note that on MSDOS `child_setup' actually returns the child process
551 exit status, not its PID, so assign it to status below. */
552 pid
= child_setup (filefd
, outfilefd
, fd_error
, new_argv
, 0, current_dir
);
555 emacs_close (outfilefd
);
556 if (fd_error
!= outfilefd
)
557 emacs_close (fd_error
);
560 synchronize_system_messages_locale ();
562 code_convert_string_norecord (build_string (strerror (child_errno
)),
563 Vlocale_coding_system
, 0);
566 fd1
= -1; /* No harm in closing that one! */
569 /* Since CRLF is converted to LF within `decode_coding', we
570 can always open a file with binary mode. */
571 fd0
= emacs_open (tempfile
, O_RDONLY
| O_BINARY
, 0);
575 emacs_close (filefd
);
576 report_file_error ("Cannot re-open temporary file",
577 Fcons (build_string (tempfile
), Qnil
));
581 fd0
= -1; /* We are not going to read from tempfile. */
582 #else /* not MSDOS */
584 /* Do the unwind-protect now, even though the pid is not known, so
585 that no storage allocation is done in the critical section.
586 The actual PID will be filled in during the critical section. */
587 synch_process_pid
= 0;
588 synch_process_fd
= fd0
;
589 record_unwind_protect (call_process_cleanup
, Fcurrent_buffer ());
592 block_child_signal ();
595 pid
= child_setup (filefd
, fd1
, fd_error
, new_argv
, 0, current_dir
);
596 #else /* not WINDOWSNT */
598 /* vfork, and prevent local vars from being clobbered by the vfork. */
600 Lisp_Object
volatile buffer_volatile
= buffer
;
601 Lisp_Object
volatile coding_systems_volatile
= coding_systems
;
602 Lisp_Object
volatile current_dir_volatile
= current_dir
;
603 bool volatile display_p_volatile
= display_p
;
604 bool volatile output_to_buffer_volatile
= output_to_buffer
;
605 bool volatile sa_must_free_volatile
= sa_must_free
;
606 int volatile fd0_volatile
= fd0
;
607 int volatile fd1_volatile
= fd1
;
608 int volatile fd_error_volatile
= fd_error
;
609 int volatile fd_output_volatile
= fd_output
;
610 int volatile filefd_volatile
= filefd
;
611 ptrdiff_t volatile count_volatile
= count
;
612 ptrdiff_t volatile sa_count_volatile
= sa_count
;
613 char **volatile new_argv_volatile
= new_argv
;
618 buffer
= buffer_volatile
;
619 coding_systems
= coding_systems_volatile
;
620 current_dir
= current_dir_volatile
;
621 display_p
= display_p_volatile
;
622 output_to_buffer
= output_to_buffer_volatile
;
623 sa_must_free
= sa_must_free_volatile
;
626 fd_error
= fd_error_volatile
;
627 fd_output
= fd_output_volatile
;
628 filefd
= filefd_volatile
;
629 count
= count_volatile
;
630 sa_count
= sa_count_volatile
;
631 new_argv
= new_argv_volatile
;
636 unblock_child_signal ();
643 /* Emacs ignores SIGPIPE, but the child should not. */
644 signal (SIGPIPE
, SIG_DFL
);
646 child_setup (filefd
, fd1
, fd_error
, new_argv
, 0, current_dir
);
649 #endif /* not WINDOWSNT */
655 if (INTEGERP (buffer
))
656 record_deleted_pid (pid
);
658 synch_process_pid
= pid
;
661 unblock_child_signal ();
664 /* The MSDOS case did this already. */
666 emacs_close (fd_error
);
667 #endif /* not MSDOS */
669 /* Close most of our file descriptors, but not fd0
670 since we will use that to read input from. */
671 emacs_close (filefd
);
673 emacs_close (fd_output
);
674 if (fd1
>= 0 && fd1
!= fd_error
)
681 report_file_error ("Doing vfork", Qnil
);
684 if (INTEGERP (buffer
))
692 /* MSDOS needs different cleanup information. */
693 record_unwind_protect (call_process_cleanup
,
694 Fcons (Fcurrent_buffer (),
695 build_string (tempfile
? tempfile
: "")));
698 if (BUFFERP (buffer
))
699 Fset_buffer (buffer
);
703 /* If BUFFER is nil, we must read process output once and then
704 discard it, so setup coding system but with nil. */
705 setup_coding_system (Qnil
, &process_coding
);
706 process_coding
.dst_multibyte
= 0;
710 Lisp_Object val
, *args2
;
713 if (!NILP (Vcoding_system_for_read
))
714 val
= Vcoding_system_for_read
;
717 if (EQ (coding_systems
, Qt
))
721 SAFE_NALLOCA (args2
, 1, nargs
+ 1);
722 args2
[0] = Qcall_process
;
723 for (i
= 0; i
< nargs
; i
++) args2
[i
+ 1] = args
[i
];
725 = Ffind_operation_coding_system (nargs
+ 1, args2
);
727 if (CONSP (coding_systems
))
728 val
= XCAR (coding_systems
);
729 else if (CONSP (Vdefault_process_coding_system
))
730 val
= XCAR (Vdefault_process_coding_system
);
734 Fcheck_coding_system (val
);
735 /* In unibyte mode, character code conversion should not take
736 place but EOL conversion should. So, setup raw-text or one
737 of the subsidiary according to the information just setup. */
738 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
))
740 val
= raw_text_coding_system (val
);
741 setup_coding_system (val
, &process_coding
);
742 process_coding
.dst_multibyte
743 = ! NILP (BVAR (current_buffer
, enable_multibyte_characters
));
745 process_coding
.src_multibyte
= 0;
750 if (output_to_buffer
)
752 enum { CALLPROC_BUFFER_SIZE_MIN
= 16 * 1024 };
753 enum { CALLPROC_BUFFER_SIZE_MAX
= 4 * CALLPROC_BUFFER_SIZE_MIN
};
754 char buf
[CALLPROC_BUFFER_SIZE_MAX
];
755 int bufsize
= CALLPROC_BUFFER_SIZE_MIN
;
758 EMACS_INT total_read
= 0;
760 bool display_on_the_fly
= display_p
;
761 struct coding_system saved_coding
;
763 saved_coding
= process_coding
;
766 /* Repeatedly read until we've filled as much as possible
767 of the buffer size we have. But don't read
768 less than 1024--save that for the next bufferful. */
770 while (nread
< bufsize
- 1024)
772 int this_read
= emacs_read (fd0
, buf
+ nread
,
780 process_coding
.mode
|= CODING_MODE_LAST_BLOCK
;
785 total_read
+= this_read
;
787 if (display_on_the_fly
)
791 /* Now NREAD is the total amount of data in the buffer. */
796 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
))
797 && ! CODING_MAY_REQUIRE_DECODING (&process_coding
))
798 insert_1_both (buf
, nread
, nread
, 0, 1, 0);
800 { /* We have to decode the input. */
802 ptrdiff_t count1
= SPECPDL_INDEX ();
804 XSETBUFFER (curbuf
, current_buffer
);
805 /* We cannot allow after-change-functions be run
806 during decoding, because that might modify the
807 buffer, while we rely on process_coding.produced to
808 faithfully reflect inserted text until we
809 TEMP_SET_PT_BOTH below. */
810 specbind (Qinhibit_modification_hooks
, Qt
);
811 decode_coding_c_string (&process_coding
,
812 (unsigned char *) buf
, nread
, curbuf
);
813 unbind_to (count1
, Qnil
);
814 if (display_on_the_fly
815 && CODING_REQUIRE_DETECTION (&saved_coding
)
816 && ! CODING_REQUIRE_DETECTION (&process_coding
))
818 /* We have detected some coding system. But,
819 there's a possibility that the detection was
820 done by insufficient data. So, we give up
821 displaying on the fly. */
822 if (process_coding
.produced
> 0)
823 del_range_2 (process_coding
.dst_pos
,
824 process_coding
.dst_pos_byte
,
825 process_coding
.dst_pos
826 + process_coding
.produced_char
,
827 process_coding
.dst_pos_byte
828 + process_coding
.produced
, 0);
829 display_on_the_fly
= 0;
830 process_coding
= saved_coding
;
832 /* This is to make the above condition always
833 fails in the future. */
834 saved_coding
.common_flags
835 &= ~CODING_REQUIRE_DETECTION_MASK
;
839 TEMP_SET_PT_BOTH (PT
+ process_coding
.produced_char
,
840 PT_BYTE
+ process_coding
.produced
);
841 carryover
= process_coding
.carryover_bytes
;
843 memcpy (buf
, process_coding
.carryover
,
844 process_coding
.carryover_bytes
);
848 if (process_coding
.mode
& CODING_MODE_LAST_BLOCK
)
851 /* Make the buffer bigger as we continue to read more data,
852 but not past CALLPROC_BUFFER_SIZE_MAX. */
853 if (bufsize
< CALLPROC_BUFFER_SIZE_MAX
&& total_read
> 32 * bufsize
)
854 if ((bufsize
*= 2) > CALLPROC_BUFFER_SIZE_MAX
)
855 bufsize
= CALLPROC_BUFFER_SIZE_MAX
;
860 prepare_menu_bars ();
862 redisplay_preserve_echo_area (1);
863 /* This variable might have been set to 0 for code
864 detection. In that case, we set it back to 1 because
865 we should have already detected a coding system. */
866 display_on_the_fly
= 1;
873 Vlast_coding_system_used
= CODING_ID_NAME (process_coding
.id
);
874 /* If the caller required, let the buffer inherit the
875 coding-system used to decode the process output. */
876 if (inherit_process_coding_system
)
877 call1 (intern ("after-insert-file-set-buffer-file-coding-system"),
878 make_number (total_read
));
882 /* Wait for it to terminate, unless it already has. */
883 wait_for_termination (pid
, &status
, !output_to_buffer
);
888 /* Don't kill any children that the subprocess may have left behind
890 synch_process_pid
= 0;
893 unbind_to (count
, Qnil
);
895 if (WIFSIGNALED (status
))
899 synchronize_system_messages_locale ();
900 signame
= strsignal (WTERMSIG (status
));
905 return code_convert_string_norecord (build_string (signame
),
906 Vlocale_coding_system
, 0);
909 eassert (WIFEXITED (status
));
910 return make_number (WEXITSTATUS (status
));
914 delete_temp_file (Lisp_Object name
)
916 /* Suppress jka-compr handling, etc. */
917 ptrdiff_t count
= SPECPDL_INDEX ();
918 specbind (intern ("file-name-handler-alist"), Qnil
);
919 internal_delete_file (name
);
920 unbind_to (count
, Qnil
);
924 DEFUN ("call-process-region", Fcall_process_region
, Scall_process_region
,
926 doc
: /* Send text from START to END to a synchronous process running PROGRAM.
927 The remaining arguments are optional.
928 Delete the text if fourth arg DELETE is non-nil.
930 Insert output in BUFFER before point; t means current buffer; nil for
931 BUFFER means discard it; 0 means discard and don't wait; and `(:file
932 FILE)', where FILE is a file name string, means that it should be
933 written to that file (if the file already exists it is overwritten).
934 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,
935 REAL-BUFFER says what to do with standard output, as above,
936 while STDERR-FILE says what to do with standard error in the child.
937 STDERR-FILE may be nil (discard standard error output),
938 t (mix it with ordinary output), or a file name string.
940 Sixth arg DISPLAY non-nil means redisplay buffer as output is inserted.
941 Remaining args are passed to PROGRAM at startup as command args.
943 If BUFFER is 0, `call-process-region' returns immediately with value nil.
944 Otherwise it waits for PROGRAM to terminate
945 and returns a numeric exit status or a signal description string.
946 If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.
948 usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &rest ARGS) */)
949 (ptrdiff_t nargs
, Lisp_Object
*args
)
952 Lisp_Object filename_string
;
953 register Lisp_Object start
, end
;
954 ptrdiff_t count
= SPECPDL_INDEX ();
955 /* Qt denotes we have not yet called Ffind_operation_coding_system. */
956 Lisp_Object coding_systems
;
957 Lisp_Object val
, *args2
;
961 if (STRINGP (Vtemporary_file_directory
))
962 tmpdir
= Vtemporary_file_directory
;
966 if (getenv ("TMPDIR"))
967 tmpdir
= build_string (getenv ("TMPDIR"));
969 tmpdir
= build_string ("/tmp/");
972 if ((outf
= egetenv ("TMPDIR"))
973 || (outf
= egetenv ("TMP"))
974 || (outf
= egetenv ("TEMP")))
975 tmpdir
= build_string (outf
);
977 tmpdir
= Ffile_name_as_directory (build_string ("c:/temp"));
983 Lisp_Object pattern
= Fexpand_file_name (Vtemp_file_name_pattern
, tmpdir
);
984 char *tempfile
= SAFE_ALLOCA (SBYTES (pattern
) + 1);
985 memcpy (tempfile
, SDATA (pattern
), SBYTES (pattern
) + 1);
993 fd
= mkstemp (tempfile
);
996 report_file_error ("Failed to open temporary file",
997 Fcons (build_string (tempfile
), Qnil
));
1005 filename_string
= build_string (tempfile
);
1006 GCPRO1 (filename_string
);
1012 /* Decide coding-system of the contents of the temporary file. */
1013 if (!NILP (Vcoding_system_for_write
))
1014 val
= Vcoding_system_for_write
;
1015 else if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
1020 SAFE_NALLOCA (args2
, 1, nargs
+ 1);
1021 args2
[0] = Qcall_process_region
;
1022 for (i
= 0; i
< nargs
; i
++) args2
[i
+ 1] = args
[i
];
1023 coding_systems
= Ffind_operation_coding_system (nargs
+ 1, args2
);
1024 val
= CONSP (coding_systems
) ? XCDR (coding_systems
) : Qnil
;
1027 val
= complement_process_encoding_system (val
);
1030 ptrdiff_t count1
= SPECPDL_INDEX ();
1032 specbind (intern ("coding-system-for-write"), val
);
1033 /* POSIX lets mk[s]temp use "."; don't invoke jka-compr if we
1034 happen to get a ".Z" suffix. */
1035 specbind (intern ("file-name-handler-alist"), Qnil
);
1036 Fwrite_region (start
, end
, filename_string
, Qnil
, Qlambda
, Qnil
, Qnil
);
1038 unbind_to (count1
, Qnil
);
1041 /* Note that Fcall_process takes care of binding
1042 coding-system-for-read. */
1044 record_unwind_protect (delete_temp_file
, filename_string
);
1046 if (nargs
> 3 && !NILP (args
[3]))
1047 Fdelete_region (start
, end
);
1059 args
[1] = filename_string
;
1061 RETURN_UNGCPRO (unbind_to (count
, Fcall_process (nargs
, args
)));
1065 static int relocate_fd (int fd
, int minfd
);
1069 add_env (char **env
, char **new_env
, char *string
)
1076 /* See if this string duplicates any string already in the env.
1077 If so, don't put it in.
1078 When an env var has multiple definitions,
1079 we keep the definition that comes first in process-environment. */
1080 for (ep
= env
; ok
&& ep
!= new_env
; ep
++)
1082 char *p
= *ep
, *q
= string
;
1088 /* The string is a lone variable name; keep it for now, we
1089 will remove it later. It is a placeholder for a
1090 variable that is not to be included in the environment. */
1098 *new_env
++ = string
;
1102 /* This is the last thing run in a newly forked inferior
1103 either synchronous or asynchronous.
1104 Copy descriptors IN, OUT and ERR as descriptors 0, 1 and 2.
1105 Initialize inferior's priority, pgrp, connected dir and environment.
1106 then exec another program based on new_argv.
1108 If SET_PGRP, put the subprocess into a separate process group.
1110 CURRENT_DIR is an elisp string giving the path of the current
1111 directory the subprocess should have. Since we can't really signal
1112 a decent error from within the child, this should be verified as an
1113 executable directory by the parent. */
1116 child_setup (int in
, int out
, int err
, char **new_argv
, bool set_pgrp
,
1117 Lisp_Object current_dir
)
1124 #endif /* WINDOWSNT */
1126 pid_t pid
= getpid ();
1128 /* Close Emacs's descriptors that this process should not have. */
1129 close_process_descs ();
1131 /* DOS_NT isn't in a vfork, so if we are in the middle of load-file,
1132 we will lose if we call close_load_descs here. */
1134 close_load_descs ();
1137 /* Note that use of alloca is always safe here. It's obvious for systems
1138 that do not have true vfork or that have true (stack) alloca.
1139 If using vfork and C_ALLOCA (when Emacs used to include
1140 src/alloca.c) it is safe because that changes the superior's
1141 static variables as if the superior had done alloca and will be
1142 cleaned up in the usual way. */
1144 register char *temp
;
1145 size_t i
; /* size_t, because ptrdiff_t might overflow here! */
1147 i
= SBYTES (current_dir
);
1149 /* MSDOS must have all environment variables malloc'ed, because
1150 low-level libc functions that launch subsidiary processes rely
1152 pwd_var
= xmalloc (i
+ 6);
1154 pwd_var
= alloca (i
+ 6);
1157 memcpy (pwd_var
, "PWD=", 4);
1158 memcpy (temp
, SDATA (current_dir
), i
);
1159 if (!IS_DIRECTORY_SEP (temp
[i
- 1])) temp
[i
++] = DIRECTORY_SEP
;
1163 /* We can't signal an Elisp error here; we're in a vfork. Since
1164 the callers check the current directory before forking, this
1165 should only return an error if the directory's permissions
1166 are changed between the check and this chdir, but we should
1168 if (chdir (temp
) < 0)
1171 /* Get past the drive letter, so that d:/ is left alone. */
1172 if (i
> 2 && IS_DEVICE_SEP (temp
[1]) && IS_DIRECTORY_SEP (temp
[2]))
1179 /* Strip trailing slashes for PWD, but leave "/" and "//" alone. */
1180 while (i
> 2 && IS_DIRECTORY_SEP (temp
[i
- 1]))
1184 /* Set `env' to a vector of the strings in the environment. */
1186 register Lisp_Object tem
;
1187 register char **new_env
;
1189 register int new_length
;
1190 Lisp_Object display
= Qnil
;
1194 for (tem
= Vprocess_environment
;
1195 CONSP (tem
) && STRINGP (XCAR (tem
));
1198 if (strncmp (SSDATA (XCAR (tem
)), "DISPLAY", 7) == 0
1199 && (SDATA (XCAR (tem
)) [7] == '\0'
1200 || SDATA (XCAR (tem
)) [7] == '='))
1201 /* DISPLAY is specified in process-environment. */
1206 /* If not provided yet, use the frame's DISPLAY. */
1209 Lisp_Object tmp
= Fframe_parameter (selected_frame
, Qdisplay
);
1210 if (!STRINGP (tmp
) && CONSP (Vinitial_environment
))
1211 /* If still not found, Look for DISPLAY in Vinitial_environment. */
1212 tmp
= Fgetenv_internal (build_string ("DISPLAY"),
1213 Vinitial_environment
);
1221 /* new_length + 2 to include PWD and terminating 0. */
1222 env
= new_env
= alloca ((new_length
+ 2) * sizeof *env
);
1223 /* If we have a PWD envvar, pass one down,
1224 but with corrected value. */
1225 if (egetenv ("PWD"))
1226 *new_env
++ = pwd_var
;
1228 if (STRINGP (display
))
1230 char *vdata
= alloca (sizeof "DISPLAY=" + SBYTES (display
));
1231 strcpy (vdata
, "DISPLAY=");
1232 strcat (vdata
, SSDATA (display
));
1233 new_env
= add_env (env
, new_env
, vdata
);
1237 for (tem
= Vprocess_environment
;
1238 CONSP (tem
) && STRINGP (XCAR (tem
));
1240 new_env
= add_env (env
, new_env
, SSDATA (XCAR (tem
)));
1244 /* Remove variable names without values. */
1248 while (*q
!= 0 && strchr (*q
, '=') == NULL
)
1258 prepare_standard_handles (in
, out
, err
, handles
);
1259 set_process_dir (SDATA (current_dir
));
1260 /* Spawn the child. (See ntproc.c:Spawnve). */
1261 cpid
= spawnve (_P_NOWAIT
, new_argv
[0], new_argv
, env
);
1262 reset_standard_handles (in
, out
, err
, handles
);
1264 /* An error occurred while trying to spawn the process. */
1265 report_file_error ("Spawning child process", Qnil
);
1268 #else /* not WINDOWSNT */
1269 /* Make sure that in, out, and err are not actually already in
1270 descriptors zero, one, or two; this could happen if Emacs is
1271 started with its standard in, out, or error closed, as might
1274 int oin
= in
, oout
= out
;
1276 /* We have to avoid relocating the same descriptor twice! */
1278 in
= relocate_fd (in
, 3);
1283 out
= relocate_fd (out
, 3);
1287 else if (err
== oout
)
1290 err
= relocate_fd (err
, 3);
1304 if (err
!= in
&& err
!= out
)
1310 execve (new_argv
[0], new_argv
, env
);
1312 emacs_write (1, "Can't exec program: ", 20);
1313 emacs_write (1, new_argv
[0], strlen (new_argv
[0]));
1314 emacs_write (1, "\n", 1);
1318 pid
= run_msdos_command (new_argv
, pwd_var
+ 4, in
, out
, err
, env
);
1321 /* An error occurred while trying to run the subprocess. */
1322 report_file_error ("Spawning child process", Qnil
);
1325 #endif /* not WINDOWSNT */
1329 /* Move the file descriptor FD so that its number is not less than MINFD.
1330 If the file descriptor is moved at all, the original is freed. */
1332 relocate_fd (int fd
, int minfd
)
1338 int new = fcntl (fd
, F_DUPFD
, minfd
);
1341 const char *message_1
= "Error while setting up child: ";
1342 const char *errmessage
= strerror (errno
);
1343 const char *message_2
= "\n";
1344 emacs_write (2, message_1
, strlen (message_1
));
1345 emacs_write (2, errmessage
, strlen (errmessage
));
1346 emacs_write (2, message_2
, strlen (message_2
));
1353 #endif /* not WINDOWSNT */
1356 getenv_internal_1 (const char *var
, ptrdiff_t varlen
, char **value
,
1357 ptrdiff_t *valuelen
, Lisp_Object env
)
1359 for (; CONSP (env
); env
= XCDR (env
))
1361 Lisp_Object entry
= XCAR (env
);
1363 && SBYTES (entry
) >= varlen
1365 /* NT environment variables are case insensitive. */
1366 && ! strnicmp (SDATA (entry
), var
, varlen
)
1367 #else /* not WINDOWSNT */
1368 && ! memcmp (SDATA (entry
), var
, varlen
)
1369 #endif /* not WINDOWSNT */
1372 if (SBYTES (entry
) > varlen
&& SREF (entry
, varlen
) == '=')
1374 *value
= SSDATA (entry
) + (varlen
+ 1);
1375 *valuelen
= SBYTES (entry
) - (varlen
+ 1);
1378 else if (SBYTES (entry
) == varlen
)
1380 /* Lone variable names in Vprocess_environment mean that
1381 variable should be removed from the environment. */
1391 getenv_internal (const char *var
, ptrdiff_t varlen
, char **value
,
1392 ptrdiff_t *valuelen
, Lisp_Object frame
)
1394 /* Try to find VAR in Vprocess_environment first. */
1395 if (getenv_internal_1 (var
, varlen
, value
, valuelen
,
1396 Vprocess_environment
))
1397 return *value
? 1 : 0;
1399 /* For DISPLAY try to get the values from the frame or the initial env. */
1400 if (strcmp (var
, "DISPLAY") == 0)
1403 = Fframe_parameter (NILP (frame
) ? selected_frame
: frame
, Qdisplay
);
1404 if (STRINGP (display
))
1406 *value
= SSDATA (display
);
1407 *valuelen
= SBYTES (display
);
1410 /* If still not found, Look for DISPLAY in Vinitial_environment. */
1411 if (getenv_internal_1 (var
, varlen
, value
, valuelen
,
1412 Vinitial_environment
))
1413 return *value
? 1 : 0;
1419 DEFUN ("getenv-internal", Fgetenv_internal
, Sgetenv_internal
, 1, 2, 0,
1420 doc
: /* Get the value of environment variable VARIABLE.
1421 VARIABLE should be a string. Value is nil if VARIABLE is undefined in
1422 the environment. Otherwise, value is a string.
1424 This function searches `process-environment' for VARIABLE.
1426 If optional parameter ENV is a list, then search this list instead of
1427 `process-environment', and return t when encountering a negative entry
1428 \(an entry for a variable with no value). */)
1429 (Lisp_Object variable
, Lisp_Object env
)
1434 CHECK_STRING (variable
);
1437 if (getenv_internal_1 (SSDATA (variable
), SBYTES (variable
),
1438 &value
, &valuelen
, env
))
1439 return value
? make_string (value
, valuelen
) : Qt
;
1443 else if (getenv_internal (SSDATA (variable
), SBYTES (variable
),
1444 &value
, &valuelen
, env
))
1445 return make_string (value
, valuelen
);
1450 /* A version of getenv that consults the Lisp environment lists,
1451 easily callable from C. */
1453 egetenv (const char *var
)
1458 if (getenv_internal (var
, strlen (var
), &value
, &valuelen
, Qnil
))
1465 /* This is run before init_cmdargs. */
1468 init_callproc_1 (void)
1471 const char *etc_dir
= ns_etc_directory ();
1472 const char *path_exec
= ns_exec_path ();
1475 Vdata_directory
= decode_env_path ("EMACSDATA",
1480 Vdata_directory
= Ffile_name_as_directory (Fcar (Vdata_directory
));
1482 Vdoc_directory
= decode_env_path ("EMACSDOC",
1487 Vdoc_directory
= Ffile_name_as_directory (Fcar (Vdoc_directory
));
1489 /* Check the EMACSPATH environment variable, defaulting to the
1490 PATH_EXEC path from epaths.h. */
1491 Vexec_path
= decode_env_path ("EMACSPATH",
1493 path_exec
? path_exec
:
1496 Vexec_directory
= Ffile_name_as_directory (Fcar (Vexec_path
));
1497 /* FIXME? For ns, path_exec should go at the front? */
1498 Vexec_path
= nconc2 (decode_env_path ("PATH", ""), Vexec_path
);
1501 /* This is run after init_cmdargs, when Vinstallation_directory is valid. */
1504 init_callproc (void)
1506 char *data_dir
= egetenv ("EMACSDATA");
1509 Lisp_Object tempdir
;
1513 const char *etc_dir
= ns_etc_directory ();
1516 data_dir
= alloca (strlen (etc_dir
) + 1);
1517 strcpy (data_dir
, etc_dir
);
1522 if (!NILP (Vinstallation_directory
))
1524 /* Add to the path the lib-src subdir of the installation dir. */
1526 tem
= Fexpand_file_name (build_string ("lib-src"),
1527 Vinstallation_directory
);
1529 /* MSDOS uses wrapped binaries, so don't do this. */
1530 if (NILP (Fmember (tem
, Vexec_path
)))
1533 const char *path_exec
= ns_exec_path ();
1535 Vexec_path
= decode_env_path ("EMACSPATH",
1537 path_exec
? path_exec
:
1540 Vexec_path
= Fcons (tem
, Vexec_path
);
1541 Vexec_path
= nconc2 (decode_env_path ("PATH", ""), Vexec_path
);
1544 Vexec_directory
= Ffile_name_as_directory (tem
);
1545 #endif /* not MSDOS */
1547 /* Maybe use ../etc as well as ../lib-src. */
1550 tem
= Fexpand_file_name (build_string ("etc"),
1551 Vinstallation_directory
);
1552 Vdoc_directory
= Ffile_name_as_directory (tem
);
1556 /* Look for the files that should be in etc. We don't use
1557 Vinstallation_directory, because these files are never installed
1558 near the executable, and they are never in the build
1559 directory when that's different from the source directory.
1561 Instead, if these files are not in the nominal place, we try the
1562 source directory. */
1565 Lisp_Object tem
, tem1
, srcdir
;
1567 srcdir
= Fexpand_file_name (build_string ("../src/"),
1568 build_string (PATH_DUMPLOADSEARCH
));
1569 tem
= Fexpand_file_name (build_string ("GNU"), Vdata_directory
);
1570 tem1
= Ffile_exists_p (tem
);
1571 if (!NILP (Fequal (srcdir
, Vinvocation_directory
)) || NILP (tem1
))
1574 newdir
= Fexpand_file_name (build_string ("../etc/"),
1575 build_string (PATH_DUMPLOADSEARCH
));
1576 tem
= Fexpand_file_name (build_string ("GNU"), newdir
);
1577 tem1
= Ffile_exists_p (tem
);
1579 Vdata_directory
= newdir
;
1587 tempdir
= Fdirectory_file_name (Vexec_directory
);
1588 if (! file_accessible_directory_p (SSDATA (tempdir
)))
1589 dir_warning ("arch-dependent data dir", Vexec_directory
);
1592 tempdir
= Fdirectory_file_name (Vdata_directory
);
1593 if (! file_accessible_directory_p (SSDATA (tempdir
)))
1594 dir_warning ("arch-independent data dir", Vdata_directory
);
1596 sh
= (char *) getenv ("SHELL");
1597 Vshell_file_name
= build_string (sh
? sh
: "/bin/sh");
1600 Vshared_game_score_directory
= Qnil
;
1602 Vshared_game_score_directory
= build_string (PATH_GAME
);
1603 if (NILP (Ffile_accessible_directory_p (Vshared_game_score_directory
)))
1604 Vshared_game_score_directory
= Qnil
;
1609 set_initial_environment (void)
1612 for (envp
= environ
; *envp
; envp
++)
1613 Vprocess_environment
= Fcons (build_string (*envp
),
1614 Vprocess_environment
);
1615 /* Ideally, the `copy' shouldn't be necessary, but it seems it's frequent
1616 to use `delete' and friends on process-environment. */
1617 Vinitial_environment
= Fcopy_sequence (Vprocess_environment
);
1621 syms_of_callproc (void)
1624 Vtemp_file_name_pattern
= build_string ("emacsXXXXXX");
1625 #elif defined (WINDOWSNT)
1626 Vtemp_file_name_pattern
= build_string ("emXXXXXX");
1628 Vtemp_file_name_pattern
= build_string ("detmp.XXX");
1630 staticpro (&Vtemp_file_name_pattern
);
1632 DEFVAR_LISP ("shell-file-name", Vshell_file_name
,
1633 doc
: /* File name to load inferior shells from.
1634 Initialized from the SHELL environment variable, or to a system-dependent
1635 default if SHELL is not set. */);
1637 DEFVAR_LISP ("exec-path", Vexec_path
,
1638 doc
: /* List of directories to search programs to run in subprocesses.
1639 Each element is a string (directory name) or nil (try default directory). */);
1641 DEFVAR_LISP ("exec-suffixes", Vexec_suffixes
,
1642 doc
: /* List of suffixes to try to find executable file names.
1643 Each element is a string. */);
1644 Vexec_suffixes
= Qnil
;
1646 DEFVAR_LISP ("exec-directory", Vexec_directory
,
1647 doc
: /* Directory for executables for Emacs to invoke.
1648 More generally, this includes any architecture-dependent files
1649 that are built and installed from the Emacs distribution. */);
1651 DEFVAR_LISP ("data-directory", Vdata_directory
,
1652 doc
: /* Directory of machine-independent files that come with GNU Emacs.
1653 These are files intended for Emacs to use while it runs. */);
1655 DEFVAR_LISP ("doc-directory", Vdoc_directory
,
1656 doc
: /* Directory containing the DOC file that comes with GNU Emacs.
1657 This is usually the same as `data-directory'. */);
1659 DEFVAR_LISP ("configure-info-directory", Vconfigure_info_directory
,
1660 doc
: /* For internal use by the build procedure only.
1661 This is the name of the directory in which the build procedure installed
1662 Emacs's info files; the default value for `Info-default-directory-list'
1664 Vconfigure_info_directory
= build_string (PATH_INFO
);
1666 DEFVAR_LISP ("shared-game-score-directory", Vshared_game_score_directory
,
1667 doc
: /* Directory of score files for games which come with GNU Emacs.
1668 If this variable is nil, then Emacs is unable to use a shared directory. */);
1670 Vshared_game_score_directory
= Qnil
;
1672 Vshared_game_score_directory
= build_string (PATH_GAME
);
1675 DEFVAR_LISP ("initial-environment", Vinitial_environment
,
1676 doc
: /* List of environment variables inherited from the parent process.
1677 Each element should be a string of the form ENVVARNAME=VALUE.
1678 The elements must normally be decoded (using `locale-coding-system') for use. */);
1679 Vinitial_environment
= Qnil
;
1681 DEFVAR_LISP ("process-environment", Vprocess_environment
,
1682 doc
: /* List of overridden environment variables for subprocesses to inherit.
1683 Each element should be a string of the form ENVVARNAME=VALUE.
1685 Entries in this list take precedence to those in the frame-local
1686 environments. Therefore, let-binding `process-environment' is an easy
1687 way to temporarily change the value of an environment variable,
1688 irrespective of where it comes from. To use `process-environment' to
1689 remove an environment variable, include only its name in the list,
1692 This variable is set to nil when Emacs starts.
1694 If multiple entries define the same variable, the first one always
1697 Non-ASCII characters are encoded according to the initial value of
1698 `locale-coding-system', i.e. the elements must normally be decoded for
1701 See `setenv' and `getenv'. */);
1702 Vprocess_environment
= Qnil
;
1704 defsubr (&Scall_process
);
1705 defsubr (&Sgetenv_internal
);
1706 defsubr (&Scall_process_region
);