annotate src/callproc.c @ 765:e4093444f9f8

*** empty log message ***
author Jim Blandy <jimb@redhat.com>
date Mon, 13 Jul 1992 20:53:59 +0000
parents 012c1f6e9e7d
children 1e2e41fd188b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
1 /* Synchronous subprocess invocation for GNU Emacs.
579
e2782df984a2 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 545
diff changeset
2 Copyright (C) 1985, 1986, 1987, 1988, 1992 Free Software Foundation, Inc.
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
3
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
4 This file is part of GNU Emacs.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
5
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
6 GNU Emacs is free software; you can redistribute it and/or modify
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
7 it under the terms of the GNU General Public License as published by
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 the Free Software Foundation; either version 1, or (at your option)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 any later version.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 GNU Emacs is distributed in the hope that it will be useful,
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 GNU General Public License for more details.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 along with GNU Emacs; see the file COPYING. If not, write to
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 #include <signal.h>
538
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
22 #include <errno.h>
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 #include "config.h"
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26 /* Define SIGCHLD as an alias for SIGCLD. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 #if !defined (SIGCHLD) && defined (SIGCLD)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 #define SIGCHLD SIGCLD
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 #endif /* SIGCLD */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 #include <sys/types.h>
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 #define PRIO_PROCESS 0
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 #include <sys/file.h>
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 #ifdef USG5
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 #include <fcntl.h>
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 #ifndef O_RDONLY
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 #define O_RDONLY 0
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 #ifndef O_WRONLY
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 #define O_WRONLY 1
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 #include "lisp.h"
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 #include "commands.h"
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 #include "buffer.h"
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 #include "paths.h"
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 #include "process.h"
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 #ifdef VMS
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 extern noshare char **environ;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 #else
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 extern char **environ;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 #define max(a, b) ((a) > (b) ? (a) : (b))
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60
439
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
61 Lisp_Object Vexec_path, Vexec_directory, Vdata_directory;
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 Lisp_Object Vshell_file_name;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 Lisp_Object Vprocess_environment;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 /* True iff we are about to fork off a synchronous process or if we
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 are waiting for it. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 int synch_process_alive;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 /* Nonzero => this is a string explaining death of synchronous subprocess. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 char *synch_process_death;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 /* If synch_process_death is zero,
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 this is exit code of synchronous subprocess. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 int synch_process_retcode;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 #ifndef VMS /* VMS version is in vmsproc.c. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 Lisp_Object
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 call_process_cleanup (fdpid)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 Lisp_Object fdpid;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 register Lisp_Object fd, pid;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 fd = Fcar (fdpid);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 pid = Fcdr (fdpid);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 close (XFASTINT (fd));
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 kill (XFASTINT (pid), SIGKILL);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 synch_process_alive = 0;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 return Qnil;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 DEFUN ("call-process", Fcall_process, Scall_process, 1, MANY, 0,
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 "Call PROGRAM synchronously in separate process.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 The program's input comes from file INFILE (nil means `/dev/null').\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 Insert output in BUFFER before point; t means current buffer;\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 nil for BUFFER means discard it; 0 means discard and don't wait.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 Remaining arguments are strings passed as command arguments to PROGRAM.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 If BUFFER is nil or 0, returns immediately with value nil.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 Otherwise waits for PROGRAM to terminate\n\
760
012c1f6e9e7d *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 648
diff changeset
102 and returns a numeric exit status or a signal description string.\n\
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 If you quit, the process is killed with SIGKILL.")
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 (nargs, args)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 int nargs;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 register Lisp_Object *args;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 {
538
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
108 Lisp_Object display, infile, buffer, path, current_dir;
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 int fd[2];
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 int filefd;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 register int pid;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 char buf[1024];
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 int count = specpdl_ptr - specpdl;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 register unsigned char **new_argv
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 = (unsigned char **) alloca ((max (2, nargs - 2)) * sizeof (char *));
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 struct buffer *old = current_buffer;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 #if 0
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 int mask;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 CHECK_STRING (args[0], 0);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121
538
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
122 if (nargs >= 2 && ! NILP (args[1]))
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
123 {
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
124 infile = Fexpand_file_name (args[1], current_buffer->directory);
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
125 CHECK_STRING (infile, 1);
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
126 }
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 else
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
128 #ifdef VMS
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
129 infile = build_string ("NLA0:");
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
130 #else
538
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
131 infile = build_string ("/dev/null");
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
132 #endif /* not VMS */
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
133
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
134 if (nargs >= 3)
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
135 {
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
136 register Lisp_Object tem;
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
138 buffer = tem = args[2];
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
139 if (!(EQ (tem, Qnil)
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
140 || EQ (tem, Qt)
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
141 || XFASTINT (tem) == 0))
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
142 {
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
143 buffer = Fget_buffer (tem);
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
144 CHECK_BUFFER (buffer, 2);
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
145 }
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
146 }
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
147 else
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
148 buffer = Qnil;
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
150 display = nargs >= 4 ? args[3] : Qnil;
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 register int i;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 for (i = 4; i < nargs; i++)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 CHECK_STRING (args[i], i);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 new_argv[i - 3] = XSTRING (args[i])->data;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 /* Program name is first command arg */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 new_argv[0] = XSTRING (args[0])->data;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 new_argv[i - 3] = 0;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163
538
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
164 filefd = open (XSTRING (infile)->data, O_RDONLY, 0);
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 if (filefd < 0)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 {
538
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
167 report_file_error ("Opening process input file", Fcons (infile, Qnil));
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 /* Search for program; barf if not found. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 openp (Vexec_path, args[0], "", &path, 1);
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
171 if (NILP (path))
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 close (filefd);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 report_file_error ("Searching for program", Fcons (args[0], Qnil));
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 new_argv[0] = XSTRING (path)->data;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 if (XTYPE (buffer) == Lisp_Int)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 fd[1] = open ("/dev/null", O_WRONLY), fd[0] = -1;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 else
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 pipe (fd);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 #if 0
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 /* Replaced by close_process_descs */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 set_exclusive_use (fd[0]);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188
538
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
189 /* Make sure that the child will be able to chdir to the current
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
190 buffer's current directory. We can't just have the child check
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
191 for an error when it does the chdir, since it's in a vfork. */
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
192 current_dir = expand_and_dir_to_file (current_buffer->directory, Qnil);
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
193 if (NILP (Ffile_accessible_directory_p (current_dir)))
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
194 report_file_error ("Setting current directory",
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
195 Fcons (current_buffer->directory, Qnil));
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
196
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 /* child_setup must clobber environ in systems with true vfork.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 Protect it from permanent change. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 register char **save_environ = environ;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 register int fd1 = fd[1];
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 #if 0 /* Some systems don't have sigblock. */
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 624
diff changeset
204 mask = sigblock (sigmask (SIGCHLD));
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 /* Record that we're about to create a synchronous process. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 synch_process_alive = 1;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 pid = vfork ();
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 if (pid == 0)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 if (fd[0] >= 0)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 close (fd[0]);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 #ifdef USG
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 setpgrp ();
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 #else
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 setpgrp (pid, pid);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 #endif /* USG */
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 624
diff changeset
221 child_setup (filefd, fd1, fd1, new_argv, 0, current_dir);
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 #if 0
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 /* Tell SIGCHLD handler to look for this pid. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 synch_process_pid = pid;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 /* Now let SIGCHLD come through. */
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 624
diff changeset
228 sigsetmask (mask);
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 environ = save_environ;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 close (filefd);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 close (fd1);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 if (pid < 0)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 close (fd[0]);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 report_file_error ("Doing vfork", Qnil);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 if (XTYPE (buffer) == Lisp_Int)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 #ifndef subprocesses
585
1d71babec025 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 579
diff changeset
246 /* If Emacs has been built with asynchronous subprocess support,
1d71babec025 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 579
diff changeset
247 we don't need to do this, I think because it will then have
1d71babec025 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 579
diff changeset
248 the facilities for handling SIGCHLD. */
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 wait_without_blocking ();
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 #endif /* subprocesses */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 return Qnil;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253
545
3bf63e2cf890 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 538
diff changeset
254 synch_process_death = 0;
3bf63e2cf890 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 538
diff changeset
255 synch_process_retcode = 0;
3bf63e2cf890 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 538
diff changeset
256
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 record_unwind_protect (call_process_cleanup,
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 Fcons (make_number (fd[0]), make_number (pid)));
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 if (XTYPE (buffer) == Lisp_Buffer)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 Fset_buffer (buffer);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 immediate_quit = 1;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 QUIT;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 register int nread;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 while ((nread = read (fd[0], buf, sizeof buf)) > 0)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 immediate_quit = 0;
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
273 if (!NILP (buffer))
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 insert (buf, nread);
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
275 if (!NILP (display) && INTERACTIVE)
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 redisplay_preserve_echo_area ();
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 immediate_quit = 1;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 QUIT;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 /* Wait for it to terminate, unless it already has. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 wait_for_termination (pid);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 immediate_quit = 0;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 set_buffer_internal (old);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 unbind_to (count, Qnil);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 if (synch_process_death)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 return build_string (synch_process_death);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 return make_number (synch_process_retcode);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 static void
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 delete_temp_file (name)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 Lisp_Object name;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 unlink (XSTRING (name)->data);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 DEFUN ("call-process-region", Fcall_process_region, Scall_process_region,
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 3, MANY, 0,
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 "Send text from START to END to a synchronous process running PROGRAM.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 Delete the text if fourth arg DELETE is non-nil.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 Insert output in BUFFER before point; t means current buffer;\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 nil for BUFFER means discard it; 0 means discard and don't wait.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 Sixth arg DISPLAY non-nil means redisplay buffer as output is inserted.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 Remaining args are passed to PROGRAM at startup as command args.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 If BUFFER is nil, returns immediately with value nil.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 Otherwise waits for PROGRAM to terminate\n\
760
012c1f6e9e7d *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 648
diff changeset
314 and returns a numeric exit status or a signal description string.\n\
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 If you quit, the process is killed with SIGKILL.")
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 (nargs, args)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 int nargs;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 register Lisp_Object *args;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 register Lisp_Object filename_string, start, end;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 char tempfile[20];
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 int count = specpdl_ptr - specpdl;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 #ifdef VMS
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 strcpy (tempfile, "tmp:emacsXXXXXX.");
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 #else
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 strcpy (tempfile, "/tmp/emacsXXXXXX");
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 mktemp (tempfile);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 filename_string = build_string (tempfile);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 start = args[0];
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 end = args[1];
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 Fwrite_region (start, end, filename_string, Qnil, Qlambda);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 record_unwind_protect (delete_temp_file, filename_string);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
337 if (!NILP (args[3]))
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 Fdelete_region (start, end);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 args[3] = filename_string;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 Fcall_process (nargs - 2, args + 2);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 return unbind_to (count, Qnil);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 #ifndef VMS /* VMS version is in vmsproc.c. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348 /* This is the last thing run in a newly forked inferior
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 either synchronous or asynchronous.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 Copy descriptors IN, OUT and ERR as descriptors 0, 1 and 2.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 Initialize inferior's priority, pgrp, connected dir and environment.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 then exec another program based on new_argv.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 This function may change environ for the superior process.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 Therefore, the superior process must save and restore the value
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 of environ around the vfork and the call to this function.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 ENV is the environment for the subprocess.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 SET_PGRP is nonzero if we should put the subprocess into a separate
538
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
361 process group.
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362
538
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
363 CURRENT_DIR is an elisp string giving the path of the current
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
364 directory the subprocess should have. Since we can't really signal
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
365 a decent error from within the child, this should be verified as an
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
366 executable directory by the parent. */
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
367
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 624
diff changeset
368 child_setup (in, out, err, new_argv, set_pgrp, current_dir)
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 int in, out, err;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 register char **new_argv;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 int set_pgrp;
538
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
372 Lisp_Object current_dir;
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 {
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 624
diff changeset
374 char **env;
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 624
diff changeset
375
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 register int pid = getpid();
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 setpriority (PRIO_PROCESS, pid, 0);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 #ifdef subprocesses
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 /* Close Emacs's descriptors that this process should not have. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382 close_process_descs ();
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 /* Note that use of alloca is always safe here. It's obvious for systems
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 that do not have true vfork or that have true (stack) alloca.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 If using vfork and C_ALLOCA it is safe because that changes
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 the superior's static variables as if the superior had done alloca
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389 and will be cleaned up in the usual way. */
538
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
390 {
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
391 register unsigned char *temp;
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
392 register int i;
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393
538
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
394 i = XSTRING (current_dir)->size;
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
395 temp = (unsigned char *) alloca (i + 2);
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
396 bcopy (XSTRING (current_dir)->data, temp, i);
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
397 if (temp[i - 1] != '/') temp[i++] = '/';
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
398 temp[i] = 0;
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
399
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
400 /* We can't signal an Elisp error here; we're in a vfork. Since
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
401 the callers check the current directory before forking, this
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
402 should only return an error if the directory's permissions
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
403 are changed between the check and this chdir, but we should
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
404 at least check. */
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
405 if (chdir (temp) < 0)
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
406 exit (errno);
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
407 }
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 /* Set `env' to a vector of the strings in Vprocess_environment. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 register Lisp_Object tem;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412 register char **new_env;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 register int new_length;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 new_length = 0;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416 for (tem = Vprocess_environment;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 (XTYPE (tem) == Lisp_Cons
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 && XTYPE (XCONS (tem)->car) == Lisp_String);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419 tem = XCONS (tem)->cdr)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 new_length++;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 /* new_length + 1 to include terminating 0 */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423 env = new_env = (char **) alloca ((new_length + 1) * sizeof (char *));
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 624
diff changeset
425 /* Copy the Vprocess_alist strings into new_env. */
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426 for (tem = Vprocess_environment;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 (XTYPE (tem) == Lisp_Cons
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428 && XTYPE (XCONS (tem)->car) == Lisp_String);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 tem = XCONS (tem)->cdr)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430 *new_env++ = (char *) XSTRING (XCONS (tem)->car)->data;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 *new_env = 0;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434 close (0);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
435 close (1);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436 close (2);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438 dup2 (in, 0);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 dup2 (out, 1);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 dup2 (err, 2);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441 close (in);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442 close (out);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443 close (err);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444
579
e2782df984a2 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 545
diff changeset
445 #ifdef USG
e2782df984a2 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 545
diff changeset
446 setpgrp (); /* No arguments but equivalent in this case */
e2782df984a2 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 545
diff changeset
447 #else
e2782df984a2 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 545
diff changeset
448 setpgrp (pid, pid);
e2782df984a2 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 545
diff changeset
449 #endif /* USG */
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450 setpgrp_of_tty (pid);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 #ifdef vipc
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 something missing here;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454 #endif /* vipc */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456 /* execvp does not accept an environment arg so the only way
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457 to pass this environment is to set environ. Our caller
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458 is responsible for restoring the ambient value of environ. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 environ = env;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460 execvp (new_argv[0], new_argv);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462 write (1, "Couldn't exec the program ", 26);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463 write (1, new_argv[0], strlen (new_argv[0]));
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
464 _exit (1);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
467 static int
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
468 getenv_internal (var, varlen, value, valuelen)
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
469 char *var;
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
470 int varlen;
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
471 char **value;
538
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
472 int *valuelen;
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
473 {
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
474 Lisp_Object scan;
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
475
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
476 for (scan = Vprocess_environment; CONSP (scan); scan = XCONS (scan)->cdr)
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
477 {
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
478 Lisp_Object entry = XCONS (scan)->car;
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
479
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
480 if (XTYPE (entry) == Lisp_String
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
481 && XSTRING (entry)->size > varlen
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
482 && XSTRING (entry)->data[varlen] == '='
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
483 && ! bcmp (XSTRING (entry)->data, var, varlen))
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
484 {
538
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
485 *value = (char *) XSTRING (entry)->data + (varlen + 1);
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
486 *valuelen = XSTRING (entry)->size - (varlen + 1);
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
487 return 1;
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
488 }
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
489 }
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
490
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
491 return 0;
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
492 }
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
494 DEFUN ("getenv", Fgetenv, Sgetenv, 1, 2, 0,
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
495 "Return the value of environment variable VAR, as a string.\n\
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
496 VAR should be a string. Value is nil if VAR is undefined in the environment.\n\
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
497 This function consults the variable ``process-environment'' for its value.")
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
498 (var)
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
499 Lisp_Object var;
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
500 {
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
501 char *value;
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
502 int valuelen;
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
503
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
504 CHECK_STRING (var, 0);
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
505 if (getenv_internal (XSTRING (var)->data, XSTRING (var)->size,
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
506 &value, &valuelen))
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
507 return make_string (value, valuelen);
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
508 else
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
509 return Qnil;
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
510 }
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
511
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
512 /* A version of getenv that consults process_environment, easily
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
513 callable from C. */
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
514 char *
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
515 egetenv (var)
621
eca8812e61cd *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 585
diff changeset
516 char *var;
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
517 {
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
518 char *value;
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
519 int valuelen;
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
520
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
521 if (getenv_internal (var, strlen (var), &value, &valuelen))
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
522 return value;
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
523 else
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
524 return 0;
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
525 }
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
526
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
527 #endif /* not VMS */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
528
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
529 init_callproc ()
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
530 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
531 register char * sh;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
532 register char **envp;
439
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
533 Lisp_Object tempdir;
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
534
624
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
535 {
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
536 char *data_dir = egetenv ("EMACSDATA");
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
537
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
538 Vdata_directory =
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
539 Ffile_name_as_directory
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
540 (build_string (data_dir ? data_dir : PATH_DATA));
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
541 }
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
542
624
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
543 /* Check the EMACSPATH environment variable, defaulting to the
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
544 PATH_EXEC path from paths.h. */
2bb7f23b7ea5 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 621
diff changeset
545 Vexec_path = decode_env_path ("EMACSPATH", PATH_EXEC);
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
546 Vexec_directory = Ffile_name_as_directory (Fcar (Vexec_path));
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
547 Vexec_path = nconc2 (decode_env_path ("PATH", ""), Vexec_path);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
548
439
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
549 tempdir = Fdirectory_file_name (Vexec_directory);
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
550 if (access (XSTRING (tempdir)->data, 0) < 0)
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
551 {
439
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
552 printf ("Warning: arch-dependent data dir (%s) does not exist.\n",
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
553 XSTRING (Vexec_directory)->data);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
554 sleep (2);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
555 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
556
439
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
557 tempdir = Fdirectory_file_name (Vdata_directory);
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
558 if (access (XSTRING (tempdir)->data, 0) < 0)
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
559 {
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
560 printf ("Warning: arch-independent data dir (%s) does not exist.\n",
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
561 XSTRING (Vdata_directory)->data);
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
562 sleep (2);
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
563 }
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
564
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
565 #ifdef VMS
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
566 Vshell_file_name = build_string ("*dcl*");
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
567 #else
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
568 sh = (char *) getenv ("SHELL");
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
569 Vshell_file_name = build_string (sh ? sh : "/bin/sh");
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
570 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
571
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
572 Vprocess_environment = Qnil;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
573 #ifndef CANNOT_DUMP
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
574 if (initialized)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
575 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
576 for (envp = environ; *envp; envp++)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
577 Vprocess_environment = Fcons (build_string (*envp),
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
578 Vprocess_environment);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
579 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
580
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
581 syms_of_callproc ()
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
582 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
583 DEFVAR_LISP ("shell-file-name", &Vshell_file_name,
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
584 "*File name to load inferior shells from.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
585 Initialized from the SHELL environment variable.");
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
586
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
587 DEFVAR_LISP ("exec-path", &Vexec_path,
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
588 "*List of directories to search programs to run in subprocesses.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
589 Each element is a string (directory name) or nil (try default directory).");
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
590
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
591 DEFVAR_LISP ("exec-directory", &Vexec_directory,
439
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
592 "Directory of architecture-dependent files that come with GNU Emacs,\n\
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
593 especially executable programs intended for Emacs to invoke.");
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
594
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
595 DEFVAR_LISP ("data-directory", &Vdata_directory,
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
596 "Directory of architecture-independent files that come with GNU Emacs,\n\
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
597 intended for Emacs to use.");
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
598
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
599 DEFVAR_LISP ("process-environment", &Vprocess_environment,
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
600 "List of environment variables for subprocesses to inherit.\n\
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
601 Each element should be a string of the form ENVVARNAME=VALUE.\n\
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
602 The environment which Emacs inherits is placed in this variable\n\
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
603 when Emacs starts.");
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
604
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
605 #ifndef VMS
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
606 defsubr (&Scall_process);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
607 #endif
493
8b101799ff37 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 439
diff changeset
608 defsubr (&Sgetenv);
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
609 defsubr (&Scall_process_region);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
610 }