annotate src/process.c @ 114:8619ce7e4c50 r20-1b9

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