1 /* Synchronous subprocess invocation for GNU Emacs.
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
28 extern char *strerror ();
30 /* Define SIGCHLD as an alias for SIGCLD. */
32 #if !defined (SIGCHLD) && defined (SIGCLD)
33 #define SIGCHLD SIGCLD
36 #include <sys/types.h>
40 #define INCLUDED_FCNTL
47 #include <stdlib.h> /* for proper declaration of environ */
50 #define _P_NOWAIT 1 /* from process.h */
53 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
55 #define INCLUDED_FCNTL
58 #include <sys/param.h>
75 #include "syssignal.h"
79 extern noshare
char **environ
;
81 extern char **environ
;
84 #define max(a, b) ((a) > (b) ? (a) : (b))
87 /* When we are starting external processes we need to know whether they
88 take binary input (no conversion) or text input (\n is converted to
89 \r\n). Similar for output: if newlines are written as \r\n then it's
90 text process output, otherwise it's binary. */
91 Lisp_Object Vbinary_process_input
;
92 Lisp_Object Vbinary_process_output
;
95 Lisp_Object Vexec_path
, Vexec_directory
, Vdata_directory
, Vdoc_directory
;
96 Lisp_Object Vconfigure_info_directory
;
98 Lisp_Object Vshell_file_name
;
100 Lisp_Object Vprocess_environment
;
103 Lisp_Object Qbuffer_file_type
;
106 /* True iff we are about to fork off a synchronous process or if we
107 are waiting for it. */
108 int synch_process_alive
;
110 /* Nonzero => this is a string explaining death of synchronous subprocess. */
111 char *synch_process_death
;
113 /* If synch_process_death is zero,
114 this is exit code of synchronous subprocess. */
115 int synch_process_retcode
;
117 extern Lisp_Object Vdoc_file_name
;
119 /* Clean up when exiting Fcall_process.
120 On MSDOS, delete the temporary file on any kind of termination.
121 On Unix, kill the process and any children on termination by signal. */
123 /* Nonzero if this is termination due to exit. */
124 static int call_process_exited
;
126 #ifndef VMS /* VMS version is in vmsproc.c. */
129 call_process_kill (fdpid
)
132 close (XFASTINT (Fcar (fdpid
)));
133 EMACS_KILLPG (XFASTINT (Fcdr (fdpid
)), SIGKILL
);
134 synch_process_alive
= 0;
139 call_process_cleanup (fdpid
)
143 /* for MSDOS fdpid is really (fd . tempfile) */
144 register Lisp_Object file
;
146 close (XFASTINT (Fcar (fdpid
)));
147 if (strcmp (XSTRING (file
)-> data
, NULL_DEVICE
) != 0)
148 unlink (XSTRING (file
)->data
);
149 #else /* not MSDOS */
150 register int pid
= XFASTINT (Fcdr (fdpid
));
153 if (call_process_exited
)
155 close (XFASTINT (Fcar (fdpid
)));
159 if (EMACS_KILLPG (pid
, SIGINT
) == 0)
161 int count
= specpdl_ptr
- specpdl
;
162 record_unwind_protect (call_process_kill
, fdpid
);
163 message1 ("Waiting for process to die...(type C-g again to kill it instantly)");
166 wait_for_termination (pid
);
168 specpdl_ptr
= specpdl
+ count
; /* Discard the unwind protect. */
169 message1 ("Waiting for process to die...done");
171 synch_process_alive
= 0;
172 close (XFASTINT (Fcar (fdpid
)));
173 #endif /* not MSDOS */
177 DEFUN ("call-process", Fcall_process
, Scall_process
, 1, MANY
, 0,
178 "Call PROGRAM synchronously in separate process.\n\
179 The program's input comes from file INFILE (nil means `/dev/null').\n\
180 Insert output in BUFFER before point; t means current buffer;\n\
181 nil for BUFFER means discard it; 0 means discard and don't wait.\n\
182 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,\n\
183 REAL-BUFFER says what to do with standard output, as above,\n\
184 while STDERR-FILE says what to do with standard error in the child.\n\
185 STDERR-FILE may be nil (discard standard error output),\n\
186 t (mix it with ordinary output), or a file name string.\n\
188 Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted.\n\
189 Remaining arguments are strings passed as command arguments to PROGRAM.\n\
191 If BUFFER is 0, `call-process' returns immediately with value nil.\n\
192 Otherwise it waits for PROGRAM to terminate\n\
193 and returns a numeric exit status or a signal description string.\n\
194 If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
197 register Lisp_Object
*args
;
199 Lisp_Object infile
, buffer
, current_dir
, display
, path
;
206 int count
= specpdl_ptr
- specpdl
;
207 register unsigned char **new_argv
208 = (unsigned char **) alloca ((max (2, nargs
- 2)) * sizeof (char *));
209 struct buffer
*old
= current_buffer
;
210 /* File to use for stderr in the child.
211 t means use same as standard output. */
212 Lisp_Object error_file
;
213 #ifdef MSDOS /* Demacs 1.1.1 91/10/16 HIRANO Satoshi */
214 char *outf
, *tempfile
;
220 CHECK_STRING (args
[0], 0);
225 /* Without asynchronous processes we cannot have BUFFER == 0. */
226 if (nargs
>= 3 && INTEGERP (args
[2]))
227 error ("Operating system cannot handle asynchronous subprocesses");
228 #endif /* subprocesses */
230 if (nargs
>= 2 && ! NILP (args
[1]))
232 infile
= Fexpand_file_name (args
[1], current_buffer
->directory
);
233 CHECK_STRING (infile
, 1);
236 infile
= build_string (NULL_DEVICE
);
242 /* If BUFFER is a list, its meaning is
243 (BUFFER-FOR-STDOUT FILE-FOR-STDERR). */
246 if (CONSP (XCONS (buffer
)->cdr
))
247 error_file
= Fexpand_file_name (XCONS (XCONS (buffer
)->cdr
)->car
,
249 buffer
= XCONS (buffer
)->car
;
252 if (!(EQ (buffer
, Qnil
)
254 || XFASTINT (buffer
) == 0))
256 Lisp_Object spec_buffer
;
257 spec_buffer
= buffer
;
258 buffer
= Fget_buffer (buffer
);
259 /* Mention the buffer name for a better error message. */
261 CHECK_BUFFER (spec_buffer
, 2);
262 CHECK_BUFFER (buffer
, 2);
268 /* Make sure that the child will be able to chdir to the current
269 buffer's current directory, or its unhandled equivalent. We
270 can't just have the child check for an error when it does the
271 chdir, since it's in a vfork.
273 We have to GCPRO around this because Fexpand_file_name,
274 Funhandled_file_name_directory, and Ffile_accessible_directory_p
275 might call a file name handling function. The argument list is
276 protected by the caller, so all we really have to worry about is
279 struct gcpro gcpro1
, gcpro2
, gcpro3
;
281 current_dir
= current_buffer
->directory
;
283 GCPRO3 (infile
, buffer
, current_dir
);
286 = expand_and_dir_to_file (Funhandled_file_name_directory (current_dir
),
288 if (NILP (Ffile_accessible_directory_p (current_dir
)))
289 report_file_error ("Setting current directory",
290 Fcons (current_buffer
->directory
, Qnil
));
295 display
= nargs
>= 4 ? args
[3] : Qnil
;
297 filefd
= open (XSTRING (infile
)->data
, O_RDONLY
, 0);
300 report_file_error ("Opening process input file", Fcons (infile
, Qnil
));
302 /* Search for program; barf if not found. */
306 GCPRO1 (current_dir
);
307 openp (Vexec_path
, args
[0], EXEC_SUFFIXES
, &path
, 1);
313 report_file_error ("Searching for program", Fcons (args
[0], Qnil
));
315 new_argv
[0] = XSTRING (path
)->data
;
318 for (i
= 4; i
< nargs
; i
++)
320 CHECK_STRING (args
[i
], i
);
321 new_argv
[i
- 3] = XSTRING (args
[i
])->data
;
326 #ifdef MSDOS /* MW, July 1993 */
327 /* These vars record information from process termination.
328 Clear them now before process can possibly terminate,
329 to avoid timing error if process terminates soon. */
330 synch_process_death
= 0;
331 synch_process_retcode
= 0;
333 if ((outf
= egetenv ("TMP")) || (outf
= egetenv ("TEMP")))
334 strcpy (tempfile
= alloca (strlen (outf
) + 20), outf
);
337 tempfile
= alloca (20);
340 dostounix_filename (tempfile
);
341 if (*tempfile
== '\0' || tempfile
[strlen (tempfile
) - 1] != '/')
342 strcat (tempfile
, "/");
343 strcat (tempfile
, "detmp.XXX");
346 outfilefd
= creat (tempfile
, S_IREAD
| S_IWRITE
);
350 report_file_error ("Opening process output file", Fcons (tempfile
, Qnil
));
354 if (INTEGERP (buffer
))
355 fd
[1] = open (NULL_DEVICE
, O_WRONLY
), fd
[0] = -1;
360 pipe_with_inherited_out (fd
);
361 #else /* not WINDOWSNT */
363 #endif /* not WINDOWSNT */
366 /* Replaced by close_process_descs */
367 set_exclusive_use (fd
[0]);
372 /* child_setup must clobber environ in systems with true vfork.
373 Protect it from permanent change. */
374 register char **save_environ
= environ
;
375 register int fd1
= fd
[1];
378 #if 0 /* Some systems don't have sigblock. */
379 mask
= sigblock (sigmask (SIGCHLD
));
382 /* Record that we're about to create a synchronous process. */
383 synch_process_alive
= 1;
385 /* These vars record information from process termination.
386 Clear them now before process can possibly terminate,
387 to avoid timing error if process terminates soon. */
388 synch_process_death
= 0;
389 synch_process_retcode
= 0;
391 #ifdef MSDOS /* MW, July 1993 */
392 /* ??? Someone who knows MSDOG needs to check whether this properly
393 closes all descriptors that it opens. */
394 pid
= run_msdos_command (new_argv
, current_dir
, filefd
, outfilefd
);
396 fd1
= -1; /* No harm in closing that one! */
397 fd
[0] = open (tempfile
, NILP (Vbinary_process_output
) ? O_TEXT
: O_BINARY
);
402 report_file_error ("Cannot re-open temporary file", Qnil
);
404 #else /* not MSDOS */
406 if (NILP (error_file
))
407 fd_error
= open (NULL_DEVICE
, O_WRONLY
);
408 else if (STRINGP (error_file
))
411 fd_error
= open (XSTRING (error_file
)->data
,
412 O_WRONLY
| O_TRUNC
| O_CREAT
| O_TEXT
,
414 #else /* not DOS_NT */
415 fd_error
= creat (XSTRING (error_file
)->data
, 0666);
416 #endif /* not DOS_NT */
425 report_file_error ("Cannot open", error_file
);
429 pid
= child_setup (filefd
, fd1
, fd_error
, new_argv
, 0, current_dir
);
430 #else /* not WINDOWSNT */
442 child_setup (filefd
, fd1
, fd_error
, new_argv
, 0, current_dir
);
444 #endif /* not MSDOS */
445 #endif /* not WINDOWSNT */
447 environ
= save_environ
;
449 /* Close most of our fd's, but not fd[0]
450 since we will use that to read input from. */
460 report_file_error ("Doing vfork", Qnil
);
463 if (INTEGERP (buffer
))
468 /* If Emacs has been built with asynchronous subprocess support,
469 we don't need to do this, I think because it will then have
470 the facilities for handling SIGCHLD. */
471 wait_without_blocking ();
472 #endif /* subprocesses */
476 /* Enable sending signal if user quits below. */
477 call_process_exited
= 0;
480 /* MSDOS needs different cleanup information. */
481 record_unwind_protect (call_process_cleanup
,
482 Fcons (make_number (fd
[0]), build_string (tempfile
)));
484 record_unwind_protect (call_process_cleanup
,
485 Fcons (make_number (fd
[0]), make_number (pid
)));
486 #endif /* not MSDOS */
489 if (BUFFERP (buffer
))
490 Fset_buffer (buffer
);
502 /* Repeatedly read until we've filled as much as possible
503 of the buffer size we have. But don't read
504 less than 1024--save that for the next bufferfull. */
507 while (nread
< bufsize
- 1024)
510 = read (fd
[0], bufptr
+ nread
, bufsize
- nread
);
523 /* Now NREAD is the total amount of data in the buffer. */
531 insert (bufptr
, nread
);
533 /* Make the buffer bigger as we continue to read more data,
535 if (bufsize
< 64 * 1024 && total_read
> 32 * bufsize
)
538 bufptr
= (char *) alloca (bufsize
);
541 if (!NILP (display
) && INTERACTIVE
)
544 prepare_menu_bars ();
546 redisplay_preserve_echo_area ();
554 /* Wait for it to terminate, unless it already has. */
555 wait_for_termination (pid
);
559 set_buffer_internal (old
);
561 /* Don't kill any children that the subprocess may have left behind
563 call_process_exited
= 1;
565 unbind_to (count
, Qnil
);
567 if (synch_process_death
)
568 return build_string (synch_process_death
);
569 return make_number (synch_process_retcode
);
574 delete_temp_file (name
)
577 /* Use Fdelete_file (indirectly) because that runs a file name handler.
578 We did that when writing the file, so we should do so when deleting. */
579 internal_delete_file (name
);
582 DEFUN ("call-process-region", Fcall_process_region
, Scall_process_region
,
584 "Send text from START to END to a synchronous process running PROGRAM.\n\
585 Delete the text if fourth arg DELETE is non-nil.\n\
587 Insert output in BUFFER before point; t means current buffer;\n\
588 nil for BUFFER means discard it; 0 means discard and don't wait.\n\
589 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,\n\
590 REAL-BUFFER says what to do with standard output, as above,\n\
591 while STDERR-FILE says what to do with standard error in the child.\n\
592 STDERR-FILE may be nil (discard standard error output),\n\
593 t (mix it with ordinary output), or a file name string.\n\
595 Sixth arg DISPLAY non-nil means redisplay buffer as output is inserted.\n\
596 Remaining args are passed to PROGRAM at startup as command args.\n\
598 If BUFFER is nil, `call-process-region' returns immediately with value nil.\n\
599 Otherwise it waits for PROGRAM to terminate\n\
600 and returns a numeric exit status or a signal description string.\n\
601 If you quit, the process is killed with SIGINT, or SIGKILL if you quit again.")
604 register Lisp_Object
*args
;
607 Lisp_Object filename_string
;
608 register Lisp_Object start
, end
;
614 int count
= specpdl_ptr
- specpdl
;
618 if ((outf
= egetenv ("TMP")) || (outf
= egetenv ("TEMP")))
619 strcpy (tempfile
= alloca (strlen (outf
) + 20), outf
);
622 tempfile
= alloca (20);
625 dostounix_filename (tempfile
);
626 if (!IS_DIRECTORY_SEP (tempfile
[strlen (tempfile
) - 1]))
627 strcat (tempfile
, "/");
629 strcat (tempfile
, "emXXXXXX");
631 strcat (tempfile
, "detmp.XXX");
633 #else /* not DOS_NT */
636 strcpy (tempfile
, "tmp:emacsXXXXXX.");
638 strcpy (tempfile
, "/tmp/emacsXXXXXX");
640 #endif /* not DOS_NT */
644 filename_string
= build_string (tempfile
);
645 GCPRO1 (filename_string
);
649 specbind (Qbuffer_file_type
, Vbinary_process_input
);
650 Fwrite_region (start
, end
, filename_string
, Qnil
, Qlambda
);
651 unbind_to (count
, Qnil
);
652 #else /* not DOS_NT */
653 Fwrite_region (start
, end
, filename_string
, Qnil
, Qlambda
);
654 #endif /* not DOS_NT */
656 record_unwind_protect (delete_temp_file
, filename_string
);
659 Fdelete_region (start
, end
);
661 args
[3] = filename_string
;
663 RETURN_UNGCPRO (unbind_to (count
, Fcall_process (nargs
- 2, args
+ 2)));
666 #ifndef VMS /* VMS version is in vmsproc.c. */
668 /* This is the last thing run in a newly forked inferior
669 either synchronous or asynchronous.
670 Copy descriptors IN, OUT and ERR as descriptors 0, 1 and 2.
671 Initialize inferior's priority, pgrp, connected dir and environment.
672 then exec another program based on new_argv.
674 This function may change environ for the superior process.
675 Therefore, the superior process must save and restore the value
676 of environ around the vfork and the call to this function.
678 ENV is the environment for the subprocess.
680 SET_PGRP is nonzero if we should put the subprocess into a separate
683 CURRENT_DIR is an elisp string giving the path of the current
684 directory the subprocess should have. Since we can't really signal
685 a decent error from within the child, this should be verified as an
686 executable directory by the parent. */
688 child_setup (in
, out
, err
, new_argv
, set_pgrp
, current_dir
)
690 register char **new_argv
;
692 Lisp_Object current_dir
;
695 /* The MSDOS port of gcc cannot fork, vfork, ... so we must call system
697 #else /* not MSDOS */
703 #endif /* WINDOWSNT */
707 #ifdef SET_EMACS_PRIORITY
709 extern int emacs_priority
;
711 if (emacs_priority
< 0)
712 nice (- emacs_priority
);
717 /* Close Emacs's descriptors that this process should not have. */
718 close_process_descs ();
722 /* Note that use of alloca is always safe here. It's obvious for systems
723 that do not have true vfork or that have true (stack) alloca.
724 If using vfork and C_ALLOCA it is safe because that changes
725 the superior's static variables as if the superior had done alloca
726 and will be cleaned up in the usual way. */
731 i
= XSTRING (current_dir
)->size
;
732 pwd_var
= (char *) alloca (i
+ 6);
734 bcopy ("PWD=", pwd_var
, 4);
735 bcopy (XSTRING (current_dir
)->data
, temp
, i
);
736 if (!IS_DIRECTORY_SEP (temp
[i
- 1])) temp
[i
++] = DIRECTORY_SEP
;
739 /* We can't signal an Elisp error here; we're in a vfork. Since
740 the callers check the current directory before forking, this
741 should only return an error if the directory's permissions
742 are changed between the check and this chdir, but we should
744 if (chdir (temp
) < 0)
747 /* Strip trailing slashes for PWD, but leave "/" and "//" alone. */
748 while (i
> 2 && IS_DIRECTORY_SEP (temp
[i
- 1]))
752 /* Set `env' to a vector of the strings in Vprocess_environment. */
754 register Lisp_Object tem
;
755 register char **new_env
;
756 register int new_length
;
759 for (tem
= Vprocess_environment
;
760 CONSP (tem
) && STRINGP (XCONS (tem
)->car
);
761 tem
= XCONS (tem
)->cdr
)
764 /* new_length + 2 to include PWD and terminating 0. */
765 env
= new_env
= (char **) alloca ((new_length
+ 2) * sizeof (char *));
767 /* If we have a PWD envvar, pass one down,
768 but with corrected value. */
770 *new_env
++ = pwd_var
;
772 /* Copy the Vprocess_environment strings into new_env. */
773 for (tem
= Vprocess_environment
;
774 CONSP (tem
) && STRINGP (XCONS (tem
)->car
);
775 tem
= XCONS (tem
)->cdr
)
778 char *string
= (char *) XSTRING (XCONS (tem
)->car
)->data
;
779 /* See if this string duplicates any string already in the env.
780 If so, don't put it in.
781 When an env var has multiple definitions,
782 we keep the definition that comes first in process-environment. */
783 for (; ep
!= new_env
; ep
++)
785 char *p
= *ep
, *q
= string
;
789 /* The string is malformed; might as well drop it. */
804 prepare_standard_handles (in
, out
, err
, handles
);
805 #else /* not WINDOWSNT */
806 /* Make sure that in, out, and err are not actually already in
807 descriptors zero, one, or two; this could happen if Emacs is
808 started with its standard in, out, or error closed, as might
811 int oin
= in
, oout
= out
;
813 /* We have to avoid relocating the same descriptor twice! */
815 in
= relocate_fd (in
, 3);
820 out
= relocate_fd (out
, 3);
824 else if (err
== oout
)
827 err
= relocate_fd (err
, 3);
840 #endif /* not WINDOWSNT */
843 #ifndef SETPGRP_RELEASES_CTTY
844 setpgrp (); /* No arguments but equivalent in this case */
849 /* setpgrp_of_tty is incorrect here; it uses input_fd. */
850 EMACS_SET_TTY_PGRP (0, &pid
);
853 something missing here
;
857 /* Spawn the child. (See ntproc.c:Spawnve). */
858 cpid
= spawnve (_P_NOWAIT
, new_argv
[0], new_argv
, env
);
860 /* An error occurred while trying to spawn the process. */
861 report_file_error ("Spawning child process", Qnil
);
862 reset_standard_handles (in
, out
, err
, handles
);
864 #else /* not WINDOWSNT */
865 /* execvp does not accept an environment arg so the only way
866 to pass this environment is to set environ. Our caller
867 is responsible for restoring the ambient value of environ. */
869 execvp (new_argv
[0], new_argv
);
871 write (1, "Can't exec program: ", 26);
872 write (1, new_argv
[0], strlen (new_argv
[0]));
875 #endif /* not WINDOWSNT */
876 #endif /* not MSDOS */
879 /* Move the file descriptor FD so that its number is not less than MIN.
880 If the file descriptor is moved at all, the original is freed. */
882 relocate_fd (fd
, min
)
892 char *message1
= "Error while setting up child: ";
893 char *errmessage
= strerror (errno
);
894 char *message2
= "\n";
895 write (2, message1
, strlen (message1
));
896 write (2, errmessage
, strlen (errmessage
));
897 write (2, message2
, strlen (message2
));
900 /* Note that we hold the original FD open while we recurse,
901 to guarantee we'll get a new FD if we need it. */
902 new = relocate_fd (new, min
);
909 getenv_internal (var
, varlen
, value
, valuelen
)
917 for (scan
= Vprocess_environment
; CONSP (scan
); scan
= XCONS (scan
)->cdr
)
921 entry
= XCONS (scan
)->car
;
923 && XSTRING (entry
)->size
> varlen
924 && XSTRING (entry
)->data
[varlen
] == '='
926 /* NT environment variables are case insensitive. */
927 && ! strnicmp (XSTRING (entry
)->data
, var
, varlen
)
928 #else /* not WINDOWSNT */
929 && ! bcmp (XSTRING (entry
)->data
, var
, varlen
)
930 #endif /* not WINDOWSNT */
933 *value
= (char *) XSTRING (entry
)->data
+ (varlen
+ 1);
934 *valuelen
= XSTRING (entry
)->size
- (varlen
+ 1);
942 DEFUN ("getenv", Fgetenv
, Sgetenv
, 1, 1, 0,
943 "Return the value of environment variable VAR, as a string.\n\
944 VAR should be a string. Value is nil if VAR is undefined in the environment.\n\
945 This function consults the variable ``process-environment'' for its value.")
952 CHECK_STRING (var
, 0);
953 if (getenv_internal (XSTRING (var
)->data
, XSTRING (var
)->size
,
955 return make_string (value
, valuelen
);
960 /* A version of getenv that consults process_environment, easily
969 if (getenv_internal (var
, strlen (var
), &value
, &valuelen
))
977 /* This is run before init_cmdargs. */
981 char *data_dir
= egetenv ("EMACSDATA");
982 char *doc_dir
= egetenv ("EMACSDOC");
985 = Ffile_name_as_directory (build_string (data_dir
? data_dir
988 = Ffile_name_as_directory (build_string (doc_dir
? doc_dir
991 /* Check the EMACSPATH environment variable, defaulting to the
992 PATH_EXEC path from paths.h. */
993 Vexec_path
= decode_env_path ("EMACSPATH", PATH_EXEC
);
994 Vexec_directory
= Ffile_name_as_directory (Fcar (Vexec_path
));
995 Vexec_path
= nconc2 (decode_env_path ("PATH", ""), Vexec_path
);
998 /* This is run after init_cmdargs, when Vinstallation_directory is valid. */
1002 char *data_dir
= egetenv ("EMACSDATA");
1005 Lisp_Object tempdir
;
1007 if (initialized
&& !NILP (Vinstallation_directory
))
1009 /* Add to the path the lib-src subdir of the installation dir. */
1011 tem
= Fexpand_file_name (build_string ("lib-src"),
1012 Vinstallation_directory
);
1013 if (NILP (Fmember (tem
, Vexec_path
)))
1016 /* MSDOS uses wrapped binaries, so don't do this. */
1017 Vexec_path
= nconc2 (Vexec_path
, Fcons (tem
, Qnil
));
1018 Vexec_directory
= Ffile_name_as_directory (tem
);
1019 #endif /* not DOS_NT */
1022 /* Maybe use ../etc as well as ../lib-src. */
1025 tem
= Fexpand_file_name (build_string ("etc"),
1026 Vinstallation_directory
);
1027 Vdoc_directory
= Ffile_name_as_directory (tem
);
1031 /* Look for the files that should be in etc. We don't use
1032 Vinstallation_directory, because these files are never installed
1033 near the executable, and they are never in the build
1034 directory when that's different from the source directory.
1036 Instead, if these files are not in the nominal place, we try the
1037 source directory. */
1040 Lisp_Object tem
, tem1
, newdir
;
1042 tem
= Fexpand_file_name (build_string ("GNU"), Vdata_directory
);
1043 tem1
= Ffile_exists_p (tem
);
1046 newdir
= Fexpand_file_name (build_string ("../etc/"),
1047 build_string (PATH_DUMPLOADSEARCH
));
1048 tem
= Fexpand_file_name (build_string ("GNU"), newdir
);
1049 tem1
= Ffile_exists_p (tem
);
1051 Vdata_directory
= newdir
;
1055 tempdir
= Fdirectory_file_name (Vexec_directory
);
1056 if (access (XSTRING (tempdir
)->data
, 0) < 0)
1059 "Warning: arch-dependent data dir (%s) does not exist.\n",
1060 XSTRING (Vexec_directory
)->data
);
1064 tempdir
= Fdirectory_file_name (Vdata_directory
);
1065 if (access (XSTRING (tempdir
)->data
, 0) < 0)
1068 "Warning: arch-independent data dir (%s) does not exist.\n",
1069 XSTRING (Vdata_directory
)->data
);
1074 Vshell_file_name
= build_string ("*dcl*");
1076 sh
= (char *) getenv ("SHELL");
1077 Vshell_file_name
= build_string (sh
? sh
: "/bin/sh");
1081 set_process_environment ()
1083 register char **envp
;
1085 Vprocess_environment
= Qnil
;
1089 for (envp
= environ
; *envp
; envp
++)
1090 Vprocess_environment
= Fcons (build_string (*envp
),
1091 Vprocess_environment
);
1097 Qbuffer_file_type
= intern ("buffer-file-type");
1098 staticpro (&Qbuffer_file_type
);
1100 DEFVAR_LISP ("binary-process-input", &Vbinary_process_input
,
1101 "*If non-nil then new subprocesses are assumed to take binary input.");
1102 Vbinary_process_input
= Qnil
;
1104 DEFVAR_LISP ("binary-process-output", &Vbinary_process_output
,
1105 "*If non-nil then new subprocesses are assumed to produce binary output.");
1106 Vbinary_process_output
= Qnil
;
1109 DEFVAR_LISP ("shell-file-name", &Vshell_file_name
,
1110 "*File name to load inferior shells from.\n\
1111 Initialized from the SHELL environment variable.");
1113 DEFVAR_LISP ("exec-path", &Vexec_path
,
1114 "*List of directories to search programs to run in subprocesses.\n\
1115 Each element is a string (directory name) or nil (try default directory).");
1117 DEFVAR_LISP ("exec-directory", &Vexec_directory
,
1118 "Directory of architecture-dependent files that come with GNU Emacs,\n\
1119 especially executable programs intended for Emacs to invoke.");
1121 DEFVAR_LISP ("data-directory", &Vdata_directory
,
1122 "Directory of architecture-independent files that come with GNU Emacs,\n\
1123 intended for Emacs to use.");
1125 DEFVAR_LISP ("doc-directory", &Vdoc_directory
,
1126 "Directory containing the DOC file that comes with GNU Emacs.\n\
1127 This is usually the same as data-directory.");
1129 DEFVAR_LISP ("configure-info-directory", &Vconfigure_info_directory
,
1130 "For internal use by the build procedure only.\n\
1131 This is the name of the directory in which the build procedure installed\n\
1132 Emacs's info files; the default value for Info-default-directory-list\n\
1134 Vconfigure_info_directory
= build_string (PATH_INFO
);
1136 DEFVAR_LISP ("process-environment", &Vprocess_environment
,
1137 "List of environment variables for subprocesses to inherit.\n\
1138 Each element should be a string of the form ENVVARNAME=VALUE.\n\
1139 The environment which Emacs inherits is placed in this variable\n\
1140 when Emacs starts.");
1143 defsubr (&Scall_process
);
1146 defsubr (&Scall_process_region
);