annotate src/callproc.c @ 1587:57ae5625fe22

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