annotate src/callproc.c @ 2780:cfe7659bbc05

* lisp.h (Lisp_Overlay): New tag. (OVERLAYP): New predicate. (CHECK_OVERLAY): New type-checker. (Qoverlayp): New extern declaration. * buffer.c (Foverlayp): New function. (Qoverlayp): New atom. (overlays_at, recenter_overlay_lists): Abort if we encounter an invalid overlay. (syms_of_buffer): defsubr Soverlayp; initialize Qoverlayp. (Fdelete_overlay): Set the overlay's markers to point nowhere. Use CHECK_OVERLAY instead of signalling a special error. (Fmove_overlay, Foverlay_put): Use CHECK_OVERLAY instead of signalling a special error. (Foverlay_get): Use CHECK_OVERLAY. * fns.c (internal_equal): Define this for overlays. * buffer.h (OVERLAY_VALID): Define in terms of OVERLAYP. * print.c (print): Give overlays their own print syntax. * alloc.c (mark_object): Treat overlays like conses. * lisp.h (FLOATP): Define this appropriately when LISP_FLOAT_TYPE is not defined.
author Jim Blandy <jimb@redhat.com>
date Fri, 14 May 1993 14:41:36 +0000
parents a3ee51f30431
children e94a593c3952
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
2286
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
26 extern int errno;
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
27 #ifndef VMS
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
28 extern char *sys_errlist[];
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
29 #endif
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
30
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 /* Define SIGCHLD as an alias for SIGCLD. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 #if !defined (SIGCHLD) && defined (SIGCLD)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 #define SIGCHLD SIGCLD
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 #endif /* SIGCLD */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 #include <sys/types.h>
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 #define PRIO_PROCESS 0
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 #include <sys/file.h>
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 #ifdef USG5
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 #include <fcntl.h>
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 #ifndef O_RDONLY
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 #define O_RDONLY 0
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 #ifndef O_WRONLY
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 #define O_WRONLY 1
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 #include "lisp.h"
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 #include "commands.h"
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 #include "buffer.h"
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 #include "paths.h"
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 #include "process.h"
1504
e074a2236b00 * callproc.c: Arrange for synchronous processes to get SIGINT the
Jim Blandy <jimb@redhat.com>
parents: 1201
diff changeset
57 #include "syssignal.h"
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 #ifdef VMS
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 extern noshare char **environ;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 #else
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 extern char **environ;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 #define max(a, b) ((a) > (b) ? (a) : (b))
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66
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
67 Lisp_Object Vexec_path, Vexec_directory, Vdata_directory;
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 Lisp_Object Vshell_file_name;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 Lisp_Object Vprocess_environment;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 /* 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
74 are waiting for it. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 int synch_process_alive;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 /* Nonzero => this is a string explaining death of synchronous subprocess. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 char *synch_process_death;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 /* If synch_process_death is zero,
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 this is exit code of synchronous subprocess. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 int synch_process_retcode;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 #ifndef VMS /* VMS version is in vmsproc.c. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85
1504
e074a2236b00 * callproc.c: Arrange for synchronous processes to get SIGINT the
Jim Blandy <jimb@redhat.com>
parents: 1201
diff changeset
86 static Lisp_Object
e074a2236b00 * callproc.c: Arrange for synchronous processes to get SIGINT the
Jim Blandy <jimb@redhat.com>
parents: 1201
diff changeset
87 call_process_kill (fdpid)
e074a2236b00 * callproc.c: Arrange for synchronous processes to get SIGINT the
Jim Blandy <jimb@redhat.com>
parents: 1201
diff changeset
88 Lisp_Object fdpid;
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 close (XFASTINT (Fcar (fdpid)));
e074a2236b00 * callproc.c: Arrange for synchronous processes to get SIGINT the
Jim Blandy <jimb@redhat.com>
parents: 1201
diff changeset
91 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
92 synch_process_alive = 0;
e074a2236b00 * callproc.c: Arrange for synchronous processes to get SIGINT the
Jim Blandy <jimb@redhat.com>
parents: 1201
diff changeset
93 return Qnil;
e074a2236b00 * callproc.c: Arrange for synchronous processes to get SIGINT the
Jim Blandy <jimb@redhat.com>
parents: 1201
diff changeset
94 }
e074a2236b00 * callproc.c: Arrange for synchronous processes to get SIGINT the
Jim Blandy <jimb@redhat.com>
parents: 1201
diff changeset
95
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 Lisp_Object
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 call_process_cleanup (fdpid)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 Lisp_Object fdpid;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 {
1504
e074a2236b00 * callproc.c: Arrange for synchronous processes to get SIGINT the
Jim Blandy <jimb@redhat.com>
parents: 1201
diff changeset
100 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
101
e074a2236b00 * callproc.c: Arrange for synchronous processes to get SIGINT the
Jim Blandy <jimb@redhat.com>
parents: 1201
diff changeset
102 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
103 {
e074a2236b00 * callproc.c: Arrange for synchronous processes to get SIGINT the
Jim Blandy <jimb@redhat.com>
parents: 1201
diff changeset
104 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
105 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
106 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
107 immediate_quit = 1;
e074a2236b00 * callproc.c: Arrange for synchronous processes to get SIGINT the
Jim Blandy <jimb@redhat.com>
parents: 1201
diff changeset
108 QUIT;
e074a2236b00 * callproc.c: Arrange for synchronous processes to get SIGINT the
Jim Blandy <jimb@redhat.com>
parents: 1201
diff changeset
109 wait_for_termination (pid);
e074a2236b00 * callproc.c: Arrange for synchronous processes to get SIGINT the
Jim Blandy <jimb@redhat.com>
parents: 1201
diff changeset
110 immediate_quit = 0;
e074a2236b00 * callproc.c: Arrange for synchronous processes to get SIGINT the
Jim Blandy <jimb@redhat.com>
parents: 1201
diff changeset
111 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
112 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
113 }
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 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
115 close (XFASTINT (Fcar (fdpid)));
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 return Qnil;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 DEFUN ("call-process", Fcall_process, Scall_process, 1, MANY, 0,
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 "Call PROGRAM synchronously in separate process.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 The program's input comes from file INFILE (nil means `/dev/null').\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 Insert output in BUFFER before point; t means current buffer;\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 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
124 Fourth arg DISPLAY non-nil means redisplay buffer as output is inserted.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 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
126 If BUFFER is 0, returns immediately with value nil.\n\
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 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
128 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
129 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
130 (nargs, args)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 int nargs;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 register Lisp_Object *args;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 {
1678
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
134 Lisp_Object infile, buffer, current_dir, display, path;
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 int fd[2];
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 int filefd;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 register int pid;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 char buf[1024];
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 int count = specpdl_ptr - specpdl;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 register unsigned char **new_argv
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 = (unsigned char **) alloca ((max (2, nargs - 2)) * sizeof (char *));
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 struct buffer *old = current_buffer;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 #if 0
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 int mask;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 CHECK_STRING (args[0], 0);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147
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
148 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
149 {
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 = 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
151 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
152 }
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 else
2432
17a84e60603b New macros NULL_DEVICE and EXEC_SUFFIXES, to give the name of the
Jim Blandy <jimb@redhat.com>
parents: 2286
diff changeset
154 infile = build_string (NULL_DEVICE);
648
70b112526394 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 638
diff changeset
155
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
156 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
157 {
928ed74adf4f Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
parents: 942
diff changeset
158 register Lisp_Object tem;
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159
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
160 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
161 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
162 || 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
163 || 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
164 {
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 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
166 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
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 }
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 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
170 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
171
1678
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
172 /* Make sure that the child will be able to chdir to the current
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
173 buffer's current directory, or its unhandled equivalent. We
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
174 can't just have the child check for an error when it does the
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
175 chdir, since it's in a vfork.
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
176
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
177 We have to GCPRO around this because Fexpand_file_name,
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
178 Funhandled_file_name_directory, and Ffile_accessible_directory_p
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
179 might call a file name handling function. The argument list is
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
180 protected by the caller, so all we really have to worry about is
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
181 buffer. */
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
182 {
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
183 struct gcpro gcpro1, gcpro2, gcpro3;
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
184
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
185 current_dir = current_buffer->directory;
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
186
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
187 GCPRO3 (infile, buffer, current_dir);
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
188
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
189 current_dir =
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
190 expand_and_dir_to_file
1886
dd2e31cbf205 * process.c (Fstart_process): Jimb's change of December 11
Michael I. Bushnell <mib@gnu.org>
parents: 1678
diff changeset
191 (Funhandled_file_name_directory (current_dir), Qnil);
1678
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
192 if (NILP (Ffile_accessible_directory_p (current_dir)))
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
193 report_file_error ("Setting current directory",
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
194 Fcons (current_buffer->directory, Qnil));
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
195
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
196 UNGCPRO;
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
197 }
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
198
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
199 display = nargs >= 4 ? args[3] : Qnil;
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 register int i;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 for (i = 4; i < nargs; i++)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 CHECK_STRING (args[i], i);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 new_argv[i - 3] = XSTRING (args[i])->data;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 /* Program name is first command arg */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 new_argv[0] = XSTRING (args[0])->data;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 new_argv[i - 3] = 0;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212
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
213 filefd = open (XSTRING (infile)->data, O_RDONLY, 0);
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 if (filefd < 0)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 {
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
216 report_file_error ("Opening process input file", Fcons (infile, Qnil));
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 /* Search for program; barf if not found. */
2432
17a84e60603b New macros NULL_DEVICE and EXEC_SUFFIXES, to give the name of the
Jim Blandy <jimb@redhat.com>
parents: 2286
diff changeset
219 openp (Vexec_path, args[0], EXEC_SUFFIXES, &path, 1);
942
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
220 if (NILP (path))
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 close (filefd);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 report_file_error ("Searching for program", Fcons (args[0], Qnil));
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 new_argv[0] = XSTRING (path)->data;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 if (XTYPE (buffer) == Lisp_Int)
2432
17a84e60603b New macros NULL_DEVICE and EXEC_SUFFIXES, to give the name of the
Jim Blandy <jimb@redhat.com>
parents: 2286
diff changeset
228 fd[1] = open (NULL_DEVICE, O_WRONLY), fd[0] = -1;
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 else
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 pipe (fd);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 #if 0
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 /* Replaced by close_process_descs */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 set_exclusive_use (fd[0]);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 /* child_setup must clobber environ in systems with true vfork.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 Protect it from permanent change. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 register char **save_environ = environ;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 register int fd1 = fd[1];
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 #if 0 /* Some systems don't have sigblock. */
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 624
diff changeset
245 mask = sigblock (sigmask (SIGCHLD));
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 /* Record that we're about to create a synchronous process. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 synch_process_alive = 1;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 pid = vfork ();
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 if (pid == 0)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 if (fd[0] >= 0)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 close (fd[0]);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 #ifdef USG
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 setpgrp ();
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 #else
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 setpgrp (pid, pid);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 #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
262 child_setup (filefd, fd1, fd1, new_argv, 0, current_dir);
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 #if 0
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 /* Tell SIGCHLD handler to look for this pid. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 synch_process_pid = pid;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 /* Now let SIGCHLD come through. */
638
40b255f55df3 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 624
diff changeset
269 sigsetmask (mask);
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 environ = save_environ;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 close (filefd);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 close (fd1);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 if (pid < 0)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 close (fd[0]);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 report_file_error ("Doing vfork", Qnil);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 if (XTYPE (buffer) == Lisp_Int)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 #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
287 /* 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
288 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
289 the facilities for handling SIGCHLD. */
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 wait_without_blocking ();
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 #endif /* subprocesses */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 return Qnil;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294
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
295 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
296 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
297
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 record_unwind_protect (call_process_cleanup,
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 Fcons (make_number (fd[0]), make_number (pid)));
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 if (XTYPE (buffer) == Lisp_Buffer)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 Fset_buffer (buffer);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 immediate_quit = 1;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 QUIT;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 register int nread;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 while ((nread = read (fd[0], buf, sizeof buf)) > 0)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 immediate_quit = 0;
942
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
314 if (!NILP (buffer))
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 insert (buf, nread);
942
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
316 if (!NILP (display) && INTERACTIVE)
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 redisplay_preserve_echo_area ();
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 immediate_quit = 1;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 QUIT;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323 /* Wait for it to terminate, unless it already has. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 wait_for_termination (pid);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 immediate_quit = 0;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 set_buffer_internal (old);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 unbind_to (count, Qnil);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 if (synch_process_death)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 return build_string (synch_process_death);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 return make_number (synch_process_retcode);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337
1912
f0d4fb2b9157 * callproc.c (delete_temp_file): Declare this to return
Jim Blandy <jimb@redhat.com>
parents: 1886
diff changeset
338 static Lisp_Object
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 delete_temp_file (name)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 Lisp_Object name;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 unlink (XSTRING (name)->data);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 DEFUN ("call-process-region", Fcall_process_region, Scall_process_region,
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 3, MANY, 0,
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 "Send text from START to END to a synchronous process running PROGRAM.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348 Delete the text if fourth arg DELETE is non-nil.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 Insert output in BUFFER before point; t means current buffer;\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 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
351 Sixth arg DISPLAY non-nil means redisplay buffer as output is inserted.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 Remaining args are passed to PROGRAM at startup as command args.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353 If BUFFER is nil, returns immediately with value nil.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 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
355 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
356 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
357 (nargs, args)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 int nargs;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359 register Lisp_Object *args;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 register Lisp_Object filename_string, start, end;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 char tempfile[20];
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 int count = specpdl_ptr - specpdl;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 #ifdef VMS
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 strcpy (tempfile, "tmp:emacsXXXXXX.");
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 #else
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 strcpy (tempfile, "/tmp/emacsXXXXXX");
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 mktemp (tempfile);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 filename_string = build_string (tempfile);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 start = args[0];
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 end = args[1];
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 Fwrite_region (start, end, filename_string, Qnil, Qlambda);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 record_unwind_protect (delete_temp_file, filename_string);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377
942
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
378 if (!NILP (args[3]))
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 Fdelete_region (start, end);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 args[3] = filename_string;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382
1678
62ecf0c5b54c Give subprocess creation a way to find a valid current directory
Jim Blandy <jimb@redhat.com>
parents: 1596
diff changeset
383 return unbind_to (count, Fcall_process (nargs - 2, args + 2));
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 #ifndef VMS /* VMS version is in vmsproc.c. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 /* This is the last thing run in a newly forked inferior
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389 either synchronous or asynchronous.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 Copy descriptors IN, OUT and ERR as descriptors 0, 1 and 2.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 Initialize inferior's priority, pgrp, connected dir and environment.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 then exec another program based on new_argv.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 This function may change environ for the superior process.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 Therefore, the superior process must save and restore the value
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396 of environ around the vfork and the call to this function.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 ENV is the environment for the subprocess.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 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
401 process group.
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402
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
403 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
404 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
405 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
406 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
407
928ed74adf4f Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
parents: 942
diff changeset
408 child_setup (in, out, err, new_argv, set_pgrp, current_dir)
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 int in, out, err;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410 register char **new_argv;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 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
412 Lisp_Object current_dir;
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 {
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
414 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
415
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416 register int pid = getpid();
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417
1201
4ea86d32c012 * callproc.c (child_setup): Don't use setpriority; we just need a
Jim Blandy <jimb@redhat.com>
parents: 948
diff changeset
418 {
4ea86d32c012 * callproc.c (child_setup): Don't use setpriority; we just need a
Jim Blandy <jimb@redhat.com>
parents: 948
diff changeset
419 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
420
4ea86d32c012 * callproc.c (child_setup): Don't use setpriority; we just need a
Jim Blandy <jimb@redhat.com>
parents: 948
diff changeset
421 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
422 }
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 #ifdef subprocesses
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425 /* Close Emacs's descriptors that this process should not have. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426 close_process_descs ();
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 /* 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
430 that do not have true vfork or that have true (stack) alloca.
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 If using vfork and C_ALLOCA it is safe because that changes
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 the superior's static variables as if the superior had done alloca
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 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
434 {
928ed74adf4f Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
parents: 942
diff changeset
435 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
436 register int i;
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437
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
438 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
439 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
440 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
441 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
442 temp[i] = 0;
538
c3e1fe268e78 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 493
diff changeset
443
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
444 /* 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
445 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
446 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
447 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
448 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
449 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
450 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
451 }
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 /* Set `env' to a vector of the strings in Vprocess_environment. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455 register Lisp_Object tem;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456 register char **new_env;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457 register int new_length;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 new_length = 0;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460 for (tem = Vprocess_environment;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461 (XTYPE (tem) == Lisp_Cons
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462 && XTYPE (XCONS (tem)->car) == Lisp_String);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463 tem = XCONS (tem)->cdr)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
464 new_length++;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465
2757
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
466 /* new_length + 1 to include terminating 0. */
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467 env = new_env = (char **) alloca ((new_length + 1) * sizeof (char *));
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468
2757
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
469 /* Copy the Vprocess_environment strings into new_env. */
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470 for (tem = Vprocess_environment;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 (XTYPE (tem) == Lisp_Cons
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472 && XTYPE (XCONS (tem)->car) == Lisp_String);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473 tem = XCONS (tem)->cdr)
2757
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
474 {
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
475 char **ep = env;
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
476 char *string = (char *) XSTRING (XCONS (tem)->car)->data;
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
477 /* See if this string duplicates any string already in the env.
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
478 If so, don't put it in.
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
479 When an env var has multiple definitions,
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
480 we keep the definition that comes first in process-environment. */
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
481 for (; ep != new_env; ep++)
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
482 {
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
483 char *p = *ep, *q = string;
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
484 while (1)
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
485 {
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
486 if (*q == 0)
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
487 /* The string is malformed; might as well drop it. */
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
488 goto duplicate;
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
489 if (*q != *p)
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
490 break;
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
491 if (*q == '=')
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
492 goto duplicate;
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
493 p++, q++;
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
494 }
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
495 }
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
496 *new_env++ = string;
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
497 duplicate: ;
a3ee51f30431 (child_setup): Omit duplicates from new env array.
Richard M. Stallman <rms@gnu.org>
parents: 2509
diff changeset
498 }
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
499 *new_env = 0;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
500 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
501
2286
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
502 /* Make sure that in, out, and err are not actually already in
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
503 descriptors zero, one, or two; this could happen if Emacs is
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
504 started with its standard in, our, or error closed, as might
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
505 happen under X. */
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
506 in = relocate_fd (in, 3);
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
507 out = relocate_fd (out, 3);
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
508 err = relocate_fd (err, 3);
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
509
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
510 close (0);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
511 close (1);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512 close (2);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
513
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
514 dup2 (in, 0);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
515 dup2 (out, 1);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
516 dup2 (err, 2);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
517 close (in);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
518 close (out);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
519 close (err);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
520
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
521 #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
522 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
523 #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
524 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
525 #endif /* USG */
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
526 setpgrp_of_tty (pid);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
527
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
528 #ifdef vipc
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
529 something missing here;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
530 #endif /* vipc */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
531
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
532 /* execvp does not accept an environment arg so the only way
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
533 to pass this environment is to set environ. Our caller
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
534 is responsible for restoring the ambient value of environ. */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
535 environ = env;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
536 execvp (new_argv[0], new_argv);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
537
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
538 write (1, "Couldn't exec the program ", 26);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
539 write (1, new_argv[0], strlen (new_argv[0]));
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
540 _exit (1);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
541 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
542
2286
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
543 /* Move the file descriptor FD so that its number is not less than MIN.
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
544 If the file descriptor is moved at all, the original is freed. */
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
545 int
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
546 relocate_fd (fd, min)
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
547 int fd, min;
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
548 {
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
549 if (fd >= min)
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
550 return fd;
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
551 else
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
552 {
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
553 int new = dup (fd);
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
554 if (new == -1)
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
555 {
2509
daaa78c8c980 * callproc.c (relocate_fd): Make messages string literals, not
Jim Blandy <jimb@redhat.com>
parents: 2432
diff changeset
556 char *message1 = "Error while setting up child: ";
daaa78c8c980 * callproc.c (relocate_fd): Make messages string literals, not
Jim Blandy <jimb@redhat.com>
parents: 2432
diff changeset
557 char *message2 = "\n";
daaa78c8c980 * callproc.c (relocate_fd): Make messages string literals, not
Jim Blandy <jimb@redhat.com>
parents: 2432
diff changeset
558 write (2, message1, strlen (message1));
2286
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
559 write (2, sys_errlist[errno], strlen (sys_errlist[errno]));
2509
daaa78c8c980 * callproc.c (relocate_fd): Make messages string literals, not
Jim Blandy <jimb@redhat.com>
parents: 2432
diff changeset
560 write (2, message2, strlen (message2));
2286
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
561 _exit (1);
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
562 }
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
563 /* Note that we hold the original FD open while we recurse,
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
564 to guarantee we'll get a new FD if we need it. */
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
565 new = relocate_fd (new, min);
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
566 close (fd);
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
567 return new;
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
568 }
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
569 }
7f66b40a0192 * callproc.c (child_setup): Make sure that in, out, and err are
Jim Blandy <jimb@redhat.com>
parents: 1912
diff changeset
570
942
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
571 static int
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
572 getenv_internal (var, varlen, value, valuelen)
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
573 char *var;
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
574 int varlen;
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
575 char **value;
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
576 int *valuelen;
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
577 {
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
578 Lisp_Object scan;
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
579
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
580 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
581 {
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
582 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
583
942
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
584 if (XTYPE (entry) == Lisp_String
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
585 && XSTRING (entry)->size > varlen
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
586 && XSTRING (entry)->data[varlen] == '='
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
587 && ! bcmp (XSTRING (entry)->data, var, varlen))
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
588 {
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
589 *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
590 *valuelen = XSTRING (entry)->size - (varlen + 1);
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
591 return 1;
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
592 }
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
593 }
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
594
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
595 return 0;
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
596 }
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
597
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
598 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
599 "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
600 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
601 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
602 (var)
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
603 Lisp_Object var;
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
604 {
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
605 char *value;
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
606 int valuelen;
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
607
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
608 CHECK_STRING (var, 0);
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
609 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
610 &value, &valuelen))
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
611 return make_string (value, valuelen);
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
612 else
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
613 return Qnil;
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
614 }
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
615
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
616 /* 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
617 callable from C. */
942
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
618 char *
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
619 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
620 char *var;
942
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
621 {
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
622 char *value;
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
623 int valuelen;
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
624
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
625 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
626 return value;
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
627 else
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
628 return 0;
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
629 }
c519b70eb50b Replaced fuctions egetenv, Fgetenv, getenv_internal, which had
Joseph Arceneaux <jla@gnu.org>
parents: 934
diff changeset
630
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
631 #endif /* not VMS */
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
632
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
633 init_callproc ()
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
634 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
635 register char * sh;
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
636 Lisp_Object tempdir;
439
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
637
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
638 {
928ed74adf4f Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
parents: 942
diff changeset
639 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
640
928ed74adf4f Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
parents: 942
diff changeset
641 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
642 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
643 (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
644 }
928ed74adf4f Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
parents: 942
diff changeset
645
928ed74adf4f Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
parents: 942
diff changeset
646 /* 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
647 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
648 Vexec_path = decode_env_path ("EMACSPATH", PATH_EXEC);
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
649 Vexec_directory = Ffile_name_as_directory (Fcar (Vexec_path));
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
650 Vexec_path = nconc2 (decode_env_path ("PATH", ""), Vexec_path);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
651
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
652 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
653 if (access (XSTRING (tempdir)->data, 0) < 0)
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
654 {
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
655 printf ("Warning: arch-dependent data dir (%s) does not exist.\n",
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
656 XSTRING (Vexec_directory)->data);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
657 sleep (2);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
658 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
659
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
660 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
661 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
662 {
928ed74adf4f Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
parents: 942
diff changeset
663 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
664 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
665 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
666 }
928ed74adf4f Restored up-to-date version of this file from pogo. What is going on
Jim Blandy <jimb@redhat.com>
parents: 942
diff changeset
667
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
668 #ifdef VMS
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
669 Vshell_file_name = build_string ("*dcl*");
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
670 #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
671 sh = (char *) getenv ("SHELL");
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
672 Vshell_file_name = build_string (sh ? sh : "/bin/sh");
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
673 #endif
1912
f0d4fb2b9157 * callproc.c (delete_temp_file): Declare this to return
Jim Blandy <jimb@redhat.com>
parents: 1886
diff changeset
674 }
f0d4fb2b9157 * callproc.c (delete_temp_file): Declare this to return
Jim Blandy <jimb@redhat.com>
parents: 1886
diff changeset
675
f0d4fb2b9157 * callproc.c (delete_temp_file): Declare this to return
Jim Blandy <jimb@redhat.com>
parents: 1886
diff changeset
676 set_process_environment ()
f0d4fb2b9157 * callproc.c (delete_temp_file): Declare this to return
Jim Blandy <jimb@redhat.com>
parents: 1886
diff changeset
677 {
f0d4fb2b9157 * callproc.c (delete_temp_file): Declare this to return
Jim Blandy <jimb@redhat.com>
parents: 1886
diff changeset
678 register char **envp;
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
679
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
680 Vprocess_environment = Qnil;
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
681 #ifndef CANNOT_DUMP
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
682 if (initialized)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
683 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
684 for (envp = environ; *envp; envp++)
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
685 Vprocess_environment = Fcons (build_string (*envp),
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
686 Vprocess_environment);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
687 }
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
688
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
689 syms_of_callproc ()
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
690 {
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
691 DEFVAR_LISP ("shell-file-name", &Vshell_file_name,
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
692 "*File name to load inferior shells from.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
693 Initialized from the SHELL environment variable.");
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
694
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
695 DEFVAR_LISP ("exec-path", &Vexec_path,
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
696 "*List of directories to search programs to run in subprocesses.\n\
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
697 Each element is a string (directory name) or nil (try default directory).");
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
698
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
699 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
700 "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
701 especially executable programs intended for Emacs to invoke.");
439
350065270fc8 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 311
diff changeset
702
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
703 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
704 "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
705 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
706
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
707 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
708 "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
709 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
710 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
711 when Emacs starts.");
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
712
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
713 #ifndef VMS
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
714 defsubr (&Scall_process);
1596
0e105bd23f44 * systty.h, process.c, buffer.h, callproc.c, sysdep.c, dired.c:
Jim Blandy <jimb@redhat.com>
parents: 1504
diff changeset
715 defsubr (&Sgetenv);
296
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
716 #endif
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
717 defsubr (&Scall_process_region);
558b874b5259 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
718 }