annotate src/callproc.c @ 54:05472e90ae02 r19-16-pre2

Import from CVS: tag r19-16-pre2
author cvs
date Mon, 13 Aug 2007 08:57:55 +0200
parents 56c54cf7c5b6
children 131b0175ea99
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Synchronous subprocess invocation for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 /* Synched up with: Mule 2.0, FSF 19.30. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #include "commands.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 #include "insdel.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #include "lstream.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 #include "paths.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #include "process.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 #include "sysdep.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 #include "window.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 #include "sysfile.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 #include "systime.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 #include "sysproc.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 #include "syssignal.h" /* Always include before systty.h */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #include "systty.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #ifdef DOS_NT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 /* When we are starting external processes we need to know whether they
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 take binary input (no conversion) or text input (\n is converted to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 \r\n). Similar for output: if newlines are written as \r\n then it's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 text process output, otherwise it's binary. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 Lisp_Object Vbinary_process_input;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 Lisp_Object Vbinary_process_output;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 #endif /* DOS_NT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 Lisp_Object Vexec_path, Vexec_directory, Vdata_directory, Vdoc_directory;
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
52 Lisp_Object Vconfigure_info_directory, Vsite_directory;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 /* The default base directory XEmacs is installed under. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 Lisp_Object Vprefix_directory;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 Lisp_Object Vshell_file_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 /* The environment to pass to all subprocesses when they are started.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 This is in the semi-bogus format of ("VAR=VAL" "VAR2=VAL2" ... )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 Lisp_Object Vprocess_environment;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 /* True iff we are about to fork off a synchronous process or if we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 are waiting for it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 volatile int synch_process_alive;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 /* Nonzero => this is a string explaining death of synchronous subprocess. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 CONST char *synch_process_death;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 /* If synch_process_death is zero,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 this is exit code of synchronous subprocess. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 int synch_process_retcode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 /* Clean up when exiting Fcall_process_internal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 On MSDOS, delete the temporary file on any kind of termination.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 On Unix, kill the process and any children on termination by signal. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 /* Nonzero if this is termination due to exit. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 static int call_process_exited;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 #ifndef VMS /* VMS version is in vmsproc.c. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 call_process_kill (Lisp_Object fdpid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 Lisp_Object fd = Fcar (fdpid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 Lisp_Object pid = Fcdr (fdpid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 if (!NILP (fd))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 close (XINT (fd));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 if (!NILP (pid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 EMACS_KILLPG (XINT (pid), SIGKILL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 synch_process_alive = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 call_process_cleanup (Lisp_Object fdpid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 /* for MSDOS fdpid is really (fd . tempfile) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 Lisp_Object file = Fcdr (fdpid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 close (XINT (Fcar (fdpid)));
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
107 if (strcmp (XSTRING_DATA (file), NULL_DEVICE) != 0)
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
108 unlink (XSTRING_DATA (file));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 #else /* not MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 int fd = XINT (Fcar (fdpid));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 int pid = XINT (Fcdr (fdpid));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 if (!call_process_exited &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 EMACS_KILLPG (pid, SIGINT) == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 record_unwind_protect (call_process_kill, fdpid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 /* #### "c-G" -- need non-consing Single-key-description */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 message ("Waiting for process to die...(type C-g again to kill it instantly)");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 /* "Discard" the unwind protect. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 XCAR (fdpid) = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 XCDR (fdpid) = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 unbind_to (speccount, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 message ("Waiting for process to die... done");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 synch_process_alive = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 close (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 #endif /* not MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 static Lisp_Object fork_error;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 #if 0 /* UNUSED */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 report_fork_error (char *string, Lisp_Object data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 Lisp_Object errstring = build_string (strerror (errno));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 /* System error messages are capitalized. Downcase the initial. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 set_string_char (XSTRING (errstring), 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 DOWNCASE (current_buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 string_char (XSTRING (errstring), 0)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 fork_error = Fcons (build_string (string), Fcons (errstring, data));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 /* terminate this branch of the fork, without closing stdin/out/etc. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 _exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 #endif /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
154 DEFUN ("call-process-internal", Fcall_process_internal, 1, MANY, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 Call PROGRAM synchronously in separate process, with coding-system specified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 Arguments are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 The program's input comes from file INFILE (nil means `/dev/null').
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 Insert output in BUFFER before point; t means current buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 nil for BUFFER means discard it; 0 means discard and don't wait.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 REAL-BUFFER says what to do with standard output, as above,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 while STDERR-FILE says what to do with standard error in the child.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 STDERR-FILE may be nil (discard standard error output),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 t (mix it with ordinary output), or a file name string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 Remaining arguments are strings passed as command arguments to PROGRAM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 If BUFFER is 0, `call-process' returns immediately with value nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 Otherwise it waits for PROGRAM to terminate and returns a numeric exit status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 or a signal description string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 If you quit, the process is killed with SIGINT, or SIGKILL if you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 quit again.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
175 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
176 (int nargs, Lisp_Object *args))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 Lisp_Object infile, buffer, current_dir, display, path;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 int fd[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 int filefd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 int pid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 char buf[16384];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 char *bufptr = buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 int bufsize = 16384;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 int speccount = specpdl_depth ();
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 32
diff changeset
187 struct gcpro gcpro1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 char **new_argv
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 = (char **) alloca ((max (2, nargs - 2)) * sizeof (char *));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 /* File to use for stderr in the child.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 t means use same as standard output. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 Lisp_Object error_file;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 char *outf, *tempfile;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 int outfilefd;
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
197 #endif /* MSDOS */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 CHECK_STRING (args[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 error_file = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 #if defined (NO_SUBPROCESSES)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 /* Without asynchronous processes we cannot have BUFFER == 0. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 if (nargs >= 3 && !INTP (args[2]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 error ("Operating system cannot handle asynchronous subprocesses");
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
207 #endif /* NO_SUBPROCESSES */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 /* Do this before building new_argv because GC in Lisp code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 * called by various filename-hacking routines might relocate strings */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 locate_file (Vexec_path, args[0], EXEC_SUFFIXES, &path, X_OK);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 /* Make sure that the child will be able to chdir to the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 buffer's current directory, or its unhandled equivalent. We
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 can't just have the child check for an error when it does the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 chdir, since it's in a vfork. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 struct gcpro gcpro1, gcpro2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 /* Do this test before building new_argv because GC in Lisp code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 * called by various filename-hacking routines might relocate strings */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 /* Make sure that the child will be able to chdir to the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 buffer's current directory. We can't just have the child check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 for an error when it does the chdir, since it's in a vfork. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 GCPRO2 (current_dir, path); /* Caller gcprotects args[] */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 current_dir = current_buffer->directory;
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 32
diff changeset
227 current_dir = Funhandled_file_name_directory (current_dir);
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 32
diff changeset
228 current_dir = expand_and_dir_to_file (current_dir, Qnil);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 /* I don't know how RMS intends this crock of shit to work, but it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 breaks everything in the presence of ange-ftp-visited files, so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 fuck it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 if (NILP (Ffile_accessible_directory_p (current_dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 report_file_error ("Setting current directory",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 Fcons (current_buffer->directory, Qnil));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 #endif /* 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 if (nargs >= 2 && ! NILP (args[1]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 {
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 32
diff changeset
242 struct gcpro gcpro1;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 32
diff changeset
243 GCPRO1 (current_buffer->directory);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
244 infile = Fexpand_file_name (args[1], current_buffer->directory);
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 32
diff changeset
245 UNGCPRO;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 CHECK_STRING (infile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 infile = build_string (NULL_DEVICE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 32
diff changeset
251 GCPRO1 (infile); /* Fexpand_file_name might trash it */
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 32
diff changeset
252
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 if (nargs >= 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 buffer = args[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 /* If BUFFER is a list, its meaning is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (BUFFER-FOR-STDOUT FILE-FOR-STDERR). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 if (CONSP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 if (CONSP (XCDR (buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 Lisp_Object file_for_stderr = XCAR (XCDR (buffer));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 if (NILP (file_for_stderr) || EQ (Qt, file_for_stderr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 error_file = file_for_stderr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 error_file = Fexpand_file_name (file_for_stderr, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 buffer = XCAR (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 if (!(EQ (buffer, Qnil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 || EQ (buffer, Qt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 || ZEROP (buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 Lisp_Object spec_buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 spec_buffer = buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 buffer = Fget_buffer (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 /* Mention the buffer name for a better error message. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 if (NILP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 CHECK_BUFFER (spec_buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 CHECK_BUFFER (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 buffer = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
44
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 32
diff changeset
290 UNGCPRO;
8d2a9b52c682 Import from CVS: tag r19-15prefinal
cvs
parents: 32
diff changeset
291
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 display = ((nargs >= 4) ? args[3] : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
294 /* From here we assume we won't GC (unless an error is signaled). */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 REGISTER int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 for (i = 4; i < nargs; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 CHECK_STRING (args[i]);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
300 new_argv[i - 3] = (char *) XSTRING_DATA (args[i]);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 }
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
302 new_argv[nargs - 3] = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
305 if (NILP (path))
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
306 report_file_error ("Searching for program", Fcons (args[0], Qnil));
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
307 new_argv[0] = (char *) XSTRING_DATA (path);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
308
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
309 filefd = open ((char *) XSTRING_DATA (infile), O_RDONLY, 0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 if (filefd < 0)
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
311 report_file_error ("Opening process input file", Fcons (infile, Qnil));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 /* These vars record information from process termination.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 Clear them now before process can possibly terminate,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 to avoid timing error if process terminates soon. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 synch_process_death = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 synch_process_retcode = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 if ((outf = egetenv ("TMP")) || (outf = egetenv ("TEMP")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 strcpy (tempfile = alloca (strlen (outf) + 20), outf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 tempfile = alloca (20);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 *tempfile = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 dostounix_filename (tempfile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 if (*tempfile == '\0' || tempfile[strlen (tempfile) - 1] != '/')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 strcat (tempfile, "/");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 strcat (tempfile, "detmp.XXX");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 mktemp (tempfile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 outfilefd = creat (tempfile, S_IREAD | S_IWRITE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 if (outfilefd < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 close (filefd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 report_file_error ("Opening process output file",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 Fcons (tempfile, Qnil));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 }
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
340 #endif /* MSDOS */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 #ifndef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 if (INTP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 fd[1] = open (NULL_DEVICE, O_WRONLY, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 fd[0] = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 pipe_with_inherited_out (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 #else /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 pipe (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 #endif /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 /* Replaced by close_process_descs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 set_exclusive_use (fd[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 #else /* MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 char *outf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 if (INTP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 outf = NULL_DEVICE;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 /* DOS can't create pipe for interprocess communication,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 so redirect child process's standard output to temporary file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 and later read the file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 if ((outf = egetenv ("TMP")) || (outf = egetenv ("TEMP")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 strcpy (tempfile, outf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 dostounix_filename (tempfile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 *tempfile = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 if (strlen (tempfile) == 0 || tempfile[strlen (tempfile) - 1] != '/')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 strcat (tempfile, "/");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 strcat (tempfile, "demacs.XXX");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 mktemp (tempfile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 outf = tempfile;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 if ((fd[1] = creat (outf, S_IREAD | S_IWRITE)) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 report_file_error ("Can't open temporary file", Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 fd[0] = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 #endif /* MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 /* child_setup must clobber environ in systems with true vfork.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 Protect it from permanent change. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 REGISTER char **save_environ = environ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 REGISTER int fd1 = fd[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 int fd_error = fd1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 char **env;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 #ifdef EMACS_BTL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 /* when performance monitoring is on, turn it off before the vfork(),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 as the child has no handler for the signal -- when back in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 parent process, turn it back on if it was really on when you "turned
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 it off" */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 int logging_on = cadillac_stop_logging ();
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
406 #endif /* EMACS_BTL */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 env = environ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 /* Record that we're about to create a synchronous process. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 synch_process_alive = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 /* These vars record information from process termination.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 Clear them now before process can possibly terminate,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 to avoid timing error if process terminates soon. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 synch_process_death = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 synch_process_retcode = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 /* ??? Someone who knows MSDOG needs to check whether this properly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 closes all descriptors that it opens. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 pid = run_msdos_command (new_argv, current_dir, filefd, outfilefd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 close (outfilefd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 fd1 = -1; /* No harm in closing that one! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 fd[0] = open (tempfile, NILP (Vbinary_process_output) ? O_TEXT :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 O_BINARY);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 if (fd[0] < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 unlink (tempfile);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 close (filefd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 report_file_error ("Cannot re-open temporary file", Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 #else /* not MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 if (NILP (error_file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 fd_error = open (NULL_DEVICE, O_WRONLY);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 else if (STRINGP (error_file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 #ifdef DOS_NT
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
439 fd_error = open (XSTRING_DATA (error_file),
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 S_IREAD | S_IWRITE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 #else /* not DOS_NT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 fd_error =
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
444 creat ((CONST char *) XSTRING_DATA (error_file), 0666);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 #endif /* not DOS_NT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 if (fd_error < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 close (filefd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 close (fd[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 if (fd1 >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 close (fd1);
48
56c54cf7c5b6 Import from CVS: tag r19-16b90
cvs
parents: 44
diff changeset
454 report_file_error ("Cannot open", Fcons(error_file, Qnil));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 fork_error = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 pid = child_setup (filefd, fd1, fd_error, new_argv, current_dir);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 #else /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 pid = vfork ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 if (pid == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 if (fd[0] >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 close (fd[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 /* This is necessary because some shells may attempt to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 access the current controlling terminal and will hang
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 if they are run in the background, as will be the case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 when XEmacs is started in the background. Martin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 Buchholz observed this problem running a subprocess
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 that used zsh to call gzip to uncompress an info
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 disconnect_controlling_terminal ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 child_setup (filefd, fd1, fd_error, new_argv,
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
476 (char *) XSTRING_DATA (current_dir));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 #ifdef EMACS_BTL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 else if (logging_on)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 cadillac_start_logging ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 #endif /* not MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 #endif /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 environ = save_environ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 /* Close most of our fd's, but not fd[0]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 since we will use that to read input from. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 close (filefd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 if (fd1 >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 close (fd1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 if (!NILP (fork_error))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 signal_error (Qfile_error, fork_error);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 if (pid < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 if (fd[0] >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 close (fd[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 report_file_error ("Doing vfork", Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 if (INTP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 if (fd[0] >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 close (fd[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 #if defined (NO_SUBPROCESSES)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 /* If Emacs has been built with asynchronous subprocess support,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 we don't need to do this, I think because it will then have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 the facilities for handling SIGCHLD. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 wait_without_blocking ();
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
514 #endif /* NO_SUBPROCESSES */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 int nread;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 int first = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 int total_read = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 Lisp_Object instream;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 /* Enable sending signal if user quits below. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 call_process_exited = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 /* MSDOS needs different cleanup information. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 record_unwind_protect (call_process_cleanup,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 Fcons (make_int (fd[0]),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 build_string (tempfile)));
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
533 #else /* not MSDOS */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 record_unwind_protect (call_process_cleanup,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 Fcons (make_int (fd[0]), make_int (pid)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 #endif /* not MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 /* FSFmacs calls Fset_buffer() here. We don't have to because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 we can insert into buffers other than the current one. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 if (EQ (buffer, Qt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 XSETBUFFER (buffer, current_buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 instream = make_filedesc_input_stream (fd[0], 0, -1, LSTR_ALLOW_QUIT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 GCPRO1 (instream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 /* Repeatedly read until we've filled as much as possible
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 of the buffer size we have. But don't read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 less than 1024--save that for the next bufferfull. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 nread = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 while (nread < bufsize - 1024)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 int this_read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 = Lstream_read (XLSTREAM (instream), bufptr + nread,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 bufsize - nread);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 if (this_read < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 goto give_up;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 if (this_read == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 goto give_up_1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 nread += this_read;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 give_up_1:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 /* Now NREAD is the total amount of data in the buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 if (nread == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 total_read += nread;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 if (!NILP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 buffer_insert_raw_string (XBUFFER (buffer), (Bufbyte *) bufptr,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 nread);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 /* Make the buffer bigger as we continue to read more data,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 but not past 64k. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 if (bufsize < 64 * 1024 && total_read > 32 * bufsize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 bufsize *= 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 bufptr = (char *) alloca (bufsize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 if (!NILP (display) && INTERACTIVE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 first = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 redisplay ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 give_up:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 Lstream_close (XLSTREAM (instream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 #ifndef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 /* Wait for it to terminate, unless it already has. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 wait_for_termination (pid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 /* Don't kill any children that the subprocess may have left behind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 when exiting. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 call_process_exited = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 unbind_to (speccount, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 if (synch_process_death)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 return build_string (synch_process_death);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 return make_int (synch_process_retcode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 #endif /* VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 #ifndef VMS /* VMS version is in vmsproc.c. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 /* This is the last thing run in a newly forked inferior
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 either synchronous or asynchronous.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 Copy descriptors IN, OUT and ERR as descriptors 0, 1 and 2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 Initialize inferior's priority, pgrp, connected dir and environment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 then exec another program based on new_argv.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 This function may change environ for the superior process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 Therefore, the superior process must save and restore the value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 of environ around the vfork and the call to this function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 ENV is the environment for the subprocess.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 XEmacs: We've removed the SET_PGRP argument because it's already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 done by the callers of child_setup.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 CURRENT_DIR is an elisp string giving the path of the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 directory the subprocess should have. Since we can't really signal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 a decent error from within the child, this should be verified as an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 executable directory by the parent. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 static int relocate_fd (int fd, int min);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 child_setup (int in, int out, int err, char **new_argv,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 CONST char *current_dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 #ifdef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 /* The MSDOS port of gcc cannot fork, vfork, ... so we must call system
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 instead. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 #else /* not MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 char **env;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 char *pwd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 int cpid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 HANDLE handles[4];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 #endif /* WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 #ifdef SET_EMACS_PRIORITY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 if (emacs_priority != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 nice (- emacs_priority);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 #if !defined (NO_SUBPROCESSES)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 /* Close Emacs's descriptors that this process should not have. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 close_process_descs ();
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
663 #endif /* not NO_SUBPROCESSES */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 close_load_descs ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 /* Note that use of alloca is always safe here. It's obvious for systems
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 that do not have true vfork or that have true (stack) alloca.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 If using vfork and C_ALLOCA it is safe because that changes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 the superior's static variables as if the superior had done alloca
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 and will be cleaned up in the usual way. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 REGISTER int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 i = strlen (current_dir);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 pwd = (char *) alloca (i + 6);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 memcpy (pwd, "PWD=", 4);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 memcpy (pwd + 4, current_dir, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 i += 4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 if (!IS_DIRECTORY_SEP (pwd[i - 1]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 pwd[i++] = DIRECTORY_SEP;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 pwd[i] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 /* We can't signal an Elisp error here; we're in a vfork. Since
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 the callers check the current directory before forking, this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 should only return an error if the directory's permissions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 are changed between the check and this chdir, but we should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 at least check. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 if (chdir (pwd + 4) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 /* Don't report the chdir error, or ange-ftp.el doesn't work. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 /* (FSFmacs does _exit (errno) here.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 pwd = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 /* Strip trailing "/". Cretinous *[]&@$#^%@#$% Un*x */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 /* leave "//" (from FSF) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 while (i > 6 && IS_DIRECTORY_SEP (pwd[i - 1]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 pwd[--i] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 /* Set `env' to a vector of the strings in Vprocess_environment. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 REGISTER Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 REGISTER char **new_env;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 REGISTER int new_length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 new_length = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 for (tem = Vprocess_environment;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (CONSP (tem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 && STRINGP (XCAR (tem)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 tem = XCDR (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 new_length++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 /* new_length + 2 to include PWD and terminating 0. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 env = new_env = (char **) alloca ((new_length + 2) * sizeof (char *));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 /* If we have a PWD envvar and we know the real current directory,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 pass one down, but with corrected value. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 if (pwd && getenv ("PWD"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 *new_env++ = pwd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 /* Copy the Vprocess_environment strings into new_env. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 for (tem = Vprocess_environment;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (CONSP (tem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 && STRINGP (XCAR (tem)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 tem = XCDR (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 char **ep = env;
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
731 char *string = (char *) XSTRING_DATA (XCAR (tem));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 /* See if this string duplicates any string already in the env.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 If so, don't put it in.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 When an env var has multiple definitions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 we keep the definition that comes first in process-environment. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 for (; ep != new_env; ep++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 char *p = *ep, *q = string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 if (*q == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 /* The string is malformed; might as well drop it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 goto duplicate;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 if (*q != *p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 if (*q == '=')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 goto duplicate;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 p++, q++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 if (pwd && !strncmp ("PWD=", string, 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 *new_env++ = pwd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 pwd = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 *new_env++ = string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 duplicate: ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 *new_env = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 prepare_standard_handles (in, out, err, handles);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 #else /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 /* Make sure that in, out, and err are not actually already in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 descriptors zero, one, or two; this could happen if Emacs is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 started with its standard in, out, or error closed, as might
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 happen under X. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 int oin = in, oout = out;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 /* We have to avoid relocating the same descriptor twice! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 in = relocate_fd (in, 3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 if (out == oin) out = in;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 else out = relocate_fd (out, 3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 if (err == oin) err = in;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 else if (err == oout) err = out;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 else err = relocate_fd (err, 3);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 close (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 close (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 close (2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 dup2 (in, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 dup2 (out, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 dup2 (err, 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 close (in);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 close (out);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 close (err);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 /* I can't think of any reason why child processes need any more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 than the standard 3 file descriptors. It would be cleaner to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 close just the ones that need to be, but the following brute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 force approach is certainly effective, and not too slow. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 int fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 for (fd=3; fd<=64; fd++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 close(fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 #endif /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 #ifdef vipc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 something missing here;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 #endif /* vipc */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 /* Spawn the child. (See ntproc.c:Spawnve). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 cpid = spawnve (_P_NOWAIT, new_argv[0], new_argv, env);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 if (cpid == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 /* An error occurred while trying to spawn the process. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 report_file_error ("Spawning child process", Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 reset_standard_handles (in, out, err, handles);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 return cpid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 #else /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 /* execvp does not accept an environment arg so the only way
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 to pass this environment is to set environ. Our caller
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 is responsible for restoring the ambient value of environ. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 environ = env;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 execvp (new_argv[0], new_argv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 stdout_out ("Cant't exec program %s\n", new_argv[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 _exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 #endif /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 #endif /* not MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 /* Move the file descriptor FD so that its number is not less than MIN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 If the file descriptor is moved at all, the original is freed. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 relocate_fd (int fd, int min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 if (fd >= min)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 return fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 int new = dup (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 if (new == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 stderr_out ("Error while setting up child: %s\n",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 strerror (errno));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 _exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 /* Note that we hold the original FD open while we recurse,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 to guarantee we'll get a new FD if we need it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 new = relocate_fd (new, min);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 close (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 return new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 getenv_internal (CONST Bufbyte *var,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 Bytecount varlen,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 Bufbyte **value,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 Bytecount *valuelen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 Lisp_Object scan;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 Lisp_Object entry = XCAR (scan);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 if (STRINGP (entry)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
871 && XSTRING_LENGTH (entry) > varlen
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
872 && XSTRING_BYTE (entry, varlen) == '='
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 /* NT environment variables are case insensitive. */
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
875 && ! memicmp (XSTRING_DATA (entry), var, varlen)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 #else /* not WINDOWSNT */
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
877 && ! memcmp (XSTRING_DATA (entry), var, varlen)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 #endif /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 {
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
881 *value = XSTRING_DATA (entry) + (varlen + 1);
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
882 *valuelen = XSTRING_LENGTH (entry) - (varlen + 1);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
890 DEFUN ("getenv", Fgetenv, 1, 2, "sEnvironment variable: \np", /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 Return the value of environment variable VAR, as a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 VAR is a string, the name of the variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 When invoked interactively, prints the value in the echo area.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
894 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
895 (var, interactivep))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 Bufbyte *value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 Bytecount valuelen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 Lisp_Object v = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 CHECK_STRING (var);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 GCPRO1 (v);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
904 if (getenv_internal (XSTRING_DATA (var), XSTRING_LENGTH (var),
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 &value, &valuelen))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 v = make_string (value, valuelen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 if (!NILP (interactivep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 if (NILP (v))
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
910 message ("%s not defined in environment", XSTRING_DATA (var));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 message ("\"%s\"", value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 RETURN_UNGCPRO (v);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 /* A version of getenv that consults process_environment, easily
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 callable from C. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 egetenv (CONST char *var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 Bufbyte *value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 Bytecount valuelen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 if (getenv_internal ((CONST Bufbyte *) var, strlen (var), &value, &valuelen))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 return (char *) value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 #endif /* not VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 init_callproc (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 REGISTER char *sh;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 Lisp_Object tempdir;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 Vprocess_environment = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 /* jwz: always initialize Vprocess_environment, so that egetenv() works
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 in temacs. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 char **envp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 for (envp = environ; envp && *envp; envp++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 Vprocess_environment = Fcons (build_ext_string (*envp, FORMAT_OS),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 Vprocess_environment);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 /* jwz: don't do these things when in temacs (this used to be the case by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 virtue of egetenv() always returning 0, but that has been changed).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 #ifndef CANNOT_DUMP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 if (!initialized)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 Vdata_directory = Qnil;
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
957 Vsite_directory = Qnil;
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
958 Vdoc_directory = Qnil;
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
959 Vexec_path = Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 char *data_dir = egetenv ("EMACSDATA");
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
965 char *site_dir = egetenv ("EMACSSITE");
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
966 char *doc_dir = egetenv ("EMACSDOC");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 #ifdef PATH_DATA
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 if (!data_dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 data_dir = (char *) PATH_DATA;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 #ifdef PATH_DOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 if (!doc_dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 doc_dir = (char *) PATH_DOC;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 #endif
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
976 #ifdef PATH_SITE
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
977 if (!site_dir)
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
978 site_dir = (char *) PATH_SITE;
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
979 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 if (data_dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 Vdata_directory = Ffile_name_as_directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (build_string (data_dir));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 Vdata_directory = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 if (doc_dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 Vdoc_directory = Ffile_name_as_directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 (build_string (doc_dir));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 Vdoc_directory = Qnil;
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
991 if (site_dir)
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
992 Vsite_directory = Ffile_name_as_directory
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
993 (build_string (site_dir));
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
994 else
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
995 Vsite_directory = Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 /* Check the EMACSPATH environment variable, defaulting to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 PATH_EXEC path from paths.h. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 Vexec_path = decode_env_path ("EMACSPATH",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 #ifdef PATH_EXEC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 PATH_EXEC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 if (NILP (Vexec_path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 Vexec_directory = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 Vexec_directory = Ffile_name_as_directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 (Fcar (Vexec_path));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 if (initialized)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 Vexec_path = nconc2 (decode_env_path ("PATH", 0),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 Vexec_path);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 if (!NILP (Vexec_directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 tempdir = Fdirectory_file_name (Vexec_directory);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
1021 if (access ((char *) XSTRING_DATA (tempdir), 0) < 0)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 /* If the hard-coded path is bogus, fail silently.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 This will allow the normal heuristics to make an attempt. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 warn_when_safe
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 (Qpath, Qwarning,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 "Warning: machine-dependent data dir (%s) does not exist.\n",
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
1029 XSTRING_DATA (Vexec_directory));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 Vexec_directory = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 if (!NILP (Vdata_directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 tempdir = Fdirectory_file_name (Vdata_directory);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
1039 if (access ((char *) XSTRING_DATA (tempdir), 0) < 0)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 /* If the hard-coded path is bogus, fail silently.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 This will allow the normal heuristics to make an attempt. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 warn_when_safe
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 (Qpath, Qwarning,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 "Warning: machine-independent data dir (%s) does not exist.\n",
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
1047 XSTRING_DATA (Vdata_directory));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 Vdata_directory = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1054 if (!NILP (Vsite_directory))
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1055 {
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1056 tempdir = Fdirectory_file_name (Vsite_directory);
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1057 if (access ((char *) XSTRING_DATA (tempdir), 0) < 0)
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1058 {
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1059 /* If the hard-coded path is bogus, fail silently.
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1060 This will allow the normal heuristics to make an attempt. */
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1061 #if 0
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1062 warn_when_safe
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1063 (Qpath, Qwarning,
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1064 "Warning: machine-independent site dir (%s) does not exist.\n",
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1065 XSTRING_DATA (Vsite_directory));
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1066 #else
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1067 Vsite_directory = Qnil;
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1068 #endif
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1069 }
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1070 }
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1071
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 #ifdef PATH_PREFIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 Vprefix_directory = build_string ((char *) PATH_PREFIX);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 Vprefix_directory = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 Vshell_file_name = build_string ("*dcl*");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 #else /* not VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 sh = (char *) egetenv ("SHELL");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 #ifdef DOS_NT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 if (!sh) sh = egetenv ("COMSPEC");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 char *tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 if (sh)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 tem = (char *) alloca (strlen (sh) + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 sh = dostounix_filename (strcpy (tem, sh));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 Vshell_file_name = build_string (sh ? sh : "/command.com");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 #else /* not DOS_NT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 Vshell_file_name = build_string (sh ? sh : "/bin/sh");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 #endif /* not DOS_NT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 #endif /* not VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 set_process_environment (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 REGISTER char **envp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 Vprocess_environment = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 #ifndef CANNOT_DUMP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 if (initialized)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 for (envp = environ; *envp; envp++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 Vprocess_environment = Fcons (build_string (*envp),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 Vprocess_environment);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 #endif /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 syms_of_callproc (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 #ifndef VMS
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
1119 DEFSUBR (Fcall_process_internal);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 14
diff changeset
1120 DEFSUBR (Fgetenv);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 vars_of_callproc (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 #ifdef DOS_NT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 DEFVAR_LISP ("binary-process-input", &Vbinary_process_input /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 *If non-nil then new subprocesses are assumed to take binary input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 Vbinary_process_input = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 DEFVAR_LISP ("binary-process-output", &Vbinary_process_output /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 *If non-nil then new subprocesses are assumed to produce binary output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 Vbinary_process_output = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 #endif /* DOS_NT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 DEFVAR_LISP ("shell-file-name", &Vshell_file_name /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 *File name to load inferior shells from.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 Initialized from the SHELL environment variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 DEFVAR_LISP ("exec-path", &Vexec_path /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 *List of directories to search programs to run in subprocesses.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 Each element is a string (directory name) or nil (try default directory).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 DEFVAR_LISP ("exec-directory", &Vexec_directory /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 Directory of architecture-dependent files that come with XEmacs,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 especially executable programs intended for Emacs to invoke.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 DEFVAR_LISP ("data-directory", &Vdata_directory /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 Directory of architecture-independent files that come with XEmacs,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 intended for Emacs to use.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1160 DEFVAR_LISP ("site-directory", &Vsite_directory /*
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1161 Directory of architecture-independent files that do not come with XEmacs,
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1162 intended for Emacs to use.
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1163 */ );
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 20
diff changeset
1164
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 /* FSF puts the DOC file into data-directory. They do a bunch of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 contortions to attempt to put everything into the DOC file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 whether the support is there or not. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 DEFVAR_LISP ("doc-directory", &Vdoc_directory /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 Directory containing the DOC file that comes with XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 This is usually the same as exec-directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 DEFVAR_LISP ("prefix-directory", &Vprefix_directory /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 The default directory under which XEmacs is installed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 DEFVAR_LISP ("process-environment", &Vprocess_environment /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 List of environment variables for subprocesses to inherit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 Each element should be a string of the form ENVVARNAME=VALUE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 The environment which Emacs inherits is placed in this variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 when Emacs starts.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 complex_vars_of_callproc (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 DEFVAR_LISP ("configure-info-directory", &Vconfigure_info_directory /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 For internal use by the build procedure only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 This is the name of the directory in which the build procedure installed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 Emacs's info files; the default value for Info-default-directory-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 includes this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 #ifdef PATH_INFO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 Vconfigure_info_directory =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 Ffile_name_as_directory (build_string (PATH_INFO));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 Vconfigure_info_directory = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 }