annotate src/callproc.c @ 737:6415e2b73e04

[xemacs-hg @ 2002-02-02 01:53:07 by youngs] 2002-02-01 Steve Youngs <youngs@xemacs.org> * xemacs/packages.texi (Removing Packages): The interactive function is 'package-get-delete-package'.
author youngs
date Sat, 02 Feb 2002 01:53:09 +0000
parents fdefd0186b75
children 943eaba38521
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
1 /* Old synchronous subprocess invocation for XEmacs.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1985, 86, 87, 88, 93, 94, 95 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 /* Synched up with: Mule 2.0, FSF 19.30. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 /* Partly sync'ed with 19.36.4 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
24
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
25 /* #### This ENTIRE file is only used in batch mode.
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
26
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
27 We only need two things to get rid of both this and ntproc.c:
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
28
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
29 -- my `stderr-proc' ws, which adds support for a separate stderr
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
30 in asynch. subprocesses. (it's a feature in `old-call-process-internal'.)
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
31 -- a noninteractive event loop that supports processes.
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
32 */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
33
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 #include "commands.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 #include "insdel.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 #include "lstream.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 #include "process.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 #include "sysdep.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 #include "window.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 #ifdef FILE_CODING
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 #include "file-coding.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 #include "systime.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 #include "sysproc.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 #include "sysfile.h" /* Always include after sysproc.h */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 #include "syssignal.h" /* Always include before systty.h */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 #include "systty.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
54 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 #define _P_NOWAIT 1 /* from process.h */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 #include "nt.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
59 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 /* When we are starting external processes we need to know whether they
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 take binary input (no conversion) or text input (\n is converted to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 \r\n). Similarly for output: if newlines are written as \r\n then it's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 text process output, otherwise it's binary. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 Lisp_Object Vbinary_process_input;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 Lisp_Object Vbinary_process_output;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
66 #endif /* WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 Lisp_Object Vshell_file_name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 /* The environment to pass to all subprocesses when they are started.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 This is in the semi-bogus format of ("VAR=VAL" "VAR2=VAL2" ... )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 Lisp_Object Vprocess_environment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 /* True iff we are about to fork off a synchronous process or if we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 are waiting for it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 volatile int synch_process_alive;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 /* Nonzero => this is a string explaining death of synchronous subprocess. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
80 const char *synch_process_death;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 /* If synch_process_death is zero,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 this is exit code of synchronous subprocess. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 int synch_process_retcode;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 /* Clean up when exiting Fcall_process_internal.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
87 On Windows, delete the temporary file on any kind of termination.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 On Unix, kill the process and any children on termination by signal. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 /* Nonzero if this is termination due to exit. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 static int call_process_exited;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 Lisp_Object Vlisp_EXEC_SUFFIXES;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 call_process_kill (Lisp_Object fdpid)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 Lisp_Object fd = Fcar (fdpid);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 Lisp_Object pid = Fcdr (fdpid);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 if (!NILP (fd))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 close (XINT (fd));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 if (!NILP (pid))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 EMACS_KILLPG (XINT (pid), SIGKILL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 synch_process_alive = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 call_process_cleanup (Lisp_Object fdpid)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
114 int fd = XINT (Fcar (fdpid));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 int pid = XINT (Fcdr (fdpid));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 if (!call_process_exited &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 EMACS_KILLPG (pid, SIGINT) == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 int speccount = specpdl_depth ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 record_unwind_protect (call_process_kill, fdpid);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 /* #### "c-G" -- need non-consing Single-key-description */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 message ("Waiting for process to die...(type C-g again to kill it instantly)");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
126 #ifdef WIN32_NATIVE
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
127 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
128 HANDLE pHandle = OpenProcess (PROCESS_ALL_ACCESS, 0, pid);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
129 if (pHandle == NULL)
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
130 warn_when_safe (Qprocess, Qwarning,
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
131 "cannot open process (PID %d) for cleanup", pid);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
132 else
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
133 wait_for_termination (pHandle);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
134 }
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
135 #else
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 wait_for_termination (pid);
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
137 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 /* "Discard" the unwind protect. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 XCAR (fdpid) = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 XCDR (fdpid) = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 unbind_to (speccount, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 message ("Waiting for process to die... done");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 synch_process_alive = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 close (fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
151 DEFUN ("old-call-process-internal", Fold_call_process_internal, 1, MANY, 0, /*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 Call PROGRAM synchronously in separate process, with coding-system specified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 Arguments are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 (PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 The program's input comes from file INFILE (nil means `/dev/null').
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 Insert output in BUFFER before point; t means current buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 nil for BUFFER means discard it; 0 means discard and don't wait.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 REAL-BUFFER says what to do with standard output, as above,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 while STDERR-FILE says what to do with standard error in the child.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 STDERR-FILE may be nil (discard standard error output),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 t (mix it with ordinary output), or a file name string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 Remaining arguments are strings passed as command arguments to PROGRAM.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 If BUFFER is 0, `call-process' returns immediately with value nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 Otherwise it waits for PROGRAM to terminate and returns a numeric exit status
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 or a signal description string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 If you quit, the process is killed with SIGINT, or SIGKILL if you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 quit again.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 Lisp_Object infile, buffer, current_dir, display, path;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 int fd[2];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 int filefd;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
179 #ifdef WIN32_NATIVE
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
180 HANDLE pHandle;
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
181 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 int pid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 char buf[16384];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 char *bufptr = buf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 int bufsize = 16384;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 int speccount = specpdl_depth ();
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
187 struct gcpro gcpro1, gcpro2, gcpro3;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 char **new_argv = alloca_array (char *, max (2, nargs - 2));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 /* File to use for stderr in the child.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 t means use same as standard output. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 Lisp_Object error_file;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 CHECK_STRING (args[0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 error_file = Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 #if defined (NO_SUBPROCESSES)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 /* Without asynchronous processes we cannot have BUFFER == 0. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 if (nargs >= 3 && !INTP (args[2]))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
201 signal_error (Qunimplemented, "Operating system cannot handle asynchronous subprocesses", Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 #endif /* NO_SUBPROCESSES */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
204 /* Do all filename munging before building new_argv because GC in
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
205 * Lisp code called by various filename-hacking routines might
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
206 * relocate strings */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 locate_file (Vexec_path, args[0], Vlisp_EXEC_SUFFIXES, &path, X_OK);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 /* Make sure that the child will be able to chdir to the current
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
210 buffer's current directory, or its unhandled equivalent. [[ We
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 can't just have the child check for an error when it does the
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
212 chdir, since it's in a vfork. ]] -- not any more, we don't use
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
213 vfork. -ben
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
214
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
215 Note: These calls are spread out to insure that the return values
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
216 of the calls (which may be newly-created strings) are properly
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
217 GC-protected. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 struct gcpro ngcpro1, ngcpro2;
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
220 NGCPRO2 (current_dir, path); /* Caller gcprotects args[] */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
221 current_dir = current_buffer->directory;
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
222 /* If the current dir has no terminating slash, we'll get undesirable
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
223 results, so put the slash back. */
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
224 current_dir = Ffile_name_as_directory (current_dir);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 current_dir = Funhandled_file_name_directory (current_dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 current_dir = expand_and_dir_to_file (current_dir, Qnil);
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 462
diff changeset
227
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 /* This is in FSF, but it breaks everything in the presence of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 ange-ftp-visited files, so away with it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 if (NILP (Ffile_accessible_directory_p (current_dir)))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
232 signal_error (Qprocess_error, "Setting current directory",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
233 current_buffer->directory);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 #endif /* 0 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 NUNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
238 GCPRO2 (current_dir, path);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 if (nargs >= 2 && ! NILP (args[1]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 struct gcpro ngcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 NGCPRO1 (current_buffer->directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 infile = Fexpand_file_name (args[1], current_buffer->directory);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 NUNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 CHECK_STRING (infile);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 infile = build_string (NULL_DEVICE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
253 GCPRO3 (infile, current_dir, path); /* Fexpand_file_name might trash it */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 if (nargs >= 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 buffer = args[2];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 /* If BUFFER is a list, its meaning is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 (BUFFER-FOR-STDOUT FILE-FOR-STDERR). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 if (CONSP (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 if (CONSP (XCDR (buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 Lisp_Object file_for_stderr = XCAR (XCDR (buffer));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 if (NILP (file_for_stderr) || EQ (Qt, file_for_stderr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 error_file = file_for_stderr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 error_file = Fexpand_file_name (file_for_stderr, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 buffer = XCAR (buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 if (!(EQ (buffer, Qnil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 || EQ (buffer, Qt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 || ZEROP (buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 Lisp_Object spec_buffer = buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 buffer = Fget_buffer (buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 /* Mention the buffer name for a better error message. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 if (NILP (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 CHECK_BUFFER (spec_buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 CHECK_BUFFER (buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 buffer = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 display = ((nargs >= 4) ? args[3] : Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 /* From here we assume we won't GC (unless an error is signaled). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 REGISTER int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 for (i = 4; i < nargs; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 CHECK_STRING (args[i]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 new_argv[i - 3] = (char *) XSTRING_DATA (args[i]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 }
430
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
304 new_argv[max(nargs - 3,1)] = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 if (NILP (path))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
307 signal_error (Qprocess_error, "Searching for program", args[0]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 new_argv[0] = (char *) XSTRING_DATA (path);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 filefd = open ((char *) XSTRING_DATA (infile), O_RDONLY | OPEN_BINARY, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 if (filefd < 0)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
312 report_process_error ("Opening process input file", infile);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 if (INTP (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 fd[1] = open (NULL_DEVICE, O_WRONLY | OPEN_BINARY, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 fd[0] = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 pipe (fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 /* Replaced by close_process_descs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 set_exclusive_use (fd[0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 /* child_setup must clobber environ in systems with true vfork.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 Protect it from permanent change. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 REGISTER char **save_environ = environ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 REGISTER int fd1 = fd[1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 int fd_error = fd1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 /* Record that we're about to create a synchronous process. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 synch_process_alive = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 /* These vars record information from process termination.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 Clear them now before process can possibly terminate,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 to avoid timing error if process terminates soon. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 synch_process_death = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 synch_process_retcode = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 if (NILP (error_file))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 fd_error = open (NULL_DEVICE, O_WRONLY | OPEN_BINARY);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 else if (STRINGP (error_file))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
348 fd_error = open ((const char *) XSTRING_DATA (error_file),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
349 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 O_WRONLY | O_TRUNC | O_CREAT | O_TEXT,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 S_IREAD | S_IWRITE
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
352 #else /* not WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 O_WRONLY | O_TRUNC | O_CREAT | OPEN_BINARY,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 CREAT_MODE
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
355 #endif /* not WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 if (fd_error < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
361 int save_errno = errno;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 close (filefd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 close (fd[0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 if (fd1 >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 close (fd1);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
366 errno = save_errno;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
367 report_process_error ("Cannot open", error_file);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
370 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 pid = child_setup (filefd, fd1, fd_error, new_argv,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 (char *) XSTRING_DATA (current_dir));
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
373 if (!INTP (buffer))
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
374 {
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
375 /* OpenProcess() as soon after child_setup as possible. It's too
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
376 late once the process terminated. */
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
377 pHandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
378 #if 0
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
379 if (pHandle == NULL)
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
380 {
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
381 /* #### seems to cause crash in unbind_to(...) below. APA */
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
382 warn_when_safe (Qprocess, Qwarning,
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
383 "cannot open process to wait for");
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
384 }
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
385 #endif
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
386 }
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
387 /* Close STDERR into the parent process. We no longer need it. */
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
388 if (fd_error >= 0)
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
389 close (fd_error);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
390 #else /* not WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 pid = fork ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 if (pid == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 if (fd[0] >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 close (fd[0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 /* This is necessary because some shells may attempt to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 access the current controlling terminal and will hang
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 if they are run in the background, as will be the case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 when XEmacs is started in the background. Martin
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 Buchholz observed this problem running a subprocess
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 that used zsh to call gzip to uncompress an info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 file. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 disconnect_controlling_terminal ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 child_setup (filefd, fd1, fd_error, new_argv,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 (char *) XSTRING_DATA (current_dir));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 if (fd_error >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 close (fd_error);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
411 #endif /* not WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 environ = save_environ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 /* Close most of our fd's, but not fd[0]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 since we will use that to read input from. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 close (filefd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 if (fd1 >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 close (fd1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
422 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 if (pid < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
425 int save_errno = errno;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 if (fd[0] >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 close (fd[0]);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
428 errno = save_errno;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
429 report_process_error ("Doing fork", Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 }
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
431 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 if (INTP (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 if (fd[0] >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 close (fd[0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 #if defined (NO_SUBPROCESSES)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 /* If Emacs has been built with asynchronous subprocess support,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 we don't need to do this, I think because it will then have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 the facilities for handling SIGCHLD. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 wait_without_blocking ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 #endif /* NO_SUBPROCESSES */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 int nread;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 int total_read = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 Lisp_Object instream;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 struct gcpro ngcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 /* Enable sending signal if user quits below. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 call_process_exited = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 record_unwind_protect (call_process_cleanup,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 Fcons (make_int (fd[0]), make_int (pid)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 /* FSFmacs calls Fset_buffer() here. We don't have to because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 we can insert into buffers other than the current one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 if (EQ (buffer, Qt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 XSETBUFFER (buffer, current_buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 instream = make_filedesc_input_stream (fd[0], 0, -1, LSTR_ALLOW_QUIT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 #ifdef FILE_CODING
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 instream =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 make_decoding_input_stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 (XLSTREAM (instream),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 Fget_coding_system (Vcoding_system_for_read));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 Lstream_set_character_mode (XLSTREAM (instream));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 NGCPRO1 (instream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 /* Repeatedly read until we've filled as much as possible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 of the buffer size we have. But don't read
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 less than 1024--save that for the next bufferfull. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 nread = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 while (nread < bufsize - 1024)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
481 Bytecount this_read
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 = Lstream_read (XLSTREAM (instream), bufptr + nread,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 bufsize - nread);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 if (this_read < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 goto give_up;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 if (this_read == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 goto give_up_1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 nread += this_read;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 give_up_1:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 /* Now NREAD is the total amount of data in the buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 if (nread == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
500 #if 0
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
501 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 /* Until we pull out of MULE things like
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 make_decoding_input_stream(), we do the following which is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 less elegant. --marcpa */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
505 /* We did. -- kkm */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 int lf_count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 if (NILP (Vbinary_process_output)) {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 nread = crlf_to_lf(nread, bufptr, &lf_count);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 #endif
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
513 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 total_read += nread;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 if (!NILP (buffer))
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
518 buffer_insert_raw_string (XBUFFER (buffer), (Intbyte *) bufptr,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 nread);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 /* Make the buffer bigger as we continue to read more data,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 but not past 64k. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 if (bufsize < 64 * 1024 && total_read > 32 * bufsize)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 bufsize *= 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 bufptr = (char *) alloca (bufsize);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 if (!NILP (display) && INTERACTIVE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 redisplay ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 give_up:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 Lstream_close (XLSTREAM (instream));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 NUNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 QUIT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 /* Wait for it to terminate, unless it already has. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
540 #ifdef WIN32_NATIVE
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
541 wait_for_termination (pHandle);
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
542 #else
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 wait_for_termination (pid);
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 430
diff changeset
544 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 /* Don't kill any children that the subprocess may have left behind
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 when exiting. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 call_process_exited = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 unbind_to (speccount, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 if (synch_process_death)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 return build_string (synch_process_death);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 return make_int (synch_process_retcode);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 /* Move the file descriptor FD so that its number is not less than MIN. *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 The original file descriptor remains open. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 relocate_fd (int fd, int min)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 if (fd >= min)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 return fd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 int newfd = dup (fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 if (newfd == -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 stderr_out ("Error while setting up child: %s\n",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 strerror (errno));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 _exit (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 return relocate_fd (newfd, min);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 /* This is the last thing run in a newly forked inferior
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 either synchronous or asynchronous.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 Copy descriptors IN, OUT and ERR
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 as descriptors STDIN_FILENO, STDOUT_FILENO, and STDERR_FILENO.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 Initialize inferior's priority, pgrp, connected dir and environment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 then exec another program based on new_argv.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 This function may change environ for the superior process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 Therefore, the superior process must save and restore the value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 of environ around the fork and the call to this function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 ENV is the environment for the subprocess.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 XEmacs: We've removed the SET_PGRP argument because it's already
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 done by the callers of child_setup.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 CURRENT_DIR is an elisp string giving the path of the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 directory the subprocess should have. Since we can't really signal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 a decent error from within the child, this should be verified as an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 executable directory by the parent. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
600 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 child_setup (int in, int out, int err, char **new_argv,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
606 const char *current_dir)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 char **env;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 char *pwd;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
610 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 int cpid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 HANDLE handles[4];
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
613 #endif /* WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 #ifdef SET_EMACS_PRIORITY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 if (emacs_priority != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 nice (- emacs_priority);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
620 /* Under Windows, we are not in a child process at all, so we should
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
621 not close handles inherited from the parent -- we are the parent
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
622 and doing so will screw up all manner of things! Similarly, most
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
623 of the rest of the cleanup done in this function is not done
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
624 under Windows.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
625
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
626 #### This entire child_setup() function is an utter and complete
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
627 piece of shit. I would rewrite it, at the very least splitting
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
628 out the Windows and non-Windows stuff into two completely
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
629 different functions; but instead I'm trying to make it go away
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
630 entirely, using the Lisp definition in process.el. What's left
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
631 is to fix up the routines in event-msw.c (and in event-Xt.c and
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
632 event-tty.c) to allow for stream devices to be handled correctly.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
633 There isn't much to do, in fact, and I'll fix it shortly. That
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
634 way, the Lisp definition can be used non-interactively too. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
635 #if !defined (NO_SUBPROCESSES) && !defined (WIN32_NATIVE)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 /* Close Emacs's descriptors that this process should not have. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 close_process_descs ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 #endif /* not NO_SUBPROCESSES */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
639 #ifndef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 close_load_descs ();
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
641 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 /* Note that use of alloca is always safe here. It's obvious for systems
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 that do not have true vfork or that have true (stack) alloca.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 If using vfork and C_ALLOCA it is safe because that changes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 the superior's static variables as if the superior had done alloca
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 and will be cleaned up in the usual way. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 REGISTER int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 i = strlen (current_dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 pwd = alloca_array (char, i + 6);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 memcpy (pwd, "PWD=", 4);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 memcpy (pwd + 4, current_dir, i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 i += 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 if (!IS_DIRECTORY_SEP (pwd[i - 1]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 pwd[i++] = DIRECTORY_SEP;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 pwd[i] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 /* We can't signal an Elisp error here; we're in a vfork. Since
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 the callers check the current directory before forking, this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 should only return an error if the directory's permissions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 are changed between the check and this chdir, but we should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 at least check. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 if (chdir (pwd + 4) < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 /* Don't report the chdir error, or ange-ftp.el doesn't work. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 /* (FSFmacs does _exit (errno) here.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 pwd = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 /* Strip trailing "/". Cretinous *[]&@$#^%@#$% Un*x */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 /* leave "//" (from FSF) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 while (i > 6 && IS_DIRECTORY_SEP (pwd[i - 1]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 pwd[--i] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 /* Set `env' to a vector of the strings in Vprocess_environment. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 /* + 2 to include PWD and terminating 0. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 env = alloca_array (char *, XINT (Flength (Vprocess_environment)) + 2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 REGISTER Lisp_Object tail;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 char **new_env = env;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 /* If we have a PWD envvar and we know the real current directory,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 pass one down, but with corrected value. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 if (pwd && getenv ("PWD"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 *new_env++ = pwd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 /* Copy the Vprocess_environment strings into new_env. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 for (tail = Vprocess_environment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 CONSP (tail) && STRINGP (XCAR (tail));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 tail = XCDR (tail))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 char **ep = env;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 char *envvar_external;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
700 TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (tail),
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
701 C_STRING_ALLOCA, envvar_external,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
702 Qfile_name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 /* See if envvar_external duplicates any string already in the env.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 If so, don't put it in.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 When an env var has multiple definitions,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 we keep the definition that comes first in process-environment. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 for (; ep != new_env; ep++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 char *p = *ep, *q = envvar_external;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 if (*q == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 /* The string is malformed; might as well drop it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 goto duplicate;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 if (*q != *p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 if (*q == '=')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 goto duplicate;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 p++, q++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 if (pwd && !strncmp ("PWD=", envvar_external, 4))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 *new_env++ = pwd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 pwd = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 *new_env++ = envvar_external;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 duplicate: ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 *new_env = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
736 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 prepare_standard_handles (in, out, err, handles);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 set_process_dir (current_dir);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
739 #else /* not WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 /* Make sure that in, out, and err are not actually already in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 descriptors zero, one, or two; this could happen if Emacs is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 started with its standard in, out, or error closed, as might
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 happen under X. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 in = relocate_fd (in, 3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 out = relocate_fd (out, 3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 err = relocate_fd (err, 3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 /* Set the standard input/output channels of the new process. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 close (STDIN_FILENO);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 close (STDOUT_FILENO);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 close (STDERR_FILENO);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 dup2 (in, STDIN_FILENO);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 dup2 (out, STDOUT_FILENO);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 dup2 (err, STDERR_FILENO);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 close (in);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 close (out);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 close (err);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 /* I can't think of any reason why child processes need any more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 than the standard 3 file descriptors. It would be cleaner to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 close just the ones that need to be, but the following brute
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 force approach is certainly effective, and not too slow. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 int fd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 for (fd=3; fd<=64; fd++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 close (fd);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
770 #endif /* not WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 #ifdef vipc
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 something missing here;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 #endif /* vipc */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
776 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 /* Spawn the child. (See ntproc.c:Spawnve). */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
778 cpid = spawnve (_P_NOWAIT, new_argv[0], (const char* const*)new_argv,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
779 (const char* const*)env);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 if (cpid == -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 /* An error occurred while trying to spawn the process. */
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
782 report_process_error ("Spawning child process", Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 reset_standard_handles (in, out, err, handles);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 return cpid;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
785 #else /* not WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 /* execvp does not accept an environment arg so the only way
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 to pass this environment is to set environ. Our caller
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 is responsible for restoring the ambient value of environ. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 environ = env;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 execvp (new_argv[0], new_argv);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 stdout_out ("Can't exec program %s\n", new_argv[0]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 _exit (1);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
794 #endif /* not WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 static int
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
798 getenv_internal (const Intbyte *var,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 Bytecount varlen,
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
800 Intbyte **value,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 Bytecount *valuelen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 Lisp_Object scan;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 Lisp_Object entry = XCAR (scan);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 if (STRINGP (entry)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 && XSTRING_LENGTH (entry) > varlen
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 && XSTRING_BYTE (entry, varlen) == '='
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
812 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 /* NT environment variables are case insensitive. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 && ! memicmp (XSTRING_DATA (entry), var, varlen)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
815 #else /* not WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 && ! memcmp (XSTRING_DATA (entry), var, varlen)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
817 #endif /* not WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 *value = XSTRING_DATA (entry) + (varlen + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 *valuelen = XSTRING_LENGTH (entry) - (varlen + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 DEFUN ("getenv", Fgetenv, 1, 2, "sEnvironment variable: \np", /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 Return the value of environment variable VAR, as a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 VAR is a string, the name of the variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 When invoked interactively, prints the value in the echo area.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 (var, interactivep))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
836 Intbyte *value;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 Bytecount valuelen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 Lisp_Object v = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 CHECK_STRING (var);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 GCPRO1 (v);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 if (getenv_internal (XSTRING_DATA (var), XSTRING_LENGTH (var),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 &value, &valuelen))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 v = make_string (value, valuelen);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 if (!NILP (interactivep))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 if (NILP (v))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 message ("%s not defined in environment", XSTRING_DATA (var));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 /* #### Should use Fprin1_to_string or Fprin1 to handle string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 containing quotes correctly. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 message ("\"%s\"", value);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 RETURN_UNGCPRO (v);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 /* A version of getenv that consults process_environment, easily
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 callable from C. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 char *
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
861 egetenv (const char *var)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
863 /* This cannot GC -- 7-28-00 ben */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
864 Intbyte *value;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 Bytecount valuelen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
867 if (getenv_internal ((const Intbyte *) var, strlen (var), &value, &valuelen))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 return (char *) value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 init_callproc (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 /* jwz: always initialize Vprocess_environment, so that egetenv()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 works in temacs. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 char **envp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 Vprocess_environment = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 for (envp = environ; envp && *envp; envp++)
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
885 Vprocess_environment =
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 432
diff changeset
886 Fcons (build_ext_string (*envp, Qfile_name), Vprocess_environment);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 /* Initialize shell-file-name from environment variables or best guess. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
891 #ifdef WIN32_NATIVE
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
892 const char *shell = egetenv ("SHELL");
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
893 if (!shell) shell = egetenv ("COMSPEC");
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
894 /* Should never happen! */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
895 if (!shell) shell = (GetVersion () & 0x80000000 ? "command" : "cmd");
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
896 #else /* not WIN32_NATIVE */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
897 const char *shell = egetenv ("SHELL");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 if (!shell) shell = "/bin/sh";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
901 #if 0 /* defined (WIN32_NATIVE) */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
902 /* BAD BAD BAD. We do not wanting to be passing an XEmacs-created
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
903 SHELL var down to some inferior Cygwin process, which might get
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
904 screwed up.
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
905
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
906 There are a few broken apps (eterm/term.el, eterm/tshell.el,
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
907 os-utils/terminal.el, texinfo/tex-mode.el) where this will
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
908 cause problems. Those broken apps don't look at
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
909 shell-file-name, instead just at explicit-shell-file-name,
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
910 ESHELL and SHELL. They are apparently attempting to borrow
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
911 what `M-x shell' uses, but that latter also looks at
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
912 shell-file-name. What we want is for all of these apps to look
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
913 at shell-file-name, so that the user can change the value of
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
914 shell-file-name and everything will work out hunky-dorey.
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
915 */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
916
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
917 if (!egetenv ("SHELL"))
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
918 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
919 CIntbyte *faux_var = alloca_array (CIntbyte, 7 + strlen (shell));
611
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
920 sprintf (faux_var, "SHELL=%s", shell);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
921 Vprocess_environment = Fcons (build_string (faux_var),
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
922 Vprocess_environment);
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
923 }
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
924 #endif /* 0 */
38db05db9cb5 [xemacs-hg @ 2001-06-08 12:21:09 by ben]
ben
parents: 563
diff changeset
925
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 Vshell_file_name = build_string (shell);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 set_process_environment (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 REGISTER char **envp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 Vprocess_environment = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 #ifndef CANNOT_DUMP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 if (initialized)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 for (envp = environ; *envp; envp++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 Vprocess_environment = Fcons (build_string (*envp),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 Vprocess_environment);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 #endif /* unused */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 syms_of_callproc (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
949 DEFSUBR (Fold_call_process_internal);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 DEFSUBR (Fgetenv);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 vars_of_callproc (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 /* This function can GC */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
957 #ifdef WIN32_NATIVE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 DEFVAR_LISP ("binary-process-input", &Vbinary_process_input /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 *If non-nil then new subprocesses are assumed to take binary input.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 Vbinary_process_input = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 DEFVAR_LISP ("binary-process-output", &Vbinary_process_output /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 *If non-nil then new subprocesses are assumed to produce binary output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 Vbinary_process_output = Qnil;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
967 #endif /* WIN32_NATIVE */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 DEFVAR_LISP ("shell-file-name", &Vshell_file_name /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 *File name to load inferior shells from.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 Initialized from the SHELL environment variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 DEFVAR_LISP ("process-environment", &Vprocess_environment /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 List of environment variables for subprocesses to inherit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 Each element should be a string of the form ENVVARNAME=VALUE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 The environment which Emacs inherits is placed in this variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 when Emacs starts.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 Vlisp_EXEC_SUFFIXES = build_string (EXEC_SUFFIXES);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 staticpro (&Vlisp_EXEC_SUFFIXES);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 }