annotate src/process.c @ 82:6a378aca36af r20-0b91

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