annotate src/process.c @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children 0293115a14e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* Asynchronous subprocess control for XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1987, 1988, 1992, 1993, 1994, 1995
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 Copyright (C) 1995 Sun Microsystems, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 Copyright (C) 1995, 1996 Ben Wing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 /* Synched up with: Mule 2.0, FSF 19.30. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 /* This file has been Mule-ized except for `start-process-internal'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 and `open-network-stream-internal'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 #if !defined (NO_SUBPROCESSES)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 /* The entire file is within this conditional */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 #include "commands.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 #include "events.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #include "frame.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #include "insdel.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #include "lstream.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 #include "opaque.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #include "process.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 #include "sysdep.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 #include "window.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 #include <setjmp.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 #include "sysfile.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #include "sysproc.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 #include "systime.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 #include "syssignal.h" /* Always include before systty.h */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 #include "systty.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 #include "syswait.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 /* a process object is a network connection when its pid field a cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (name of name of port we are connected to . foreign host name) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 /* Valid values of process->status_symbol */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 Lisp_Object Qrun, Qstop; /* Qexit from eval.c, Qsignal from data.c. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 /* Qrun => Qopen, Qexit => Qclosed for "network connection" processes */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 Lisp_Object Qopen, Qclosed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 /* t means use pty, nil means use a pipe,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 maybe other values to come. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 static Lisp_Object Vprocess_connection_type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 /* FSFmacs says:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 These next two vars are non-static since sysdep.c uses them in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 emulation of `select'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 /* Number of events of change of status of a process. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 static volatile int process_tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 /* Number of events for which the user or sentinel has been notified. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 static int update_tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 /* Nonzero means delete a process right away if it exits. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 int delete_exited_processes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 /* Indexed by descriptor, gives the process (if any) for that descriptor */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 Lisp_Object descriptor_to_process[MAXDESC];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 /* List of process objects. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 Lisp_Object Vprocess_list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 Lisp_Object Qprocessp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 /* Buffered-ahead input char from process, indexed by channel.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 -1 means empty (no char is buffered).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 Used on sys V where the only way to tell if there is any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 output from the process is to read at least one char.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 Always -1 on systems that support FIONREAD. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 /* FSFmacs says:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 Don't make static; need to access externally. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 static int proc_buffered_char[MAXDESC];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 #ifdef HAVE_PTYS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 /* The file name of the pty opened by allocate_pty. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 static char pty_name[24];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 /* the process Lisp object */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 * Structure records pertinent information about open channels.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 * There is one channel associated with each process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 struct Lisp_Process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 struct lcrecord_header header;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 /* Name of this process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 Lisp_Object name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 /* List of command arguments that this process was run with */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 Lisp_Object command;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 /* (funcall FILTER PROC STRING) (if FILTER is non-nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 to dispose of a bunch of chars from the process all at once */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 Lisp_Object filter;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 /* (funcall SENTINEL PROCESS) when process state changes */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 Lisp_Object sentinel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 /* Buffer that output is going to */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 Lisp_Object buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 /* Marker set to end of last buffer-inserted output from this process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 Lisp_Object mark;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 /* Lisp_Int of subprocess' PID, or a cons of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 service/host if this is really a network connection */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 Lisp_Object pid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 /* Non-0 if this is really a ToolTalk channel. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 int connected_via_filedesc_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 #if 0 /* FSFmacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 /* Perhaps it's cleaner this way, but FSFmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 provides no way of retrieving this value, so I'll
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 leave this info with PID. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 /* Non-nil if this is really a child process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 Lisp_Object childp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 /* Symbol indicating status of process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 This may be a symbol: run, stop, exit, signal */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 Lisp_Object status_symbol;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 /* Exit code if process has terminated,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 signal which stopped/interrupted process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 or 0 if process is running */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 int exit_code;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 /* Number of this process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 /* Non-false if process has exited and "dumped core" on its way down */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 char core_dumped;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 /* Descriptor by which we read from this process. -1 for dead process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 int infd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 /* Descriptor by which we write to this process. -1 for dead process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 int outfd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 /* Descriptor for the tty which this process is using.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 -1 if we didn't record it (on some systems, there's no need). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 int subtty;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 /* Name of subprocess terminal. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 Lisp_Object tty_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 /* Non-false if communicating through a pty. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 char pty_flag;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 /* This next field is only actually used #ifdef ENERGIZE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 /* if this flag is not NIL, then filter will do the read on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 channel, rather than having a call to make_string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 This only works if the filter is a subr. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 char filter_does_read;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 /* Non-nil means kill silently if Emacs is exited. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 char kill_without_query;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 char selected;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 /* Event-count of last event in which this process changed status. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 volatile int tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 /* Event-count of last such event reported. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 int update_tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 /* streams used in input and output */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 Lisp_Object instream;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 Lisp_Object outstream;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 /* The actual filedesc stream used for output; may be different
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 than OUTSTREAM under Mule */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 Lisp_Object filedesc_stream;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 static Lisp_Object mark_process (Lisp_Object, void (*) (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 static void print_process (Lisp_Object, Lisp_Object, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 static void finalize_process (void *, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 DEFINE_LRECORD_IMPLEMENTATION ("process", process,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 mark_process, print_process, finalize_process,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 0, 0, struct Lisp_Process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 mark_process (Lisp_Object obj, void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 struct Lisp_Process *proc = XPROCESS (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ((markobj) (proc->name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ((markobj) (proc->command));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 ((markobj) (proc->filter));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ((markobj) (proc->sentinel));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ((markobj) (proc->buffer));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ((markobj) (proc->mark));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ((markobj) (proc->pid));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 ((markobj) (proc->tty_name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 ((markobj) (proc->instream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ((markobj) (proc->outstream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ((markobj) (proc->filedesc_stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 return (proc->status_symbol);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 print_process (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 struct Lisp_Process *proc = XPROCESS (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 if (print_readably)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 error ("printing unreadable object #<process %s>",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 string_data (XSTRING (proc->name)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 if (!escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 print_internal (proc->name, printcharfun, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 int netp = network_connection_p (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 write_c_string (((netp) ? GETTEXT ("#<network connection ") :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 GETTEXT ("#<process ")), printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 print_internal (proc->name, printcharfun, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 write_c_string (((netp) ? " " : " pid "), printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 print_internal (proc->pid, printcharfun, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 write_c_string (" state:", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 print_internal (proc->status_symbol, printcharfun, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 write_c_string (">", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 #ifdef HAVE_WINDOW_SYSTEM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 extern void debug_process_finalization (struct Lisp_Process *p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 #endif /* HAVE_WINDOW_SYSTEM */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 finalize_process (void *header, int for_disksave)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 if (for_disksave) return; /* hmm, what would this do anyway? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 /* #### this probably needs to be tied into the tty event loop */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 /* #### when there is one */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 #ifdef HAVE_WINDOW_SYSTEM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 struct Lisp_Process *p = (struct Lisp_Process *) header;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 debug_process_finalization (p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 #endif /* HAVE_WINDOW_SYSTEM */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 /* basic process accessors */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 static SIGTYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 close_safely_handler (int signo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 EMACS_REESTABLISH_SIGNAL (signo, close_safely_handler);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 SIGRETURN;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 close_safely (int fd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 stop_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 signal (SIGALRM, close_safely_handler);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 alarm (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 close (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 alarm (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 start_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 close_descriptor_pair (int in, int out)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 if (in >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 close (in);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 if (out != in && out >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 close (out);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 /* Close all descriptors currently in use for communication
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 with subprocess. This is used in a newly-forked subprocess
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 to get rid of irrelevant descriptors. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 close_process_descs (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 #ifndef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 for (i = 0; i < MAXDESC; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 Lisp_Object process;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 process = descriptor_to_process[i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 if (!NILP (process))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 close_descriptor_pair (XPROCESS (process)->infd,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 XPROCESS (process)->outfd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 get_process_file_descriptors (struct Lisp_Process *p, int *infd,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 int *outfd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 if (! p) abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 /* the cast of MAXDESC is needed for some versions of Linux */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 assert (p->infd >= -1 && p->infd < ((int) (MAXDESC)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 assert (p->outfd >= -1 && p->outfd < ((int) (MAXDESC)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 *infd = p->infd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 *outfd = p->outfd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 struct Lisp_Process *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 get_process_from_input_descriptor (int infd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 if ((infd < 0) || (infd >= ((int) (MAXDESC)))) abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 proc = descriptor_to_process[infd];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 if (NILP (proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 return XPROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 get_process_selected_p (struct Lisp_Process *p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 return p->selected;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 set_process_selected_p (struct Lisp_Process *p, int selected_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 p->selected = !!selected_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 #ifdef HAVE_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 network_connection_p (Lisp_Object process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 return (GC_CONSP (XPROCESS (process)->pid));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 connected_via_filedesc_p (struct Lisp_Process *p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 return p->connected_via_filedesc_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 DEFUN ("processp", Fprocessp, Sprocessp, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 Return t if OBJECT is a process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 Lisp_Object obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 return ((PROCESSP (obj)) ? Qt : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 DEFUN ("process-list", Fprocess_list, Sprocess_list, 0, 0, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 Return a list of all processes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 return Fcopy_sequence (Vprocess_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 DEFUN ("get-process", Fget_process, Sget_process, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 Return the process named NAME, or nil if there is none.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 Lisp_Object name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 Lisp_Object tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 if (GC_PROCESSP (name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 return (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 if (!gc_in_progress)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 /* this only gets called during GC when emacs is going away as a result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 of a signal or crash. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 CHECK_STRING (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 for (tail = Vprocess_list; GC_CONSP (tail); tail = XCDR (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 Lisp_Object proc = XCAR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 if (!NILP (Fequal (name, XPROCESS (proc)->name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 return (XCAR (tail));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 DEFUN ("get-buffer-process", Fget_buffer_process, Sget_buffer_process, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 Return the (or, a) process associated with BUFFER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 BUFFER may be a buffer or the name of one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 Lisp_Object name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 Lisp_Object buf, tail, proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 if (GC_NILP (name)) return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 buf = Fget_buffer (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 if (GC_NILP (buf)) return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 #ifdef ENERGIZE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 Lisp_Object p = energize_get_buffer_process (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 if (!GC_NILP (p)) return p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 for (tail = Vprocess_list; GC_CONSP (tail); tail = XCDR (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 /* jwz: do not quit here - it isn't necessary, as there is no way for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 Vprocess_list to get circular or overwhelmingly long, and this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 function is called from layout_mode_element under redisplay. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 /* QUIT; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 proc = XCAR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 if (GC_PROCESSP (proc) && EQ (XPROCESS (proc)->buffer, buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 return proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 /* This is how commands for the user decode process arguments. It
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 accepts a process, a process name, a buffer, a buffer name, or nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 Buffers denote the first process in the buffer, and nil denotes the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 current buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 get_process (Lisp_Object name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 /* #### Look more closely into translating process names. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 /* This may be called during a GC from process_send_signal() from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 kill_buffer_processes() if emacs decides to abort(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 if (GC_PROCESSP (name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 return name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 if (GC_NILP (name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 proc = Fget_buffer_process (Fcurrent_buffer ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 proc = Fget_process (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 if (GC_NILP (proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 proc = Fget_buffer_process (Fget_buffer (name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 if (!GC_NILP (proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 return proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 if (GC_NILP (name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 error ("Current buffer has no process");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 error ("Process %s does not exist", string_data (XSTRING (name)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 /* NOTREACHED */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 return Qnil; /* warning suppression */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 DEFUN ("process-id", Fprocess_id, Sprocess_id, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 Return the process id of PROCESS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 This is the pid of the Unix process which PROCESS uses or talks to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 For a network connection, this value is a cons of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (foreign-network-port . foreign-host-name).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 Lisp_Object pid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 pid = XPROCESS (proc)->pid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 if (network_connection_p (proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 /* return (Qnil); */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 return (Fcons (Fcar (pid), Fcdr (pid)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 return (pid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 DEFUN ("process-name", Fprocess_name, Sprocess_name, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 Return the name of PROCESS, as a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 This is the name of the program invoked in PROCESS,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 possibly modified to make it unique among process names.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 return XPROCESS (proc)->name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 DEFUN ("process-command", Fprocess_command, Sprocess_command, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 Return the command that was executed to start PROCESS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 This is a list of strings, the first string being the program executed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 and the rest of the strings being the arguments given to it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 return XPROCESS (proc)->command;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 /* creating a process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 make_process_internal (Lisp_Object name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 Lisp_Object val, name1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 struct Lisp_Process *p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 = alloc_lcrecord (sizeof (struct Lisp_Process), lrecord_process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 /* If name is already in use, modify it until it is unused. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 name1 = name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 for (i = 1; ; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 char suffix[10];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 Lisp_Object tem = Fget_process (name1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 if (NILP (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 sprintf (suffix, "<%d>", i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 name1 = concat2 (name, build_string (suffix));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 name = name1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 p->name = name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 p->command = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 p->filter = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 p->sentinel = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 p->buffer = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 p->mark = Fmake_marker ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 p->pid = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 p->status_symbol = Qrun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 p->connected_via_filedesc_p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 p->exit_code = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 p->core_dumped = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 p->infd = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 p->outfd = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 p->subtty = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 p->tty_name = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 p->pty_flag = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 p->filter_does_read = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 p->kill_without_query = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 p->selected = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 p->tick = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 p->update_tick = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 p->instream = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 p->outstream = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 XSETPROCESS (val, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 Vprocess_list = Fcons (val, Vprocess_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 return (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 #ifdef HAVE_PTYS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 /* Open an available pty, returning a file descriptor.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 Return -1 on failure.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 The file name of the terminal corresponding to the pty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 is left in the variable pty_name. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 allocate_pty (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 struct stat stb;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 int c, i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 int fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 /* Some systems name their pseudoterminals so that there are gaps in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 the usual sequence - for example, on HP9000/S700 systems, there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 are no pseudoterminals with names ending in 'f'. So we wait for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 three failures in a row before deciding that we've reached the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 end of the ptys. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 int failed_count = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 #ifdef PTY_ITERATION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 PTY_ITERATION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 for (c = FIRST_PTY_LETTER; c <= 'z'; c++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 for (i = 0; i < 16; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 #ifdef PTY_NAME_SPRINTF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 PTY_NAME_SPRINTF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 sprintf (pty_name, "/dev/pty%c%x", c, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 #endif /* no PTY_NAME_SPRINTF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 #ifdef PTY_OPEN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 PTY_OPEN;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 #else /* no PTY_OPEN */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 #ifdef IRIS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 /* Unusual IRIS code */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 *ptyv = open ("/dev/ptc", O_RDWR | O_NDELAY, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 if (fd < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 if (fstat (fd, &stb) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 #else /* not IRIS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 if (stat (pty_name, &stb) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 failed_count++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 if (failed_count >= 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 failed_count = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 #ifdef O_NONBLOCK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 fd = open (pty_name, O_RDWR | O_NONBLOCK, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 fd = open (pty_name, O_RDWR | O_NDELAY, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 #endif /* not IRIS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 #endif /* no PTY_OPEN */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 if (fd >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 /* check to make certain that both sides are available
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 this avoids a nasty yet stupid bug in rlogins */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 #ifdef PTY_TTY_NAME_SPRINTF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 PTY_TTY_NAME_SPRINTF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 sprintf (pty_name, "/dev/tty%c%x", c, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 #endif /* no PTY_TTY_NAME_SPRINTF */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 #ifndef UNIPLUS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 if (access (pty_name, 6) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 close (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 #if !defined(IRIS) && !defined(__sgi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 #endif /* IRIS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 #endif /* not UNIPLUS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 setup_pty (fd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 return fd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 #endif /* HAVE_PTYS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 create_bidirectional_pipe (int *inchannel, int *outchannel,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 volatile int *forkin, volatile int *forkout)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 int sv[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 #ifdef SKTPAIR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 if (socketpair (AF_UNIX, SOCK_STREAM, 0, sv) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 *outchannel = *inchannel = sv[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 *forkout = *forkin = sv[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 #else /* not SKTPAIR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 pipe_with_inherited_out (sv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 *inchannel = sv[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 *forkout = sv[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 pipe_with_inherited_in (sv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 *forkin = sv[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 *outchannel = sv[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 #else /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 int temp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 temp = pipe (sv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 if (temp < 0) return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 *inchannel = sv[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 *forkout = sv[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 temp = pipe (sv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 if (temp < 0) return -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 *outchannel = sv[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 *forkin = sv[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 #endif /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 #endif /* not SKTPAIR */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 #ifndef VMS /* VMS version of this function is in vmsproc.c. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 static Bufbyte
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 get_eof_char (struct Lisp_Process *p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 /* Figure out the eof character for the outfd of the given process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 * The following code is similar to that in process_send_signal, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 * should probably be merged with that code somehow. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 #ifdef HAVE_TERMIOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 struct termios t;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 tcgetattr (p->outfd, &t);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VEOF + 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 return (Bufbyte) '\004';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 return (Bufbyte) t.c_cc[VEOF];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 #else /* ! HAVE_TERMIOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 /* On Berkeley descendants, the following IOCTL's retrieve the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 current control characters. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 #if defined (TIOCGETC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 struct tchars c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 ioctl (p->outfd, TIOCGETC, &c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 return (Bufbyte) c.t_eofc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 #else /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 /* On SYSV descendants, the TCGETA ioctl retrieves the current control
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 characters. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 #ifdef TCGETA
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 struct termio t;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 ioctl (p->outfd, TCGETA, &t);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 if (strlen ((CONST char *) t.c_cc) < (unsigned int) (VINTR + 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 return (Bufbyte) '\004';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 return (Bufbyte) t.c_cc[VINTR];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 #else /* ! defined (TCGETA) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 /* Rather than complain, we'll just guess ^D, which is what
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 * earlier emacsen always used. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 return (Bufbyte) '\004';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 #endif /* ! defined (TCGETA) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 #endif /* ! defined (TIOCGETC) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 #endif /* ! defined (HAVE_TERMIOS) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 get_pty_max_bytes (struct Lisp_Process *p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 int pty_max_bytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 #if defined (HAVE_FPATHCONF) && defined (_PC_MAX_CANON)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 pty_max_bytes = fpathconf (p->outfd, _PC_MAX_CANON);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 if (pty_max_bytes < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 pty_max_bytes = 250;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 pty_max_bytes = 250;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 /* Deduct one, to leave space for the eof. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 pty_max_bytes--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 return pty_max_bytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 init_process_fds (struct Lisp_Process *p, int in, int out)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 p->infd = in;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 p->outfd = out;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 p->instream = make_filedesc_input_stream (in, 0, -1, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 p->outstream = make_filedesc_output_stream (out, 0, -1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 LSTR_BLOCKED_OK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 | (p->pty_flag ?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 LSTR_PTY_FLUSHING : 0));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 p->filedesc_stream = p->outstream;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 if (p->pty_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 Bufbyte eof_char = get_eof_char (p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 int pty_max_bytes = get_pty_max_bytes (p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 filedesc_stream_set_pty_flushing (XLSTREAM (p->outstream),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 pty_max_bytes, eof_char);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 create_process (Lisp_Object process,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 char **new_argv, CONST char *current_dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 /* This function rewritten by wing@666.com. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 int pid, inchannel, outchannel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 /* Use volatile to protect variables from being clobbered by longjmp. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 volatile int forkin, forkout;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 volatile int pty_flag = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 char **env;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 struct Lisp_Process *p = XPROCESS (process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 env = environ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 inchannel = outchannel = forkin = forkout = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 #ifdef HAVE_PTYS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 if (!NILP (Vprocess_connection_type))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 /* find a new pty, open the master side, return the opened
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 file handle, and store the name of the corresponding slave
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 side in global variable pty_name. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 outchannel = inchannel = allocate_pty ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 if (inchannel >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 /* You're "supposed" to now open the slave in the child.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 On some systems, we can open it here; this allows for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 better error checking. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 #ifndef USG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 /* On USG systems it does not work to open the pty's tty here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 and then close and reopen it in the child. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 #ifdef O_NOCTTY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 /* Don't let this terminal become our controlling terminal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (in case we don't have one). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 forkout = forkin = open (pty_name, O_RDWR | O_NOCTTY, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 forkout = forkin = open (pty_name, O_RDWR, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 if (forkin < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 goto io_failure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 #endif /* not USG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 p->pty_flag = pty_flag = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 #endif /* HAVE_PTYS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 if (create_bidirectional_pipe (&inchannel, &outchannel,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 &forkin, &forkout) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 goto io_failure;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 /* Replaced by close_process_descs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 set_exclusive_use (inchannel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 set_exclusive_use (outchannel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 set_descriptor_non_blocking (inchannel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 /* Record this as an active process, with its channels.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 As a result, child_setup will close Emacs's side of the pipes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 descriptor_to_process[inchannel] = process;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 init_process_fds (p, inchannel, outchannel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 /* Record the tty descriptor used in the subprocess. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 p->subtty = forkin;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 p->status_symbol = Qrun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 p->exit_code = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 /* child_setup must clobber environ on systems with true vfork.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 Protect it from permanent change. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 char **save_environ = environ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 #ifdef EMACS_BTL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 /* when performance monitoring is on, turn it off before the vfork(),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 as the child has no handler for the signal -- when back in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 parent process, turn it back on if it was really on when you "turned
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 it off" */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 int logging_on = cadillac_stop_logging (); /* #### rename me */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 #ifndef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 pid = vfork ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 if (pid == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 #endif /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 /**** Now we're in the child process ****/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 int xforkin = forkin;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 int xforkout = forkout;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 if (!pty_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 EMACS_SEPARATE_PROCESS_GROUP ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 #ifdef HAVE_PTYS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 /* Disconnect the current controlling terminal, pursuant to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 making the pty be the controlling terminal of the process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 Also put us in our own process group. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 disconnect_controlling_terminal ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 /* Open the pty connection and make the pty's terminal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 our controlling terminal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 On systems with TIOCSCTTY, we just use it to set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 the controlling terminal. On other systems, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 first TTY we open becomes the controlling terminal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 So, we end up with four possibilities:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (1) on USG and TIOCSCTTY systems, we open the pty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 and use TIOCSCTTY.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (2) on other USG systems, we just open the pty.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (3) on non-USG systems with TIOCSCTTY, we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 just use TIOCSCTTY. (On non-USG systems, we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 already opened the pty in the parent process.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (4) on non-USG systems without TIOCSCTTY, we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 close the pty and reopen it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 This would be cleaner if we didn't open the pty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 in the parent process, but doing it that way
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 makes it possible to trap error conditions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 It's harder to convey an error from the child
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 process, and I don't feel like messing with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 this now. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 /* There was some weirdo, probably wrong,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 conditionalization on RTU and UNIPLUS here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 I deleted it. So sue me. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 /* SunOS has TIOCSCTTY but the close/open method
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 also works. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 # if defined (USG) || !defined (TIOCSCTTY)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 /* Now close the pty (if we had it open) and reopen it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 This makes the pty the controlling terminal of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 subprocess. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 /* I wonder if close (open (pty_name, ...)) would work? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 if (xforkin >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 close (xforkin);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 xforkout = xforkin = open (pty_name, O_RDWR, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 if (xforkin < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 write (1, "Couldn't open the pty terminal ", 31);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 write (1, pty_name, strlen (pty_name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 write (1, "\n", 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 _exit (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 # endif /* USG or not TIOCSCTTY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 /* Miscellaneous setup required for some systems.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 Must be done before using tc* functions on xforkin.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 This guarantees that isatty(xforkin) is true. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 # ifdef SETUP_SLAVE_PTY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 SETUP_SLAVE_PTY;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 # endif /* SETUP_SLAVE_PTY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 # ifdef TIOCSCTTY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 /* We ignore the return value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 because faith@cs.unc.edu says that is necessary on Linux. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 assert (isatty (xforkin));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 ioctl (xforkin, TIOCSCTTY, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 # endif /* TIOCSCTTY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 /* Change the line discipline. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 # if defined (HAVE_TERMIOS) && defined (LDISC1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 struct termios t;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 assert (isatty (xforkin));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 tcgetattr (xforkin, &t);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 t.c_lflag = LDISC1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 if (tcsetattr (xforkin, TCSANOW, &t) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 perror ("create_process/tcsetattr LDISC1 failed\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 # elif defined (NTTYDISC) && defined (TIOCSETD)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 /* Use new line discipline. TIOCSETD is accepted and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 ignored on Sys5.4 systems with ttcompat. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 int ldisc = NTTYDISC;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 assert (isatty (xforkin));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 ioctl (xforkin, TIOCSETD, &ldisc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 # endif /* TIOCSETD & NTTYDISC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 /* Make our process group be the foreground group
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 of our new controlling terminal. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 int piddly = EMACS_GET_PROCESS_GROUP ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 EMACS_SET_TTY_PROCESS_GROUP (xforkin, &piddly);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 # ifdef AIX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 /* On AIX, we've disabled SIGHUP above once we start a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 child on a pty. Now reenable it in the child, so it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 will die when we want it to. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 signal (SIGHUP, SIG_DFL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 # endif /* AIX */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 #endif /* HAVE_PTYS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 signal (SIGINT, SIG_DFL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 signal (SIGQUIT, SIG_DFL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 #ifndef MSDOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 if (pty_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 /* Set up the terminal characteristics of the pty. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 child_setup_tty (xforkout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 pid = child_setup (xforkin, xforkout, xforkout,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 new_argv, current_dir);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 #else /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 child_setup (xforkin, xforkout, xforkout, new_argv, current_dir);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 #endif /* not WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 #endif /* not MSDOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 #ifdef EMACS_BTL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 else if (logging_on)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 cadillac_start_logging (); /* #### rename me */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 environ = save_environ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 if (pid < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 close_descriptor_pair (forkin, forkout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 report_file_error ("Doing vfork", Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 p->pid = make_int (pid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 /* p->subtty = -1; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 register_child (pid, inchannel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 #endif /* WINDOWSNT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 /* If the subfork execv fails, and it exits,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 this close hangs. I don't know why.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 So have an interrupt jar it loose. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 if (forkin >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 close_safely (forkin);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 if (forkin != forkout && forkout >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 close (forkout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 #ifdef HAVE_PTYS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 if (pty_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 XPROCESS (process)->tty_name = build_string (pty_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 XPROCESS (process)->tty_name = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 /* Notice that SIGCHLD was not blocked. (This is not possible on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 some systems.) No biggie if SIGCHLD occurs right around the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 time that this call happens, because SIGCHLD() does not actually
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 deselect the process (that doesn't occur until the next time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 we're waiting for an event, when status_notify() is called). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 event_stream_select_process (XPROCESS (process));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 io_failure:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 int temp = errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 close_descriptor_pair (forkin, forkout);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 close_descriptor_pair (inchannel, outchannel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 errno = temp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 report_file_error ("Opening pty or pipe", Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 #endif /* not VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 /* This function is the unwind_protect form for Fstart_process_internal. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 PROC doesn't have its pid set, then we know someone has signalled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 an error and the process wasn't started successfully, so we should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 remove it from the process list. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 static void remove_process (Lisp_Object proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 start_process_unwind (Lisp_Object proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 /* Was PROC started successfully? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 if (EQ (XPROCESS (proc)->pid, Qnil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 remove_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 DEFUN ("start-process-internal", Fstart_process_internal,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 Sstart_process_internal, 3, MANY, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 Start a program in a subprocess. Return the process object for it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 Args are NAME BUFFER PROGRAM &rest PROGRAM-ARGS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 NAME is name for process. It is modified if necessary to make it unique.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 BUFFER is the buffer or (buffer-name) to associate with the process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 Process output goes at end of that buffer, unless you specify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 an output stream or filter function to handle the output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 BUFFER may be also nil, meaning that this process is not associated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 with any buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 Third arg is program file name. It is searched for as in the shell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 Remaining arguments are strings to give program as arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 INCODE and OUTCODE specify the coding-system objects used in input/output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 from/to the process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (nargs, args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 int nargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 Lisp_Object *args;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 /* !!#### This function has not been Mule-ized */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 Lisp_Object buffer, name, program, proc, current_dir;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 Lisp_Object tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 char *new_argv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 int len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 char **new_argv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 buffer = args[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 if (!NILP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 buffer = Fget_buffer_create (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 CHECK_STRING (args[0]); /* name */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 CHECK_STRING (args[2]); /* program */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 /* Make sure that the child will be able to chdir to the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 buffer's current directory, or its unhandled equivalent. We
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 can't just have the child check for an error when it does the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 chdir, since it's in a vfork.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 We have to GCPRO around this because Fexpand_file_name and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 Funhandled_file_name_directory might call a file name handling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 function. The argument list is protected by the caller, so all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 we really have to worry about is buffer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 struct gcpro gcpro1, gcpro2; /* Caller gc-protects args[] */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 current_dir = current_buffer->directory;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 GCPRO2 (buffer, current_dir);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 current_dir =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 expand_and_dir_to_file (Funhandled_file_name_directory (current_dir),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 #if 0 /* This loser breaks ange-ftp */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 if (NILP (Ffile_accessible_directory_p (current_dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 report_file_error ("Setting current directory",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 list1 (current_buffer->directory));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 #endif /* 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 name = args[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 program = args[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 /* Make a one member argv with all args concatenated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 together separated by a blank. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 len = string_length (XSTRING (program)) + 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 for (i = 3; i < nargs; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 tem = args[i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 CHECK_STRING (tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 len += string_length (XSTRING (tem)) + 1; /* count the blank */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 new_argv = (char *) alloca (len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 strcpy (new_argv, string_data (XSTRING (program)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 for (i = 3; i < nargs; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 tem = args[i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 CHECK_STRING (tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 strcat (new_argv, " ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 strcat (new_argv, string_data (XSTRING (tem)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 /* Need to add code here to check for program existence on VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 #else /* not VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 new_argv = (char **)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 alloca ((nargs - 1) * sizeof (char *));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 new_argv[0] = (char *) string_data (XSTRING (program));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 /* If program file name is not absolute, search our path for it */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 if (!IS_DIRECTORY_SEP (string_byte (XSTRING (program), 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 && !(string_length (XSTRING (program)) > 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 && IS_DEVICE_SEP (string_byte (XSTRING (program), 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; /* Caller protects args[] */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 GCPRO4 (buffer, current_dir, name, program);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 tem = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 locate_file (Vexec_path, program, EXEC_SUFFIXES, &tem,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 X_OK);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 if (NILP (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 report_file_error ("Searching for program", list1 (program));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 tem = Fexpand_file_name (tem, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 new_argv[0] = (char *) string_data (XSTRING (tem));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 if (!NILP (Ffile_directory_p (program)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 error ("Specified program for new process is a directory");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 for (i = 3; i < nargs; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 tem = args[i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 CHECK_STRING (tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 new_argv[i - 2] =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 (char *) string_data (XSTRING (tem));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 new_argv[i - 2] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 #endif /* not VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 proc = make_process_internal (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 XPROCESS (proc)->buffer = buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 XPROCESS (proc)->command = Flist (nargs - 2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 args + 2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 /* Make the process marker point into the process buffer (if any). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 if (!NILP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 Fset_marker (XPROCESS (proc)->mark,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 make_int (BUF_ZV (XBUFFER (buffer))), buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 /* If an error occurs and we can't start the process, we want to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 remove it from the process list. This means that each error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 check in create_process doesn't need to call remove_process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 itself; it's all taken care of here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 record_unwind_protect (start_process_unwind, proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 create_process (proc, new_argv,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 (char *) string_data (XSTRING (current_dir)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 return unbind_to (speccount, proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 /* connect to an existing file descriptor. This is very similar to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 open-network-stream except that it assumes that the connection has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 already been initialized. It is currently used for ToolTalk
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 communication. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 /* This function used to be visible on the Lisp level, but there is no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 real point in doing that. Here is the doc string:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 "Connect to an existing file descriptor.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 Returns a subprocess-object to represent the connection.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 Input and output work as for subprocesses; `delete-process' closes it.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 Args are NAME BUFFER INFD OUTFD.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 NAME is name for process. It is modified if necessary to make it unique.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 BUFFER is the buffer (or buffer-name) to associate with the process.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 Process output goes at end of that buffer, unless you specify\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 an output stream or filter function to handle the output.\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 BUFFER may be also nil, meaning that this process is not associated\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 with any buffer\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 INFD and OUTFD specify the file descriptors to use for input and\n\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 output, respectively."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 connect_to_file_descriptor (Lisp_Object name, Lisp_Object buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 Lisp_Object infd, Lisp_Object outfd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 int inch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 CHECK_STRING (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 CHECK_INT (infd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 CHECK_INT (outfd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 inch = XINT (infd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 if (!NILP (descriptor_to_process[inch]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 error ("There is already a process connected to fd %d", inch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 if (!NILP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 buffer = Fget_buffer_create (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 proc = make_process_internal (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 descriptor_to_process[inch] = proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 XPROCESS (proc)->pid = Fcons (infd, name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 XPROCESS (proc)->buffer = buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 init_process_fds (XPROCESS (proc), inch, XINT (outfd));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 XPROCESS (proc)->connected_via_filedesc_p = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 event_stream_select_process (XPROCESS (proc));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 return proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 #ifdef HAVE_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 get_internet_address (Lisp_Object host, struct sockaddr_in *address,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 Error_behavior errb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 struct hostent *host_info_ptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 #ifndef HAVE_TERM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 memset (address, 0, sizeof (*address));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 #ifdef TRY_AGAIN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 h_errno = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 /* Some systems can't handle SIGIO/SIGALARM in gethostbyname. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 slow_down_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 host_info_ptr = gethostbyname ((char *) string_data (XSTRING (host)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 speed_up_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 #ifdef TRY_AGAIN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 if (! (host_info_ptr == 0 && h_errno == TRY_AGAIN))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 Fsleep_for (make_int (1));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 if (host_info_ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 address->sin_family = host_info_ptr->h_addrtype;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 memcpy (&address->sin_addr, host_info_ptr->h_addr, host_info_ptr->h_length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 IN_ADDR numeric_addr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 /* Attempt to interpret host as numeric inet address */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 numeric_addr = inet_addr ((char *) string_data (XSTRING (host)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 if (NUMERIC_ADDR_ERROR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 maybe_error (Qprocess, errb,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 "Unknown host \"%s\"", string_data (XSTRING (host)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 /* There was some broken code here that called strlen() here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 on (char *) &numeric_addr and even sometimes accessed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 uninitialized data. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 address->sin_family = AF_INET;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 * (IN_ADDR *) &address->sin_addr = numeric_addr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 /* open a TCP network connection to a given HOST/SERVICE. Treated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 exactly like a normal process when reading and writing. Only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 differences are in status display and process deletion. A network
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 connection has no PID; you cannot signal it. All you can do is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 deactivate and close it via delete-process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 DEFUN ("open-network-stream-internal", Fopen_network_stream_internal,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 Sopen_network_stream_internal,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 4, 4, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 Open a TCP connection for a service to a host.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 Returns a subprocess-object to represent the connection.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 Input and output work as for subprocesses; `delete-process' closes it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 Args are NAME BUFFER HOST SERVICE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 NAME is name for process. It is modified if necessary to make it unique.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 BUFFER is the buffer (or buffer-name) to associate with the process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 Process output goes at end of that buffer, unless you specify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 an output stream or filter function to handle the output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 BUFFER may be also nil, meaning that this process is not associated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 with any buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 Third arg is name of the host to connect to, or its IP address.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 Fourth arg SERVICE is name of the service desired, or an integer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 specifying a port number to connect to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 (name, buffer, host, service)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 Lisp_Object name, buffer, host, service;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 /* !!#### This function has not been Mule-ized */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 struct sockaddr_in address;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 int s, outch, inch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 int port;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 int retry = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 int retval;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 GCPRO4 (name, buffer, host, service);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 CHECK_STRING (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 CHECK_STRING (host);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 if (INTP (service))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 port = htons ((unsigned short) XINT (service));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 struct servent *svc_info;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 CHECK_STRING (service);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 svc_info = getservbyname ((char *) string_data (XSTRING (service)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 "tcp");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 if (svc_info == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 #ifdef WIN32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 error ("Unknown service \"%s\" (%d)",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 string_data (XSTRING (service)), WSAGetLastError ());
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 error ("Unknown service \"%s\"", string_data (XSTRING (service)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 port = svc_info->s_port;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 get_internet_address (host, &address, ERROR_ME);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 address.sin_port = port;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 s = socket (address.sin_family, SOCK_STREAM, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 if (s < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 report_file_error ("error creating socket", list1 (name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 /* Turn off interrupts here -- see comments below. There used to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 be code which called bind_polling_period() to slow the polling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 period down rather than turn it off, but that seems rather
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 bogus to me. Best thing here is to use a non-blocking connect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 or something, to check for QUIT. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 /* Comments that are not quite valid: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 /* Kernel bugs (on Ultrix at least) cause lossage (not just EINTR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 when connect is interrupted. So let's not let it get interrupted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 Note we do not turn off polling, because polling is only used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 when not interrupt_input, and thus not normally used on the systems
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 which have this bug. On systems which use polling, there's no way
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 to quit if polling is turned off. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 /* Slow down polling. Some kernels have a bug which causes retrying
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 connect to fail after a connect. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 slow_down_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 loop:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 /* A system call interrupted with a SIGALRM or SIGIO comes back
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 here, with can_break_system_calls reset to 0. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 SETJMP (break_system_call_jump);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 if (QUITP)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 speed_up_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 REALLY_QUIT;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 /* In case something really weird happens ... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 slow_down_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 /* Break out of connect with a signal (it isn't otherwise possible).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 Thus you don't get screwed with a hung network. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 can_break_system_calls = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 retval = connect (s, (struct sockaddr *) &address, sizeof (address));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 can_break_system_calls = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 if (retval == -1 && errno != EISCONN)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 int xerrno = errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 if (errno == EINTR)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 goto loop;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 if (errno == EADDRINUSE && retry < 20)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 /* A delay here is needed on some FreeBSD systems,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 and it is harmless, since this retrying takes time anyway
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 and should be infrequent. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 Fsleep_for (make_int (1));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 retry++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 goto loop;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 close (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 speed_up_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 errno = xerrno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 report_file_error ("connection failed", list2 (host, name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 speed_up_interrupts ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 #else /* HAVE_TERM */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 s = connect_server (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 if (s < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 report_file_error ("error creating socket", Fcons (name, Qnil));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 send_command (s, C_PORT, 0, "%s:%d", string_data (XSTRING (host)), ntohs (port));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 send_command (s, C_DUMB, 1, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 #endif /* HAVE_TERM */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 inch = s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 outch = dup (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 if (outch < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 close (s); /* this used to be leaked; from Kyle Jones */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 report_file_error ("error duplicating socket", list1 (name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 if (!NILP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 buffer = Fget_buffer_create (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 proc = make_process_internal (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 descriptor_to_process[inch] = proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 set_descriptor_non_blocking (inch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 XPROCESS (proc)->pid = Fcons (service, host);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 XPROCESS (proc)->buffer = buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 init_process_fds (XPROCESS (proc), inch, outch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 XPROCESS (proc)->connected_via_filedesc_p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 event_stream_select_process (XPROCESS (proc));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 return proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 #endif /* HAVE_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 canonicalize_host_name (Lisp_Object host)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 #ifdef HAVE_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 /* #### for HAVE_TERM, you probably have to do something else. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 struct sockaddr_in address;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 if (!get_internet_address (host, &address, ERROR_ME_NOT))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 return host;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 if (address.sin_family == AF_INET)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 return build_string (inet_ntoa (address.sin_addr));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 /* #### any clue what to do here? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 return host;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 return host;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 DEFUN ("set-process-window-size", Fset_process_window_size,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 Sset_process_window_size, 3, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 Tell PROCESS that it has logical window size HEIGHT and WIDTH.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 (proc, height, width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 Lisp_Object proc, height, width;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 CHECK_NATNUM (height);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 CHECK_NATNUM (width);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 if (set_window_size (XPROCESS (proc)->infd, XINT (height), XINT (width))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 <= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 return Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 /* Process I/O */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 /* (Faccept_process_output is now in event-stream.c) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 /* Some FSFmacs error handlers here. We handle this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 in call2_trapping_errors(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 /* Read pending output from the process channel,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 starting with our buffered-ahead character if we have one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 Yield number of characters read.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 This function reads at most 1024 bytes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 If you want to read all available subprocess output,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 you must call it repeatedly until it returns zero. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 Charcount
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 read_process_output (Lisp_Object proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 Bytecount nbytes, nchars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 char *chars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 Bufbyte chars[1024];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 Lisp_Object outstream;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 struct Lisp_Process *p = XPROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 /* If there is a lot of output from the subprocess, the loop in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 execute_internal_event() might call read_process_output() more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 than once. If the filter that was executed from one of these
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 calls set the filter to t, we have to stop now. Return -1 rather
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 than 0 so execute_internal_event() doesn't close the process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 Really, the loop in execute_internal_event() should check itself
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 for a process-filter change, like in status_notify(); but the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 struct Lisp_Process is not exported outside of this file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 if (p->infd < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 return -1; /* already closed */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 if (!NILP (p->filter) && (p->filter_does_read))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 Lisp_Object filter_result;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 /* Some weird FSFmacs crap here with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 Vdeactivate_mark and current_buffer->keymap */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 running_asynch_code = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 filter_result = call2_trapping_errors ("Error in process filter",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 p->filter, proc, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 running_asynch_code = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 restore_match_data ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 CHECK_INT (filter_result);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 return XINT (filter_result);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 VMS_PROC_STUFF *vs, *get_vms_process_pointer();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 vs = get_vms_process_pointer (XINT (p->pid));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 if (vs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 if (!vs->iosb[0])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 return(0); /* Really weird if it does this */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 if (!(vs->iosb[0] & 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 return -1; /* I/O error */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 error ("Could not get VMS process pointer");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 chars = vs->inputBuffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 nbytes = clean_vms_buffer (chars, vs->iosb[1]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 if (nbytes <= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 start_vms_process_read (vs); /* Crank up the next read on the process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 return 1; /* Nothing worth printing, say we got 1 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 #else /* not VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 #if 0 /* FSFmacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 /* #### equivalent code from FSFmacs. Would need some porting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 for Windows NT. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 if (proc_buffered_char[channel] < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 nchars = read_child_output (channel, chars, sizeof (chars));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 nchars = read (channel, chars, sizeof chars);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 chars[0] = proc_buffered_char[channel];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 proc_buffered_char[channel] = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 nchars = read_child_output (channel, chars + 1, sizeof (chars) - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 nchars = read (channel, chars + 1, sizeof chars - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 if (nchars < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 nchars = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 nchars = nchars + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 #endif /* FSFmacs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 nbytes = Lstream_read (XLSTREAM (p->instream), chars, sizeof (chars));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 if (nbytes <= 0) return nbytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 #endif /* not VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 nchars = bytecount_to_charcount (chars, nbytes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 outstream = p->filter;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 if (!NILP (outstream))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 /* We used to bind inhibit-quit to t here, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 call2_trapping_errors() does that for us. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 running_asynch_code = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 call2_trapping_errors ("Error in process filter",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 outstream, proc, make_string (chars, nbytes));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 running_asynch_code = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 restore_match_data ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 start_vms_process_read (vs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 return (nchars);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 /* If no filter, write into buffer if it isn't dead. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 if (!NILP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 Lisp_Object old_read_only = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 Bufpos old_point;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 Bufpos old_begv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 Bufpos old_zv;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 int old_zmacs_region_stays = zmacs_region_stays;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 struct gcpro gcpro1, gcpro2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 struct buffer *buf = XBUFFER (p->buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 GCPRO2 (proc, old_read_only);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 old_point = BUF_PT (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 old_begv = BUF_BEGV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 old_zv = BUF_ZV (buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 old_read_only = buf->read_only;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 buf->read_only = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 /* Insert new output into buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 at the current end-of-output marker,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 thus preserving logical ordering of input and output. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 if (XMARKER (p->mark)->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 BUF_SET_PT (buf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 bufpos_clip_to_bounds (old_begv, marker_position (p->mark),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 old_zv));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 BUF_SET_PT (buf, old_zv);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 /* If the output marker is outside of the visible region, save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 the restriction and widen. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 if (! (BUF_BEGV (buf) <= BUF_PT (buf) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 BUF_PT (buf) <= BUF_ZV (buf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 Fwiden (p->buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 /* Make sure opoint floats ahead of any new text, just as point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 would. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 if (BUF_PT (buf) <= old_point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700 old_point += nchars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 /* Insert after old_begv, but before old_zv. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 if (BUF_PT (buf) < old_begv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 old_begv += nchars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 if (BUF_PT (buf) <= old_zv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706 old_zv += nchars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 /* This screws up intial display of the window. jla */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 /* Insert before markers in case we are inserting where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 the buffer's mark is, and the user's next command is Meta-y. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 buffer_insert_raw_string_1 (buf, -1, chars,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 nbytes, INSDEL_BEFORE_MARKERS);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 buffer_insert_raw_string (buf, chars, nbytes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 Fset_marker (p->mark, make_int (BUF_PT (buf)), p->buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 MARK_MODELINE_CHANGED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 /* If the restriction isn't what it should be, set it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 if (old_begv != BUF_BEGV (buf) || old_zv != BUF_ZV (buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 Fnarrow_to_region (make_int (old_begv), make_int (old_zv),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 p->buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 /* Handling the process output should not deactivate the mark. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 zmacs_region_stays = old_zmacs_region_stays;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 buf->read_only = old_read_only;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 BUF_SET_PT (buf, old_point);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 start_vms_process_read (vs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 return (nchars);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 /* Sending data to subprocess */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 static JMP_BUF send_process_frame;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 static SIGTYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 send_process_trap (int signum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 EMACS_REESTABLISH_SIGNAL (signum, send_process_trap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 EMACS_UNBLOCK_SIGNAL (signum);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 LONGJMP (send_process_frame, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 /* send some data to process PROC. If NONRELOCATABLE is non-NULL, it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 specifies the address of the data. Otherwise, the data comes from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 object RELOCATABLE (either a string or a buffer). START and LEN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 specify the offset and length of the data to send.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 Note that START and LEN are in Bufpos's if RELOCATABLE is a buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 and in Bytecounts otherwise. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 send_process (volatile Lisp_Object proc,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 Lisp_Object relocatable, CONST Bufbyte *nonrelocatable,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764 int start, int len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 /* Use volatile to protect variables from being clobbered by longjmp. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 struct gcpro gcpro1, gcpro2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 SIGTYPE (*old_sigpipe) (int) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 Lisp_Object lstream = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 volatile struct Lisp_Process *p = XPROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 #if defined (NO_UNION_TYPE) /* || !defined (__GNUC__) GCC bug only??? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 /* #### ugh! There must be a better solution. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 Lisp_Object defeat_volatile_kludge = (Lisp_Object) proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 Lisp_Object defeat_volatile_kludge = proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 VMS_PROC_STUFF *vs, *get_vms_process_pointer (int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 #endif /* VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 GCPRO2 (defeat_volatile_kludge, lstream);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 if (p->outfd < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 signal_simple_error ("Process not open for writing", proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 vs = get_vms_process_pointer (XINT (p->pid));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 if (vs == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 error ("Could not find this process: %x",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 XINT (p->pid));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 else if (write_to_vms_process (vs, buf, len))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 if (nonrelocatable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 lstream =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 make_fixed_buffer_input_stream (nonrelocatable + start, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 else if (GC_BUFFERP (relocatable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 lstream = make_lisp_buffer_input_stream (XBUFFER (relocatable),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 start, start + len, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 lstream = make_lisp_string_input_stream (relocatable, start, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 if (!SETJMP (send_process_frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 /* use a reasonable-sized buffer (somewhere around the size of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 stream buffer) so as to avoid inundating the stream with blocked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 data. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 Bufbyte chunkbuf[512];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 Bytecount chunklen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 while (1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 int writeret;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 chunklen = Lstream_read (XLSTREAM (lstream), chunkbuf, 512);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 if (chunklen <= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 break; /* perhaps should abort() if < 0?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 This should never happen. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 old_sigpipe =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 /* Lstream_write() will never successfully write less than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 the amount sent in. In the worst case, it just buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 the unwritten data. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 writeret = Lstream_write (XLSTREAM (p->outstream), chunkbuf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 chunklen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 if (writeret < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 /* This is a real error. Blocking errors are handled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 specially inside of the filedesc stream. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 report_file_error ("writing to process",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 list1 (proc));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 while (filedesc_stream_was_blocked (XLSTREAM (p->filedesc_stream)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 /* Buffer is full. Wait, accepting input;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 that may allow the program
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839 to finish doing output and read more. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 Faccept_process_output (Qnil, make_int (1), Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 old_sigpipe =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 Lstream_flush (XLSTREAM (p->filedesc_stream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 #endif /* !VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 { /* We got here from a longjmp() from the SIGPIPE handler */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 p->status_symbol = Qexit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 p->exit_code = 256; /* #### SIGPIPE ??? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 p->core_dumped = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 p->tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 process_tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 deactivate_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 error ("Error writing to process %s; closed it",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 string_data (XSTRING (p->name)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 error ("SIGPIPE raised on process %s; closed it",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 string_data (XSTRING (p->name)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 Lstream_flush (XLSTREAM (p->outstream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 DEFUN ("process-tty-name", Fprocess_tty_name, Sprocess_tty_name, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 Return the name of the terminal PROCESS uses, or nil if none.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 This is the terminal that the process itself reads and writes on,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 not the name of the pty that Emacs uses to talk with that terminal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 (proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 return XPROCESS (proc)->tty_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 DEFUN ("set-process-buffer", Fset_process_buffer, Sset_process_buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 Set buffer associated with PROCESS to BUFFER (a buffer, or nil).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 (proc, buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 Lisp_Object proc, buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 if (!NILP (buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 CHECK_BUFFER (buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 XPROCESS (proc)->buffer = buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 return buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 DEFUN ("process-buffer", Fprocess_buffer, Sprocess_buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 Return the buffer PROCESS is associated with.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 Output from PROCESS is inserted in this buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 unless PROCESS has a filter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 (proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 return XPROCESS (proc)->buffer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 DEFUN ("process-mark", Fprocess_mark, Sprocess_mark,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 Return the marker for the end of the last output from PROCESS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 (proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 #ifdef ENERGIZE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918 if (EQ (proc, Venergize_process)) /* per buffer rather than per process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919 return Fenergize_user_input_buffer_mark (Qnil); /* ## current_buffer ok? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 return XPROCESS (proc)->mark;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 set_process_filter (Lisp_Object proc, Lisp_Object filter, int filter_does_read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 if (PROCESS_LIVE_P (proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 if (EQ (filter, Qt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 event_stream_unselect_process (XPROCESS (proc));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 event_stream_select_process (XPROCESS (proc));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 XPROCESS (proc)->filter = filter;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 XPROCESS (proc)->filter_does_read = filter_does_read;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 DEFUN ("set-process-filter", Fset_process_filter, Sset_process_filter,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 Give PROCESS the filter function FILTER; nil means no filter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 t means stop accepting output from the process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 When a process has a filter, each time it does output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 the entire string of output is passed to the filter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 The filter gets two arguments: the process and the string of output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 If the process has a filter, its buffer is not used for output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 (proc, filter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 Lisp_Object proc, filter;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 set_process_filter (proc, filter, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 return filter;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 DEFUN ("process-filter", Fprocess_filter, Sprocess_filter,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 Return the filter function of PROCESS; nil if none.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 See `set-process-filter' for more info on filter functions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 (proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 return XPROCESS (proc)->filter;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 DEFUN ("process-send-region", Fprocess_send_region, Sprocess_send_region,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 3, 3, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 Send current contents of region as input to PROCESS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 PROCESS may be a process name or an actual process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 Called from program, takes three arguments, PROCESS, START and END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 If the region is more than 500 or so characters long,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 it is sent in several bunches. This may happen even for shorter regions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 Output from processes can arrive in between bunches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 (process, start, end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 Lisp_Object process, start, end;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 Lisp_Object proc = get_process (process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 Bufpos st, en;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 get_buffer_range_char (current_buffer, start, end, &st, &en, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 send_process (proc, Fcurrent_buffer (), 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 st, en - st);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 return (Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 DEFUN ("process-send-string", Fprocess_send_string, Sprocess_send_string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 2, 4, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 Send PROCESS the contents of STRING as input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 PROCESS may be a process name or an actual process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 Optional arguments FROM and TO specify part of STRING, see `substring'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 If STRING is more than 500 or so characters long,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 it is sent in several bunches. This may happen even for shorter strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 Output from processes can arrive in between bunches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 (process, string, from, to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 Lisp_Object process, string, from, to;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 Bytecount len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 Bytecount bfr, bto;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 proc = get_process (process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 CHECK_STRING (string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008 get_string_range_byte (string, from, to, &bfr, &bto,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009 GB_HISTORICAL_STRING_BEHAVIOR);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 len = bto - bfr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 send_process (proc, string, 0, bfr, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013 return (Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 /* process status */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 /* Some FSFmacs error handlers here. We handle this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 in call2_trapping_errors(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 exec_sentinel_unwind (Lisp_Object datum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 struct Lisp_Cons *d = XCONS (datum);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 XPROCESS (d->car)->sentinel = d->cdr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 free_cons (d);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034 exec_sentinel (Lisp_Object proc, Lisp_Object reason)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 Lisp_Object sentinel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 struct Lisp_Process *p = XPROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 sentinel = p->sentinel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 if (NILP (sentinel))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 /* Some weird FSFmacs crap here with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 Vdeactivate_mark and current_buffer->keymap */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 /* Zilch the sentinel while it's running, to avoid recursive invocations;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 assure that it gets restored no matter how the sentinel exits. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 p->sentinel = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 record_unwind_protect (exec_sentinel_unwind, noseeum_cons (proc, sentinel));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 /* We used to bind inhibit-quit to t here, but call2_trapping_errors()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 does that for us. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 running_asynch_code = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 call2_trapping_errors ("Error in process sentinel",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 sentinel, proc, reason);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 running_asynch_code = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 restore_match_data ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 unbind_to (speccount, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 DEFUN ("set-process-sentinel", Fset_process_sentinel, Sset_process_sentinel,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 2, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 Give PROCESS the sentinel SENTINEL; nil for none.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 The sentinel is called as a function when the process changes state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066 It gets two arguments: the process, and a string describing the change.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 (proc, sentinel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 Lisp_Object proc, sentinel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 XPROCESS (proc)->sentinel = sentinel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 return sentinel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 DEFUN ("process-sentinel", Fprocess_sentinel, Sprocess_sentinel,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 Return the sentinel of PROCESS; nil if none.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 See `set-process-sentinel' for more info on sentinels.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 (proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 return XPROCESS (proc)->sentinel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 CONST char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 signal_name (int signum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 if (signum >= 0 && signum < NSIG)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 #ifndef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 return ((CONST char *) sys_siglist[signum]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 return ((CONST char *) sys_errlist[signum]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 return ((CONST char *) GETTEXT ("unknown signal"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 /* Compute the Lisp form of the process status from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 the numeric status that was returned by `wait'. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 update_status_from_wait_code (struct Lisp_Process *p, WAITTYPE *w_fmh)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 /* C compiler lossage when attempting to pass w directly */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 WAITTYPE w = *w_fmh;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 if (WIFSTOPPED (w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 p->status_symbol = Qstop;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 p->exit_code = WSTOPSIG (w);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 p->core_dumped = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 else if (WIFEXITED (w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 p->status_symbol = Qexit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 p->exit_code = WRETCODE (w);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 p->core_dumped = ((WCOREDUMP (w)) ? 1 : 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 else if (WIFSIGNALED (w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 p->status_symbol = Qsignal;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 p->exit_code = (int) WTERMSIG (w);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 p->core_dumped = ((WCOREDUMP (w)) ? 1 : 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 p->status_symbol = Qrun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 p->exit_code = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 update_process_status (Lisp_Object p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 Lisp_Object status_symbol,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 int exit_code,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 int core_dumped)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 XPROCESS (p)->tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 process_tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 XPROCESS (p)->status_symbol = status_symbol;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 XPROCESS (p)->exit_code = exit_code;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 XPROCESS (p)->core_dumped = core_dumped;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 #ifdef SIGCHLD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 #define MAX_EXITED_PROCESSES 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 static volatile pid_t exited_processes[MAX_EXITED_PROCESSES];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 static volatile WAITTYPE exited_processes_status[MAX_EXITED_PROCESSES];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 static volatile int exited_processes_index;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 static volatile int sigchld_happened;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 /* For any processes that have changed status and are recorded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 and such, update the corresponding struct Lisp_Process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 We separate this from record_exited_processes() so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 we never have to call this function from within a signal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 handler. We block SIGCHLD in case record_exited_processes()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162 is called from a signal handler. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 reap_exited_processes (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168 struct Lisp_Process *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 EMACS_BLOCK_SIGNAL (SIGCHLD);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 for (i = 0; i < exited_processes_index; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 int pid = exited_processes[i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174 WAITTYPE w = exited_processes_status[i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176 /* Find the process that signaled us, and record its status. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 Lisp_Object tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 LIST_LOOP (tail, Vprocess_list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183 Lisp_Object proc = XCAR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 p = XPROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185 if (INTP (p->pid) && XINT (p->pid) == pid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187 p = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 if (p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193 /* Change the status of the process that was found. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 p->tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195 process_tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 update_status_from_wait_code (p, &w);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 /* If process has terminated, stop waiting for its output. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 if (WIFSIGNALED (w) || WIFEXITED (w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 if (p->infd >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 /* We can't just call event_stream->unselect_process_cb (p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 here, because that calls XtRemoveInput, which is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 necessarily reentrant, so we can't call this at interrupt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 /* There was no asynchronous process found for that id. Check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 if we have a synchronous process. Only set sync process status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 if there is one, so we work OK with the waitpid() call in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 wait_for_termination(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 if (synch_process_alive != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 { /* Set the global sync process status variables. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 synch_process_alive = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 /* Report the status of the synchronous process. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 if (WIFEXITED (w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 synch_process_retcode = WRETCODE (w);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224 else if (WIFSIGNALED (w))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 synch_process_death = signal_name (WTERMSIG (w));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 exited_processes_index = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235 /* On receipt of a signal that a child status has changed,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 loop asking about children with changed statuses until
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 the system says there are no more. All we do is record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 the processes and wait status.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 This function could be called from within the SIGCHLD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 handler, so it must be completely reentrant. When
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 not called from a SIGCHLD handler, BLOCK_SIGCHLD should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 be non-zero so that SIGCHLD is blocked while this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 function is running. (This is necessary so avoid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 race conditions with the SIGCHLD_HAPPENED flag). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 record_exited_processes (int block_sigchld)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 if (block_sigchld)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 EMACS_BLOCK_SIGNAL (SIGCHLD);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 while (sigchld_happened)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 int pid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 WAITTYPE w;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 /* Keep trying to get a status until we get a definitive result. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 errno = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 #ifdef WNOHANG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 # ifndef WUNTRACED
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264 # define WUNTRACED 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 # endif /* not WUNTRACED */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 # ifdef HAVE_WAITPID
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 pid = waitpid ((pid_t) -1, &w, WNOHANG | WUNTRACED);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 pid = wait3 (&w, WNOHANG | WUNTRACED, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 #else /* not WNOHANG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 pid = wait (&w);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273 #endif /* not WNOHANG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 while (pid <= 0 && errno == EINTR);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 if (pid <= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 if (exited_processes_index < MAX_EXITED_PROCESSES)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 exited_processes[exited_processes_index] = pid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 exited_processes_status[exited_processes_index] = w;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 exited_processes_index++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287 /* On systems with WNOHANG, we just ignore the number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 of times that SIGCHLD was signalled, and keep looping
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 until there are no more processes to wait on. If we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 don't have WNOHANG, we have to rely on the count in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291 SIGCHLD_HAPPENED. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 #ifndef WNOHANG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 sigchld_happened--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 #endif /* not WNOHANG */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 sigchld_happened = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 if (block_sigchld)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 /** USG WARNING: Although it is not obvious from the documentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 in signal(2), on a USG system the SIGCLD handler MUST NOT call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 signal() before executing at least one wait(), otherwise the handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 will be called again, resulting in an infinite loop. The relevant
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 portion of the documentation reads "SIGCLD signals will be queued
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 and the signal-catching function will be continually reentered until
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 the queue is empty". Invoking signal() causes the kernel to reexamine
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 the SIGCLD queue. Fred Fish, UniSoft Systems Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 (Note that now this only applies in SYS V Release 2 and before.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313 On SYS V Release 3, we use sigset() to set the signal handler for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 the first time, and so we don't have to reestablish the signal handler
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 in the handler below. On SYS V Release 4, we don't get this weirdo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316 behavior when we use sigaction(), which we do use.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 static SIGTYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 sigchld_handler (int signo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 #ifdef OBNOXIOUS_SYSV_SIGCLD_BEHAVIOR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322 int old_errno = errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 sigchld_happened++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 record_exited_processes (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 errno = old_errno;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 sigchld_happened++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330 signal_fake_event ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331 /* WARNING - must come after wait3() for USG systems */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 EMACS_REESTABLISH_SIGNAL (signo, sigchld_handler);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333 SIGRETURN;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336 #endif /* SIGCHLD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338 /* Return a string describing a process status list. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 status_message (struct Lisp_Process *p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 Lisp_Object symbol = p->status_symbol;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 int code = p->exit_code;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 int coredump = p->core_dumped;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 Lisp_Object string, string2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 if (EQ (symbol, Qsignal) || EQ (symbol, Qstop))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 string = build_string (signal_name (code));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351 if (coredump)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 string2 = build_translated_string (" (core dumped)\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 string2 = build_string ("\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 set_string_char (XSTRING (string), 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 DOWNCASE (current_buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 string_char (XSTRING (string), 0)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 return concat2 (string, string2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 else if (EQ (symbol, Qexit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 if (code == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363 return build_translated_string ("finished\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364 string = Fnumber_to_string (make_int (code));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 if (coredump)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366 string2 = build_translated_string (" (core dumped)\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 string2 = build_string ("\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369 return concat2 (build_translated_string ("exited abnormally with code "),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2370 concat2 (string, string2));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373 return Fcopy_sequence (Fsymbol_name (symbol));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 /* Tell status_notify() to check for terminated processes. We do this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 because on some systems we sometimes miss SIGCHLD calls. (Not sure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378 why.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 kick_status_notify (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383 process_tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 /* Report all recent events of a change in process status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 (either run the sentinel or output a message).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 This is done while Emacs is waiting for keyboard input. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 status_notify (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 Lisp_Object tail = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395 Lisp_Object symbol = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 Lisp_Object msg = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 struct gcpro gcpro1, gcpro2, gcpro3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 /* process_tick is volatile, so we have to remember it now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399 Otherwise, we get a race condition is SIGCHLD happens during
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 this function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402 (Actually, this is not the case anymore. The code to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 update the process structures has been moved out of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 SIGCHLD handler. But for the moment I'm leaving this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 stuff in -- it can't hurt.) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 int temp_process_tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 #ifdef SIGCHLD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 #ifndef OBNOXIOUS_SYSV_SIGCLD_BEHAVIOR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 record_exited_processes (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 reap_exited_processes ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415 temp_process_tick = process_tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 if (update_tick == temp_process_tick)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 /* We need to gcpro tail; if read_process_output calls a filter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 which deletes a process and removes the cons to which tail points
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 from Vprocess_alist, and then causes a GC, tail is an unprotected
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 reference. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 GCPRO3 (tail, symbol, msg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 Lisp_Object proc = XCAR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 struct Lisp_Process *p = XPROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430 /* p->tick is also volatile. Same thing as above applies. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431 int this_process_tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 #ifdef HAVE_WAITPID
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 /* #### extra check for terminated processes, in case a SIGCHLD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 got missed (this seems to happen sometimes, I'm not sure why).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 WAITTYPE w;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 #ifdef SIGCHLD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440 EMACS_BLOCK_SIGNAL (SIGCHLD);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442 if (INTP (p->pid) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443 waitpid (XINT (p->pid), &w, WNOHANG) == XINT (p->pid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 p->tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 update_status_from_wait_code (p, &w);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 #ifdef SIGCHLD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 EMACS_UNBLOCK_SIGNAL (SIGCHLD);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453 this_process_tick = p->tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 if (this_process_tick != p->update_tick)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 p->update_tick = this_process_tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 /* If process is still active, read any output that remains. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 while (!EQ (p->filter, Qt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460 && read_process_output (proc) > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463 /* Get the text to use for the message. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 msg = status_message (p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 /* If process is terminated, deactivate it or delete it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 symbol = p->status_symbol;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 if (EQ (symbol, Qsignal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 || EQ (symbol, Qexit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 if (delete_exited_processes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 remove_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475 deactivate_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 /* Now output the message suitably. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 if (!NILP (p->sentinel))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 exec_sentinel (proc, msg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 /* Don't bother with a message in the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 when a process becomes runnable. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483 else if (!EQ (symbol, Qrun) && !NILP (p->buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 Lisp_Object old_read_only = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 Lisp_Object old = Fcurrent_buffer ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487 Bufpos opoint;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 struct gcpro ngcpro1, ngcpro2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490 /* Avoid error if buffer is deleted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 (probably that's why the process is dead, too) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492 if (!BUFFER_LIVE_P (XBUFFER (p->buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 NGCPRO2 (old, old_read_only);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 Fset_buffer (p->buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497 opoint = BUF_PT (current_buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 /* Insert new output into buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 at the current end-of-output marker,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 thus preserving logical ordering of input and output. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501 if (XMARKER (p->mark)->buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502 BUF_SET_PT (current_buffer, marker_position (p->mark));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504 BUF_SET_PT (current_buffer, BUF_ZV (current_buffer));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 if (BUF_PT (current_buffer) <= opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 opoint += (string_char_length (XSTRING (msg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507 + string_char_length (XSTRING (p->name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 + 10);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510 old_read_only = current_buffer->read_only;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511 current_buffer->read_only = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 buffer_insert_c_string (current_buffer, "\nProcess ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 Finsert (1, &p->name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 buffer_insert_c_string (current_buffer, " ");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515 Finsert (1, &msg);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2516 current_buffer->read_only = old_read_only;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517 Fset_marker (p->mark, make_int (BUF_PT (current_buffer)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518 p->buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2520 BUF_SET_PT (current_buffer, opoint);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2521 Fset_buffer (old);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2522 NUNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2523 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2524 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525 } /* end for */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527 /* in case buffers use %s in modeline-format */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2528 MARK_MODELINE_CHANGED;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2529 redisplay ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2531 update_tick = temp_process_tick;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2533 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536 DEFUN ("process-status", Fprocess_status, Sprocess_status, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537 Return the status of PROCESS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538 This is a symbol, one of these:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 run -- for a process that is running.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541 stop -- for a process stopped but continuable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 exit -- for a process that has exited.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543 signal -- for a process that has got a fatal signal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544 open -- for a network stream connection that is open.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545 closed -- for a network stream connection that is closed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546 nil -- if arg is a process name and no such process exists.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547 PROCESS may be a process, a buffer, the name of a process or buffer, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 nil, indicating the current buffer's process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 (proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2552 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553 Lisp_Object status;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555 if (STRINGP (proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556 proc = Fget_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 proc = get_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560 if (NILP (proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561 return proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 status = XPROCESS (proc)->status_symbol;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 if (network_connection_p (proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566 if (EQ (status, Qrun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 status = Qopen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568 else if (EQ (status, Qexit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569 status = Qclosed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571 return (status);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574 DEFUN ("process-exit-status", Fprocess_exit_status, Sprocess_exit_status,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576 Return the exit status of PROCESS or the signal number that killed it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577 If PROCESS has not yet exited or died, return 0.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2579 (proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583 return (make_int (XPROCESS (proc)->exit_code));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587 #ifdef SIGNALS_VIA_CHARACTERS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588 /* Get signal character to send to process if SIGNALS_VIA_CHARACTERS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 process_signal_char (int tty_fd, int signo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593 /* If it's not a tty, pray that these default values work */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594 if (!isatty(tty_fd)) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 #define CNTL(ch) (037 & (ch))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 switch (signo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 case SIGINT: return CNTL('C');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 case SIGQUIT: return CNTL('\\');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600 #ifdef SIGTSTP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601 case SIGTSTP: return CNTL('Z');
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 #ifdef HAVE_TERMIOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 /* TERMIOS is the latest and bestest, and seems most likely to work.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608 If the system has it, use it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 struct termios t;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 tcgetattr (tty_fd, &t);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612 switch (signo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 case SIGINT: return t.c_cc[VINTR];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 case SIGQUIT: return t.c_cc[VQUIT];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 # if defined (VSWTCH) && !defined (PREFER_VSUSP)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617 case SIGTSTP: return t.c_cc[VSWTCH];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619 case SIGTSTP: return t.c_cc[VSUSP];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2623
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624 # elif defined (TIOCGLTC) && defined (TIOCGETC) /* not HAVE_TERMIOS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626 /* On Berkeley descendants, the following IOCTL's retrieve the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 current control characters. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628 struct tchars c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 struct ltchars lc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630 switch (signo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632 case SIGINT: ioctl (tty_fd, TIOCGETC, &c); return c.t_intrc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 case SIGQUIT: ioctl (tty_fd, TIOCGETC, &c); return c.t_quitc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 # ifdef SIGTSTP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635 case SIGTSTP: ioctl (tty_fd, TIOCGLTC, &lc); return lc.t_suspc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 # endif /* SIGTSTP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 # elif defined (TCGETA) /* ! defined (TIOCGLTC) && defined (TIOCGETC) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 /* On SYSV descendants, the TCGETA ioctl retrieves the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 control characters. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 struct termio t;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 ioctl (tty_fd, TCGETA, &t);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 switch (signo) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 case SIGINT: return t.c_cc[VINTR];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 case SIGQUIT: return t.c_cc[VQUIT];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 # ifdef SIGTSTP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 case SIGTSTP: return t.c_cc[VSWTCH];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 # endif /* SIGTSTP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 # else /* ! defined (TCGETA) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 #error ERROR! Using SIGNALS_VIA_CHARACTERS, but not (TIOCGLTC && TIOCGETC) || TCGETA
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 /* If your system configuration files define SIGNALS_VIA_CHARACTERS,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 you'd better be using one of the alternatives above! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 # endif /* ! defined (TCGETA) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 return '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 #endif /* SIGNALS_VIA_CHARACTERS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 /* send a signal number SIGNO to PROCESS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665 CURRENT_GROUP means send to the process group that currently owns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 the terminal being used to communicate with PROCESS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 This is used for various commands in shell mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 If NOMSG is zero, insert signal-announcements into process's buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 right away.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 If we can, we try to signal PROCESS by sending control characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 down the pty. This allows us to signal inferiors who have changed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673 their uid, for which killpg would return an EPERM error. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 process_send_signal (Lisp_Object process0, int signo,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 int current_group, int nomsg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680 Lisp_Object proc = get_process (process0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 struct Lisp_Process *p = XPROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682 int gid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 int no_pgrp = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 if (network_connection_p (proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 error ("Network connection %s is not a subprocess",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 string_data (XSTRING (p->name)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688 if (p->infd < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689 error ("Process %s is not active",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690 string_data (XSTRING (p->name)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 if (!p->pty_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 current_group = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 /* If we are using pgrps, get a pgrp number and make it negative. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696 if (current_group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2698 #ifdef SIGNALS_VIA_CHARACTERS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699 /* If possible, send signals to the entire pgrp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700 by sending an input character to it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2702 char sigchar = process_signal_char(p->subtty, signo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703 if (sigchar) {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704 send_process (proc, Qnil, (Bufbyte *) &sigchar, 0, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708 #endif /* ! defined (SIGNALS_VIA_CHARACTERS) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710 #ifdef TIOCGPGRP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711 /* Get the pgrp using the tty itself, if we have that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2712 Otherwise, use the pty to get the pgrp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 On pfa systems, saka@pfu.fujitsu.co.JP writes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714 "TIOCGPGRP symbol defined in sys/ioctl.h at E50.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2715 But, TIOCGPGRP does not work on E50 ;-P works fine on E60"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 His patch indicates that if TIOCGPGRP returns an error, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717 we should just assume that p->pid is also the process group id. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 int err;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721 err = ioctl ( (p->subtty != -1 ? p->subtty : p->infd), TIOCGPGRP, &gid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2723 #ifdef pfa
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2724 if (err == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2725 gid = - XINT (p->pid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2726 #endif /* ! defined (pfa) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2727 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728 if (gid == -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 no_pgrp = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731 gid = - gid;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 #else /* ! defined (TIOCGPGRP ) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 /* Can't select pgrps on this system, so we know that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734 the child itself heads the pgrp. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735 gid = - XINT (p->pid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2736 #endif /* ! defined (TIOCGPGRP ) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2737 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2738 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 gid = - XINT (p->pid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741 switch (signo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743 #ifdef SIGCONT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 case SIGCONT:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745 p->status_symbol = Qrun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746 p->exit_code = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2747 p->tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2748 process_tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749 if (!nomsg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750 status_notify ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 #endif /* ! defined (SIGCONT) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 case SIGINT:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755 send_process (proc, Qnil, (Bufbyte *) "\003", 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756 1); /* ^C */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757 goto whoosh;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759 case SIGQUIT:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761 send_process (proc, Qnil, (Bufbyte *) "\031", 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762 1); /* ^Y */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763 goto whoosh;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2764 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2765 case SIGKILL:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767 sys$forcex (&(XINT (p->pid)), 0, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768 whoosh:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2770 flush_pending_output (p->infd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2773
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2774 /* If we don't have process groups, send the signal to the immediate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2775 subprocess. That isn't really right, but it's better than any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 obvious alternative. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2777 if (no_pgrp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2778 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2779 kill (XINT (p->pid), signo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2780 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2781 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783 /* gid may be a pid, or minus a pgrp's number */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 #ifdef TIOCSIGSEND
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785 if (current_group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786 ioctl (p->infd, TIOCSIGSEND, signo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2787 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2789 gid = - XINT (p->pid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2790 kill (gid, signo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2791 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792 #else /* ! defined (TIOCSIGSEND) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793 EMACS_KILLPG (-gid, signo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2794 #endif /* ! defined (TIOCSIGSEND) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2795 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2796
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2797 DEFUN ("interrupt-process", Finterrupt_process, Sinterrupt_process, 0, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2798 Interrupt process PROCESS. May be process or name of one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2799 Nil or no arg means current buffer's process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800 Second arg CURRENT-GROUP non-nil means send signal to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801 the current process-group of the process's controlling terminal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 rather than to the process's own process group.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2803 If the process is a shell, this means interrupt current subjob
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2804 rather than the shell.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2805 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806 (process, current_group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807 Lisp_Object process, current_group;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2809 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810 process_send_signal (process, SIGINT, !NILP (current_group), 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2811 return process;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2812 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2813
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2814 DEFUN ("kill-process", Fkill_process, Skill_process, 0, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2815 Kill process PROCESS. May be process or name of one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2816 See function `interrupt-process' for more details on usage.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2817 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2818 (process, current_group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2819 Lisp_Object process, current_group;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2820 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2821 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2822 process_send_signal (process, SIGKILL, !NILP (current_group),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2823 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2824 return process;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2825 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2826
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2827 DEFUN ("quit-process", Fquit_process, Squit_process, 0, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2828 Send QUIT signal to process PROCESS. May be process or name of one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2829 See function `interrupt-process' for more details on usage.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2830 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2831 (process, current_group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2832 Lisp_Object process, current_group;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2833 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2834 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2835 process_send_signal (process, SIGQUIT, !NILP (current_group),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2836 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837 return process;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2840 DEFUN ("stop-process", Fstop_process, Sstop_process, 0, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 Stop process PROCESS. May be process or name of one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 See function `interrupt-process' for more details on usage.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2843 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2844 (process, current_group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2845 Lisp_Object process, current_group;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2846 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2847 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2848 #ifndef SIGTSTP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849 error ("no SIGTSTP support");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2850 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851 process_send_signal (process, SIGTSTP, !NILP (current_group),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 return process;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 DEFUN ("continue-process", Fcontinue_process, Scontinue_process, 0, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 Continue process PROCESS. May be process or name of one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859 See function `interrupt-process' for more details on usage.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 (process, current_group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 Lisp_Object process, current_group;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2864 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2865 #ifdef SIGCONT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2866 process_send_signal (process, SIGCONT, !NILP (current_group),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2868 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2869 error ("no SIGCONT support");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2871 return process;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2872 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2873
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2874 DEFUN ("signal-process", Fsignal_process, Ssignal_process,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2875 2, 2, "nProcess number: \nnSignal code: " /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2876 Send the process with process id PID the signal with code SIGCODE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2877 PID must be an integer. The process need not be a child of this Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2878 SIGCODE may be an integer, or a symbol whose name is a signal name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2879 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2880 (pid, sigcode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2881 Lisp_Object pid, sigcode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2882 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2883 CHECK_INT (pid);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2884
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2885 #define handle_signal(NAME, VALUE) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2886 else if (!strcmp ((CONST char *) name, NAME)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2887 XSETINT (sigcode, VALUE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2888
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2889 if (INTP (sigcode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2890 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2891 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2892 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2893 Bufbyte *name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2894
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2895 CHECK_SYMBOL (sigcode);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2896 name = string_data (XSYMBOL (sigcode)->name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2897
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2898 if (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2899 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2900 #ifdef SIGHUP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2901 handle_signal ("SIGHUP", SIGHUP);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2902 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2903 #ifdef SIGINT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2904 handle_signal ("SIGINT", SIGINT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2905 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2906 #ifdef SIGQUIT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2907 handle_signal ("SIGQUIT", SIGQUIT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2908 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2909 #ifdef SIGILL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2910 handle_signal ("SIGILL", SIGILL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2911 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2912 #ifdef SIGABRT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2913 handle_signal ("SIGABRT", SIGABRT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2914 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2915 #ifdef SIGEMT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2916 handle_signal ("SIGEMT", SIGEMT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2917 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2918 #ifdef SIGKILL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2919 handle_signal ("SIGKILL", SIGKILL);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2920 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2921 #ifdef SIGFPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2922 handle_signal ("SIGFPE", SIGFPE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2923 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2924 #ifdef SIGBUS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2925 handle_signal ("SIGBUS", SIGBUS);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2926 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2927 #ifdef SIGSEGV
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2928 handle_signal ("SIGSEGV", SIGSEGV);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2929 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2930 #ifdef SIGSYS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2931 handle_signal ("SIGSYS", SIGSYS);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2932 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2933 #ifdef SIGPIPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2934 handle_signal ("SIGPIPE", SIGPIPE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2935 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2936 #ifdef SIGALRM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2937 handle_signal ("SIGALRM", SIGALRM);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2938 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2939 #ifdef SIGTERM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2940 handle_signal ("SIGTERM", SIGTERM);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2941 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2942 #ifdef SIGURG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2943 handle_signal ("SIGURG", SIGURG);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2944 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2945 #ifdef SIGSTOP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2946 handle_signal ("SIGSTOP", SIGSTOP);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2947 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2948 #ifdef SIGTSTP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2949 handle_signal ("SIGTSTP", SIGTSTP);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2950 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2951 #ifdef SIGCONT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2952 handle_signal ("SIGCONT", SIGCONT);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2953 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2954 #ifdef SIGCHLD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2955 handle_signal ("SIGCHLD", SIGCHLD);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2956 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2957 #ifdef SIGTTIN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2958 handle_signal ("SIGTTIN", SIGTTIN);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2959 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2960 #ifdef SIGTTOU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2961 handle_signal ("SIGTTOU", SIGTTOU);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2962 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2963 #ifdef SIGIO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2964 handle_signal ("SIGIO", SIGIO);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2965 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2966 #ifdef SIGXCPU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2967 handle_signal ("SIGXCPU", SIGXCPU);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2968 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2969 #ifdef SIGXFSZ
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2970 handle_signal ("SIGXFSZ", SIGXFSZ);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2971 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2972 #ifdef SIGVTALRM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2973 handle_signal ("SIGVTALRM", SIGVTALRM);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2974 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2975 #ifdef SIGPROF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2976 handle_signal ("SIGPROF", SIGPROF);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2977 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2978 #ifdef SIGWINCH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2979 handle_signal ("SIGWINCH", SIGWINCH);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2980 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2981 #ifdef SIGINFO
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2982 handle_signal ("SIGINFO", SIGINFO);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2983 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2984 #ifdef SIGUSR1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2985 handle_signal ("SIGUSR1", SIGUSR1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2986 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2987 #ifdef SIGUSR2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2988 handle_signal ("SIGUSR2", SIGUSR2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2989 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2990 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2991 error ("Undefined signal name %s", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2992 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2994 #undef handle_signal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2995
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2996 #ifdef WINDOWSNT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2997 /* Only works for kill-type signals */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2998 return make_int (win32_kill_process (XINT (pid), XINT (sigcode)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2999 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3000 return make_int (kill (XINT (pid), XINT (sigcode)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3001 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3002 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3003
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3004 DEFUN ("process-send-eof", Fprocess_send_eof, Sprocess_send_eof, 0, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3005 Make PROCESS see end-of-file in its input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3006 PROCESS may be a process, a buffer, the name of a process or buffer, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3007 nil, indicating the current buffer's process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3008 If PROCESS is a network connection, or is a process communicating
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3009 through a pipe (as opposed to a pty), then you cannot send any more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3010 text to PROCESS after you call this function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3011 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3012 (process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3013 Lisp_Object process;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3014 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3015 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3016 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3017
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3018 proc = get_process (process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3019
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3020 /* Make sure the process is really alive. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3021 if (! EQ (XPROCESS (proc)->status_symbol, Qrun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3022 error ("Process %s not running",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3023 string_data (XSTRING (XPROCESS (proc)->name)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3024
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3025 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3026 send_process (proc, Qnil, (Bufbyte *) "\032", 0, 1); /* ^Z */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3027 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3028 if (XPROCESS (proc)->pty_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3029 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3030 /* #### get_eof_char simply doesn't return the correct character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3031 here. Maybe it is needed to determine the right eof
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3032 character in init_process_fds but here it simply screws
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3033 things up. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3034 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3035 Bufbyte eof_char = get_eof_char (XPROCESS (proc));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3036 send_process (proc, Qnil, &eof_char, 0, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3037 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3038 send_process (proc, Qnil, (CONST Bufbyte *) "\004", 0, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3039 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3040 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3041 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3042 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3043 close (XPROCESS (proc)->outfd);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3044 XPROCESS (proc)->outfd = open (NULL_DEVICE, O_WRONLY, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3045 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3046 #endif /* !VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3047 return process;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3048 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3049
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3050
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3051 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3052 /* deleting a process */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3053 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3054
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3055 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3056 deactivate_process (Lisp_Object proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3057 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3058 int inchannel, outchannel;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3059 struct Lisp_Process *p = XPROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3060 SIGTYPE (*old_sigpipe) (int) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3061
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3062 inchannel = p->infd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3063 outchannel = p->outfd;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3064
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3065 /* closing the outstream could result in SIGPIPE, so ignore it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3066 old_sigpipe =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3067 (SIGTYPE (*) (int)) signal (SIGPIPE, SIG_IGN);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3068 if (!NILP (p->instream))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3069 Lstream_close (XLSTREAM (p->instream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3070 if (!NILP (p->outstream))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3071 Lstream_close (XLSTREAM (p->outstream));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3072 signal (SIGPIPE, old_sigpipe);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3073
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3074 if (inchannel >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3075 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3076 /* Beware SIGCHLD hereabouts. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3077 flush_pending_output (inchannel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3078 close_descriptor_pair (inchannel, outchannel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3079 if (!NILP (p->pid))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3080 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3081 /* It's possible that we got as far in the process-creation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3082 process as creating the descriptors but didn't get so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3083 far as selecting the process for input. In this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3084 case, p->pid is nil: p->pid is set at the same time that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3085 the process is selected for input. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3086 #ifdef VMS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3087 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3088 VMS_PROC_STUFF *get_vms_process_pointer (), *vs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3089 if (outchannel >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3090 sys$dassgn (outchannel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3091 vs = get_vms_process_pointer (XINT (p->pid));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3092 if (vs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3093 give_back_vms_process_stuff (vs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3094 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3095 #endif /* VMS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3096 /* Must call this before setting the file descriptors to 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3097 event_stream_unselect_process (p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3098 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3099
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3100 p->infd = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3101 p->outfd = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3102 descriptor_to_process[inchannel] = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3103 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3104 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3106 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3107 remove_process (Lisp_Object proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3108 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3109 Vprocess_list = delq_no_quit (proc, Vprocess_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3110 Fset_marker (XPROCESS (proc)->mark, Qnil, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3112 deactivate_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3113 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3115 DEFUN ("delete-process", Fdelete_process, Sdelete_process, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3116 Delete PROCESS: kill it and forget about it immediately.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3117 PROCESS may be a process or the name of one, or a buffer name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3118 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3119 (proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3120 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3121 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3122 /* This function can GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3123 struct Lisp_Process *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3124 proc = get_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3125 p = XPROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3126 if (network_connection_p (proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3127 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3128 p->status_symbol = Qexit;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3129 p->exit_code = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3130 p->core_dumped = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3131 p->tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3132 process_tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3133 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3134 else if (p->infd >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3135 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3136 Fkill_process (proc, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3137 /* Do this now, since remove_process will make sigchld_handler do nothing. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3138 p->status_symbol = Qsignal;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3139 p->exit_code = SIGKILL;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3140 p->core_dumped = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3141 p->tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3142 process_tick++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3143 status_notify ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3144 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3145 remove_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3146 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3147 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3149 /* Kill all processes associated with `buffer'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3150 If `buffer' is nil, kill all processes */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3152 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3153 kill_buffer_processes (Lisp_Object buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3154 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3155 Lisp_Object tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3157 for (tail = Vprocess_list; GC_CONSP (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3158 tail = XCDR (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3159 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3160 Lisp_Object proc = XCAR (tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3161 if (GC_PROCESSP (proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3162 && (GC_NILP (buffer) || GC_EQ (XPROCESS (proc)->buffer, buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3163 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3164 if (network_connection_p (proc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3165 Fdelete_process (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3166 else if (XPROCESS (proc)->infd >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3167 process_send_signal (proc, SIGHUP, 0, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3168 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3169 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3170 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3172 #if 0 /* Unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3173 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3174 count_active_processes (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3175 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3176 Lisp_Object tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3177 int count = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3179 for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3180 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3181 Lisp_Object status = XPROCESS (XCAR (tail))->status_symbol;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3182 if ((EQ (status, Qrun) || EQ (status, Qstop)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3183 count++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3184 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3186 return count;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3187 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3188 #endif /* Unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3190 DEFUN ("process-kill-without-query", Fprocess_kill_without_query,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3191 Sprocess_kill_without_query, 1, 2, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3192 Say no query needed if PROCESS is running when Emacs is exited.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3193 Optional second argument if non-nil says to require a query.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3194 Value is t if a query was formerly required.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3195 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3196 (proc, require_query_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3197 Lisp_Object proc, require_query_p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3198 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3199 int tem;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3201 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3202 tem = XPROCESS (proc)->kill_without_query;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3203 XPROCESS (proc)->kill_without_query = NILP (require_query_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3205 return (tem ? Qnil : Qt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3206 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3208 DEFUN ("process-kill-without-query-p", Fprocess_kill_without_query_p,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3209 Sprocess_kill_without_query_p, 1, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3210 Whether PROC will be killed without query if running when emacs is exited.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3211 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3212 (proc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3213 Lisp_Object proc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3214 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3215 CHECK_PROCESS (proc);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3216 return (XPROCESS (proc)->kill_without_query ? Qt : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3217 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3220 /* This is not named init_process in order to avoid a conflict with NS 3.3 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3221 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3222 init_xemacs_process (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3223 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3224 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3226 #ifdef SIGCHLD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3227 # ifndef CANNOT_DUMP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3228 if (! noninteractive || initialized)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3229 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3230 signal (SIGCHLD, sigchld_handler);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3231 #endif /* SIGCHLD */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3233 Vprocess_list = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3234 for (i = 0; i < MAXDESC; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3235 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3236 descriptor_to_process[i] = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3237 proc_buffered_char[i] = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3238 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3239 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3240 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3242 xxDEFUN ("process-connection", Fprocess_connection, Sprocess_connection,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3243 0, 1, 0 /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3244 Return the connection type of `PROCESS'. This can be nil (pipe),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3245 t or pty (pty) or stream (socket connection).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3246 */ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3247 (process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3248 Lisp_Object process;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3249 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3250 return XPROCESS (process)->type;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3251 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3253 #endif /* 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3255 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3256 syms_of_process (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3257 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3258 defsymbol (&Qprocessp, "processp");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3259 defsymbol (&Qrun, "run");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3260 defsymbol (&Qstop, "stop");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3261 defsymbol (&Qsignal, "signal");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3262 /* Qexit is already defined by syms_of_eval
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3263 * defsymbol (&Qexit, "exit");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3264 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3265 defsymbol (&Qopen, "open");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3266 defsymbol (&Qclosed, "closed");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3268 defsubr (&Sprocessp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3269 defsubr (&Sget_process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3270 defsubr (&Sget_buffer_process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3271 defsubr (&Sdelete_process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3272 defsubr (&Sprocess_status);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3273 defsubr (&Sprocess_exit_status);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3274 defsubr (&Sprocess_id);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3275 defsubr (&Sprocess_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3276 defsubr (&Sprocess_tty_name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3277 defsubr (&Sprocess_command);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3278 defsubr (&Sset_process_buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3279 defsubr (&Sprocess_buffer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3280 defsubr (&Sprocess_mark);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3281 defsubr (&Sset_process_filter);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3282 defsubr (&Sprocess_filter);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3283 defsubr (&Sset_process_window_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3284 defsubr (&Sset_process_sentinel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3285 defsubr (&Sprocess_sentinel);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3286 defsubr (&Sprocess_kill_without_query);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3287 defsubr (&Sprocess_kill_without_query_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3288 defsubr (&Sprocess_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3289 defsubr (&Sstart_process_internal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3290 #ifdef HAVE_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3291 defsubr (&Sopen_network_stream_internal);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3292 #endif /* HAVE_SOCKETS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3293 defsubr (&Sprocess_send_region);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3294 defsubr (&Sprocess_send_string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3295 defsubr (&Sinterrupt_process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3296 defsubr (&Skill_process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3297 defsubr (&Squit_process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3298 defsubr (&Sstop_process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3299 defsubr (&Scontinue_process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3300 defsubr (&Sprocess_send_eof);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3301 defsubr (&Ssignal_process);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3302 /* defsubr (&Sprocess_connection); */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3303 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3305 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3306 vars_of_process (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3307 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3308 Fprovide (intern ("subprocesses"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3309 #ifdef HAVE_SOCKETS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3310 Fprovide (intern ("network-streams"));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3311 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3312 staticpro (&Vprocess_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3314 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3315 *Non-nil means delete processes immediately when they exit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3316 nil means don't delete them until `list-processes' is run.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3317 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3319 delete_exited_processes = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3321 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3322 Control type of device used to communicate with subprocesses.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3323 Values are nil to use a pipe, or t or `pty' to use a pty.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3324 The value has no effect if the system has no ptys or if all ptys are busy:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3325 then a pipe is used in any case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3326 The value takes effect when `start-process' is called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3327 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3328 Vprocess_connection_type = Qt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3329 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3330
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3331 #endif /* not NO_SUBPROCESSES */