annotate src/process.c @ 5896:2865c4f6fab2

Fix shell syntax error.
author Stephen J. Turnbull <stephen@xemacs.org>
date Tue, 05 May 2015 03:48:07 +0900
parents d93195c2c906
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Asynchronous subprocess control for XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1987, 1988, 1992, 1993, 1994, 1995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 Copyright (C) 1995 Sun Microsystems, Inc.
5125
Ben Wing <ben@xemacs.org>
parents: 5124 5013
diff changeset
5 Copyright (C) 1995, 1996, 2001, 2002, 2004, 2005, 2010 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5255
diff changeset
9 XEmacs is free software: you can redistribute it and/or modify it
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5255
diff changeset
11 Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5255
diff changeset
12 option) any later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5255
diff changeset
20 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
22 /* This file has been Mule-ized. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 /* This file has been split into process.c and process-unix.c by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 Kirill M. Katsnelson <kkm@kis.ru>, so please bash him and not
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
26 the original author(s).
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
27
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
28 Non-synch-subprocess stuff (mostly process environment) moved from
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
29 callproc.c, 4-3-02, Ben Wing.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
30
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
31 callproc.c deleted entirely 5-23-02, Ben Wing. Good riddance!
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
32 */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 #include "commands.h"
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
40 #include "device.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 #include "events.h"
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
42 #include "file-coding.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 #include "frame.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 #include "hash.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 #include "insdel.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 #include "lstream.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 #include "opaque.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 #include "process.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 #include "procimpl.h"
816
39b1580316c8 [xemacs-hg @ 2002-04-15 09:42:17 by ben]
ben
parents: 814
diff changeset
50 #include "sysdep.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 #include "window.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 #include "sysfile.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 #include "sysproc.h"
859
84762348c6f9 [xemacs-hg @ 2002-06-01 08:06:46 by ben]
ben
parents: 854
diff changeset
55 #include "syssignal.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 #include "systime.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 #include "systty.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 #include "syswait.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
60 #ifdef WIN32_NATIVE
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
61 #include "syswindows.h"
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
62 #endif
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
63
863
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
64 Lisp_Object Qprocessp, Qprocess_live_p, Qprocess_readable_p;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 /* Process methods */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 struct process_methods the_process_methods;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 /* a process object is a network connection when its pid field a cons
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 (name of name of port we are connected to . foreign host name) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 /* Valid values of process->status_symbol */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 Lisp_Object Qrun, Qstop;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 /* Qrun => Qopen, Qexit => Qclosed for "network connection" processes */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 Lisp_Object Qopen, Qclosed;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 /* Protocol families */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 Lisp_Object Qtcp, Qudp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 #ifdef HAVE_MULTICAST
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 Lisp_Object Qmulticast; /* Will be used for occasional warnings */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 /* t means use pty, nil means use a pipe,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 maybe other values to come. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 Lisp_Object Vprocess_connection_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 /* Read comments to DEFVAR of this */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 int windowed_process_io;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 #ifdef PROCESS_IO_BLOCKING
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 /* List of port numbers or port names to set a blocking I/O mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 Nil means set a non-blocking I/O mode [default]. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 Lisp_Object network_stream_blocking_port_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 #endif /* PROCESS_IO_BLOCKING */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 /* Number of events of change of status of a process. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 volatile int process_tick;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 /* Number of events for which the user or sentinel has been notified. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 static int update_tick;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 /* Nonzero means delete a process right away if it exits. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 int delete_exited_processes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
105 /* Hash table which maps USIDs as returned by create_io_streams_cb to
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 process objects. Processes are not GC-protected through this! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 struct hash_table *usid_to_process;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108
4729
428d7c571110 Fix issue145: accept nil in default-process-coding-system.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4693
diff changeset
109 /* Read-only to Lisp. See DEFUN Fprocess_list. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 Lisp_Object Vprocess_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111
4729
428d7c571110 Fix issue145: accept nil in default-process-coding-system.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4693
diff changeset
112 /* Lisp variables; see docstrings below. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
113 Lisp_Object Vnull_device;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
114 Lisp_Object Vdefault_process_coding_system;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
115 Lisp_Object Vdefault_network_coding_system;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
116 Lisp_Object Qprocess_error;
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
117 Lisp_Object Qnetwork_error;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
118 Fixnum debug_process_io;
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
119 Lisp_Object Vshell_file_name;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
120 Lisp_Object Vprocess_environment;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
121
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
122 /* Make sure egetenv() not called too soon */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
123 int env_initted;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
124
4729
428d7c571110 Fix issue145: accept nil in default-process-coding-system.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4693
diff changeset
125 /* Internal Lisp variable. */
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
126 Lisp_Object Vlisp_EXEC_SUFFIXES;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
127
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 934
diff changeset
130 static const struct memory_description process_description [] = {
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 934
diff changeset
131 #define MARKED_SLOT(x) { XD_LISP_OBJECT, offsetof (Lisp_Process, x) },
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 934
diff changeset
132 #include "process-slots.h"
934
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 910
diff changeset
133 { XD_END }
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 910
diff changeset
134 };
c925bacdda60 [xemacs-hg @ 2002-07-29 09:21:12 by michaels]
michaels
parents: 910
diff changeset
135
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 static Lisp_Object
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
137 mark_process (Lisp_Object object)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
139 Lisp_Process *process = XPROCESS (object);
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 934
diff changeset
140 #define MARKED_SLOT(x) mark_object (process->x);
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 934
diff changeset
141 #include "process-slots.h"
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 934
diff changeset
142 return Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144
5814
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
145 static int
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
146 tls_connection_p (Lisp_Object process)
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
147 {
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
148 Lisp_Process *p = XPROCESS (process);
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
149 Lstream *in = XLSTREAM (DATA_INSTREAM (p));
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
150 Lstream *out = XLSTREAM (DATA_OUTSTREAM (p));
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
151 return Lstream_tls_p (in) || Lstream_tls_p (out);
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
152 }
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
153
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 static void
4846
a98ca4640147 clean up object print methods
Ben Wing <ben@xemacs.org>
parents: 4834
diff changeset
155 print_process (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 {
4846
a98ca4640147 clean up object print methods
Ben Wing <ben@xemacs.org>
parents: 4834
diff changeset
157 Lisp_Process *process = XPROCESS (obj);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 if (print_readably)
5142
f965e31a35f0 reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents: 5127
diff changeset
160 printing_unreadable_lisp_object (obj, XSTRING_DATA (process->name));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 if (!escapeflag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
164 print_internal (process->name, printcharfun, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 {
4846
a98ca4640147 clean up object print methods
Ben Wing <ben@xemacs.org>
parents: 4834
diff changeset
168 int netp = network_connection_p (obj);
5814
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
169 int tlsp = netp && tls_connection_p (obj);
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4932
diff changeset
170 write_ascstring (printcharfun,
5814
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
171 tlsp ? GETTEXT ("#<tls network connection ") :
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
172 (netp ? GETTEXT ("#<network connection ") :
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
173 GETTEXT ("#<process ")));
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
174 print_internal (process->name, printcharfun, 1);
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4932
diff changeset
175 write_ascstring (printcharfun, (netp ? " " : " pid "));
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
176 print_internal (process->pid, printcharfun, 1);
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
177 write_fmt_string_lisp (printcharfun, " state:%S", 1, process->status_symbol);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
178 MAYBE_PROCMETH (print_process_data, (process, printcharfun));
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4932
diff changeset
179 write_ascstring (printcharfun, ">");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 }
5255
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
182 /* Process plists are directly accessible, so we need to protect against
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
183 invalid property list structure */
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
184
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
185 static Lisp_Object
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
186 process_getprop (Lisp_Object process, Lisp_Object property)
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
187 {
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
188 return external_plist_get (&XPROCESS (process)->plist, property, 0,
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
189 ERROR_ME);
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
190 }
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
191
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
192 static int
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
193 process_putprop (Lisp_Object process, Lisp_Object property, Lisp_Object value)
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
194 {
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
195 external_plist_put (&XPROCESS (process)->plist, property, value, 0,
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
196 ERROR_ME);
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
197 return 1;
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
198 }
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
199
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
200 static int
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
201 process_remprop (Lisp_Object process, Lisp_Object property)
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
202 {
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
203 return external_remprop (&XPROCESS (process)->plist, property, 0, ERROR_ME);
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
204 }
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
205
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
206 static Lisp_Object
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
207 process_plist (Lisp_Object process)
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
208 {
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
209 return XPROCESS (process)->plist;
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
210 }
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
211
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
212 static Lisp_Object
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
213 process_setplist (Lisp_Object process, Lisp_Object newplist)
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
214 {
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
215 XPROCESS (process)->plist = newplist;
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
216 return newplist;
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
217 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 #ifdef HAVE_WINDOW_SYSTEM
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
220 extern void debug_process_finalization (Lisp_Process *p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 #endif /* HAVE_WINDOW_SYSTEM */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 static void
5127
a9c41067dd88 more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents: 5125
diff changeset
224 finalize_process (Lisp_Object obj)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 /* #### this probably needs to be tied into the tty event loop */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 /* #### when there is one */
5127
a9c41067dd88 more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents: 5125
diff changeset
228 Lisp_Process *p = XPROCESS (obj);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 #ifdef HAVE_WINDOW_SYSTEM
5124
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5118
diff changeset
230 debug_process_finalization (p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 #endif /* HAVE_WINDOW_SYSTEM */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 if (p->process_data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 {
5124
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5118
diff changeset
235 MAYBE_PROCMETH (finalize_process_data, (p));
5125
Ben Wing <ben@xemacs.org>
parents: 5124 5013
diff changeset
236 xfree (p->process_data);
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5142
diff changeset
237 p->process_data = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240
5118
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4759
diff changeset
241 DEFINE_NODUMP_LISP_OBJECT ("process", process,
5124
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5118
diff changeset
242 mark_process, print_process, finalize_process,
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5118
diff changeset
243 0, 0, process_description, Lisp_Process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 /* basic process accessors */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
249 /* This function returns low-level streams, connected directly to the child
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
250 process, rather than en/decoding streams */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 void
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
252 get_process_streams (Lisp_Process *p, Lisp_Object *instr, Lisp_Object *outstr,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
253 Lisp_Object *errstr)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 assert (p);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
256 assert (NILP (p->pipe_instream) || LSTREAMP (p->pipe_instream));
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
257 assert (NILP (p->pipe_outstream) || LSTREAMP (p->pipe_outstream));
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
258 assert (NILP (p->pipe_errstream) || LSTREAMP (p->pipe_errstream));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 *instr = p->pipe_instream;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 *outstr = p->pipe_outstream;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
261 *errstr = p->pipe_errstream;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
264 /* Given a USID referring to either a process's instream or errstream,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
265 return the associated process. */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
266 Lisp_Process *
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 get_process_from_usid (USID usid)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
269 const void *vval;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 assert (usid != USID_ERROR && usid != USID_DONTHASH);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
273 if (gethash ((const void*)usid, usid_to_process, &vval))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
275 Lisp_Object process;
5013
ae48681c47fa changes to VOID_TO_LISP et al.
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
276 process = GET_LISP_FROM_VOID (vval);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
277 return XPROCESS (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 int
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
284 get_process_selected_p (Lisp_Process *p, int do_err)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 {
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
286 return do_err ? p->err_selected : p->in_selected;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 void
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
290 set_process_selected_p (Lisp_Process *p, int in_selected, int err_selected)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 {
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
292 p->in_selected = !!in_selected;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
293 p->err_selected = !!err_selected;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 int
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
297 connected_via_filedesc_p (Lisp_Process *p)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 return MAYBE_INT_PROCMETH (tooltalk_connection_p, (p));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 #ifdef HAVE_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 network_connection_p (Lisp_Object process)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 return CONSP (XPROCESS (process)->pid);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 DEFUN ("processp", Fprocessp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 Return t if OBJECT is a process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
313 (object))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
315 return PROCESSP (object) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
318 DEFUN ("process-live-p", Fprocess_live_p, 1, 1, 0, /*
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
319 Return t if OBJECT is a process that is alive.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
320 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
321 (object))
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
322 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
323 return PROCESSP (object) && PROCESS_LIVE_P (XPROCESS (object))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
324 ? Qt : Qnil;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
325 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
326
863
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
327 #if 0
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
328 /* This is a reasonable definition for this new primitive. Kyle sez:
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
329
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
330 "The patch looks OK to me except for the creation and exporting of the
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
331 Fprocess_readable_p function. I don't think a new Lisp function
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
332 should be created until we know something actually needs it. If
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
333 we later want to give process-readable-p different semantics it
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
334 may be hard to do it and stay compatible with what we hastily
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
335 create today."
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
336
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
337 He's right, not yet. Let's discuss the semantics on XEmacs Design
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
338 before enabling this.
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
339 */
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
340 DEFUN ("process-readable-p", Fprocess_readable_p, 1, 1, 0, /*
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
341 Return t if OBJECT is a process from which input may be available.
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
342 */
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
343 (object))
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
344 {
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
345 return PROCESSP (object) && PROCESS_READABLE_P (XPROCESS (object))
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
346 ? Qt : Qnil;
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
347 }
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
348 #endif
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
349
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 DEFUN ("process-list", Fprocess_list, 0, 0, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 Return a list of all processes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 return Fcopy_sequence (Vprocess_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 DEFUN ("get-process", Fget_process, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
359 Return the process named PROCESS-NAME (a string), or nil if there is none.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
360 PROCESS-NAME may also be a process; if so, the value is that process.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
362 (process_name))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
364 if (PROCESSP (process_name))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
365 return process_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 if (!gc_in_progress)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 /* this only gets called during GC when emacs is going away as a result
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 of a signal or crash. */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
370 CHECK_STRING (process_name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
372 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
373 LIST_LOOP_2 (process, Vprocess_list)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
374 if (internal_equal (process_name, XPROCESS (process)->name, 0))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
375 return process;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
376 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 DEFUN ("get-buffer-process", Fget_buffer_process, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 Return the (or, a) process associated with BUFFER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 BUFFER may be a buffer or the name of one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
384 (buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
386 if (NILP (buffer)) return Qnil;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
387 buffer = Fget_buffer (buffer);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
388 if (NILP (buffer)) return Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
390 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
391 LIST_LOOP_2 (process, Vprocess_list)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
392 if (EQ (XPROCESS (process)->buffer, buffer))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
393 return process;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
394 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 /* This is how commands for the user decode process arguments. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 accepts a process, a process name, a buffer, a buffer name, or nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 Buffers denote the first process in the buffer, and nil denotes the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 current buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 get_process (Lisp_Object name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
406 Lisp_Object buffer;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 #ifdef I18N3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 /* #### Look more closely into translating process names. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 /* This may be called during a GC from process_send_signal() from
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2367
diff changeset
413 kill_buffer_processes() if emacs decides to ABORT(). */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 if (PROCESSP (name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 return name;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
416 else if (STRINGP (name))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
418 Lisp_Object object = Fget_process (name);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
419 if (PROCESSP (object))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
420 return object;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
421
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
422 buffer = Fget_buffer (name);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
423 if (BUFFERP (buffer))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
424 goto have_buffer_object;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
425
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
426 invalid_argument ("Process does not exist", name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 else if (NILP (name))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
429 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
430 buffer = Fcurrent_buffer ();
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
431 goto have_buffer_object;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
432 }
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
433 else if (BUFFERP (name))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
434 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
435 Lisp_Object process;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
436 buffer = name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
438 have_buffer_object:
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
439 process = Fget_buffer_process (buffer);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
440 if (PROCESSP (process))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
441 return process;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
442
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
443 invalid_argument ("Buffer has no process", buffer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 else
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
446 return get_process (Fsignal (Qwrong_type_argument,
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
447 (list2 (build_msg_string ("process or buffer or nil"),
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
448 name))));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 DEFUN ("process-id", Fprocess_id, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 Return the process id of PROCESS.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 This is the pid of the Unix process which PROCESS uses or talks to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 For a network connection, this value is a cons of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 (foreign-network-port . foreign-host-name).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
457 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 Lisp_Object pid;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
460 CHECK_PROCESS (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
462 pid = XPROCESS (process)->pid;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
463 if (network_connection_p (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 /* return Qnil; */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 return Fcons (Fcar (pid), Fcdr (pid));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 return pid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 DEFUN ("process-name", Fprocess_name, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 Return the name of PROCESS, as a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 This is the name of the program invoked in PROCESS,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 possibly modified to make it unique among process names.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
475 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
477 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
478 return XPROCESS (process)->name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 DEFUN ("process-command", Fprocess_command, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 Return the command that was executed to start PROCESS.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 This is a list of strings, the first string being the program executed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 and the rest of the strings being the arguments given to it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
486 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
488 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
489 return XPROCESS (process)->command;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 /* creating a process */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
497 DOESNT_RETURN
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4932
diff changeset
498 report_process_error (const Ascbyte *reason, Lisp_Object data)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
499 {
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4932
diff changeset
500 report_error_with_errno (Qprocess_error, reason, data);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
501 }
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
502
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
503 DOESNT_RETURN
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4932
diff changeset
504 report_network_error (const Ascbyte *reason, Lisp_Object data)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
505 {
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4932
diff changeset
506 report_error_with_errno (Qnetwork_error, reason, data);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
507 }
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
508
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 make_process_internal (Lisp_Object name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 {
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3025
diff changeset
512 Lisp_Object name1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 int i;
5127
a9c41067dd88 more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents: 5125
diff changeset
514 Lisp_Object obj = ALLOC_NORMAL_LISP_OBJECT (process);
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3025
diff changeset
515 Lisp_Process *p = XPROCESS (obj);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 934
diff changeset
517 #define MARKED_SLOT(x) p->x = Qnil;
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 934
diff changeset
518 #include "process-slots.h"
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 934
diff changeset
519
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 /* If name is already in use, modify it until it is unused. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 name1 = name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 for (i = 1; ; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 {
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4932
diff changeset
524 Ascbyte suffix[10];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 Lisp_Object tem = Fget_process (name1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 if (NILP (tem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 sprintf (suffix, "<%d>", i);
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4932
diff changeset
529 name1 = concat2 (name, build_ascstring (suffix));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 name = name1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 p->name = name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 p->mark = Fmake_marker ();
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
535 p->stderr_mark = Fmake_marker ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 p->status_symbol = Qrun;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 MAYBE_PROCMETH (alloc_process_data, (p));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3025
diff changeset
540 Vprocess_list = Fcons (obj, Vprocess_list);
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3025
diff changeset
541 return obj;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 void
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
545 init_process_io_handles (Lisp_Process *p, void* in, void* out, void* err,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
546 int flags)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 {
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
548 USID in_usid, err_usid;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
549 Lisp_Object incode, outcode;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
550
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
551 if (flags & STREAM_NETWORK_CONNECTION)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
552 {
4729
428d7c571110 Fix issue145: accept nil in default-process-coding-system.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4693
diff changeset
553 if (!LISTP (Vdefault_network_coding_system) ||
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
554 NILP (incode = (find_coding_system_for_text_file
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
555 (Fcar (Vdefault_network_coding_system), 1))) ||
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
556 NILP (outcode = (find_coding_system_for_text_file
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
557 (Fcdr (Vdefault_network_coding_system), 0))))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
558 signal_error (Qinvalid_state,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
559 "Bogus value for `default-network-coding-system'",
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
560 Vdefault_network_coding_system);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
561 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
562 else
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
563 {
4729
428d7c571110 Fix issue145: accept nil in default-process-coding-system.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4693
diff changeset
564 if (!LISTP (Vdefault_process_coding_system) ||
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
565 NILP (incode = (find_coding_system_for_text_file
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
566 (Fcar (Vdefault_process_coding_system), 1))) ||
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
567 NILP (outcode = (find_coding_system_for_text_file
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
568 (Fcdr (Vdefault_process_coding_system), 0))))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
569 signal_error (Qinvalid_state,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
570 "Bogus value for `default-process-coding-system'",
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
571 Vdefault_process_coding_system);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
572 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
573
784
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
574 if (!NILP (Vcoding_system_for_read) &&
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
575 NILP (incode = (find_coding_system_for_text_file
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
576 (Vcoding_system_for_read, 1))))
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
577 signal_error (Qinvalid_state,
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
578 "Bogus value for `coding-system-for-read'",
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
579 Vcoding_system_for_read);
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
580
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
581 if (!NILP (Vcoding_system_for_write) &&
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
582 NILP (outcode = (find_coding_system_for_text_file
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
583 (Vcoding_system_for_write, 0))))
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
584 signal_error (Qinvalid_state,
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
585 "Bogus value for `coding-system-for-write'",
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
586 Vcoding_system_for_write);
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
587
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
588 event_stream_create_io_streams (in, out, err,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
589 &p->pipe_instream,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
590 &p->pipe_outstream,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
591 &p->pipe_errstream,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
592 &in_usid, &err_usid,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
593 flags);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
595 if (in_usid == USID_ERROR || err_usid == USID_ERROR)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
596 signal_error (Qprocess_error, "Setting up communication with subprocess",
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
597 wrap_process (p));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
599 if (in_usid != USID_DONTHASH)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
601 Lisp_Object process = Qnil;
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 784
diff changeset
602 process = wrap_process (p);
5013
ae48681c47fa changes to VOID_TO_LISP et al.
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
603 puthash ((const void*) in_usid, STORE_LISP_IN_VOID (process), usid_to_process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
606 if (err_usid != USID_DONTHASH)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
607 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
608 Lisp_Object process = Qnil;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
609 process = wrap_process (p);
5013
ae48681c47fa changes to VOID_TO_LISP et al.
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
610 puthash ((const void*) err_usid, STORE_LISP_IN_VOID (process),
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
611 usid_to_process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
612 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
613
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
614 MAYBE_PROCMETH (init_process_io_handles, (p, in, out, err, flags));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
616 p->coding_instream =
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
617 make_coding_input_stream (XLSTREAM (p->pipe_instream), incode,
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
618 CODING_DECODE, 0);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
619 if (!NILP (p->pipe_errstream))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
620 p->coding_errstream =
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
621 make_coding_input_stream
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
622 (XLSTREAM (p->pipe_errstream), incode, CODING_DECODE, 0);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
623 p->coding_outstream =
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
624 make_coding_output_stream (XLSTREAM (p->pipe_outstream), outcode,
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
625 CODING_ENCODE, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 create_process (Lisp_Object process, Lisp_Object *argv, int nargv,
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
630 Lisp_Object program, Lisp_Object cur_dir,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
631 int separate_err)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
633 Lisp_Process *p = XPROCESS (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 int pid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 /* *_create_process may change status_symbol, if the process
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 is a kind of "fire-and-forget" (no I/O, unwaitable) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 p->status_symbol = Qrun;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 p->exit_code = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
641 pid = PROCMETH (create_process, (p, argv, nargv, program, cur_dir,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
642 separate_err));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5438
diff changeset
644 p->pid = make_fixnum (pid);
863
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
645 if (PROCESS_READABLE_P (p))
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
646 event_stream_select_process (p, 1, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 /* This function is the unwind_protect form for Fstart_process_internal. If
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
650 PROCESS doesn't have its pid set, then we know someone has signalled
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 an error and the process wasn't started successfully, so we should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 remove it from the process list. */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
653 static void remove_process (Lisp_Object process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 static Lisp_Object
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
655 start_process_unwind (Lisp_Object process)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
657 /* Was PROCESS started successfully? */
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
658 if (EQ (XPROCESS (process)->pid, Qnil))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
659 remove_process (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 DEFUN ("start-process-internal", Fstart_process_internal, 3, MANY, 0, /*
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
664 Internal function to start a program in a subprocess.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
665 Lisp callers should use `start-process' instead.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
666
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
667 Returns the process object for it.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 Args are NAME BUFFER PROGRAM &rest PROGRAM-ARGS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 NAME is name for process. It is modified if necessary to make it unique.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 BUFFER is the buffer or (buffer-name) to associate with the process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 Process output goes at end of that buffer, unless you specify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 an output stream or filter function to handle the output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 BUFFER may be also nil, meaning that this process is not associated
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
674 with any buffer.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
675 BUFFER can also have the form (REAL-BUFFER STDERR-BUFFER); in that case,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
676 REAL-BUFFER says what to do with standard output, as above,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
677 while STDERR-BUFFER says what to do with standard error in the child.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
678 STDERR-BUFFER may be nil (discard standard error output, unless a stderr
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
679 filter is set). Note that if you do not use this form at process creation,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
680 stdout and stderr will be mixed in the output buffer, and this cannot be
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
681 changed, even by setting a stderr filter.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 Third arg is program file name. It is searched for as in the shell.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 Remaining arguments are strings to give program as arguments.
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
684
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
685 Read and write coding systems for the process are determined from
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
686 `coding-system-for-read' and `coding-system-for-write' (intended as
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
687 overriding coding systems to be *bound* by Lisp code, not set), or
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
688 from `default-process-coding-system' if either or both are nil. You can
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
689 change the coding systems later on using `set-process-coding-system',
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
690 `set-process-input-coding-system', or `set-process-output-coding-system'.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
691
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
692 See also `set-process-filter' and `set-process-stderr-filter'.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3025
diff changeset
693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3025
diff changeset
694 arguments: (NAME BUFFER PROGRAM &rest PROGRAM-ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 /* This function can call lisp */
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
699 Lisp_Object buffer, stderr_buffer, name, program, process, current_dir;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
700 int separate_stderr;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 Lisp_Object tem;
910
34362f9d6d61 [xemacs-hg @ 2002-07-09 11:56:04 by michaels]
michaels
parents: 867
diff changeset
702 int i;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 int speccount = specpdl_depth ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 struct gcpro gcpro1, gcpro2, gcpro3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 name = args[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 buffer = args[1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 program = args[2];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 current_dir = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 /* Protect against various file handlers doing GCs below. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 GCPRO3 (buffer, program, current_dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
714 if (CONSP (buffer))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
715 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
716 if (!CONSP (XCDR (buffer)))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
717 invalid_argument ("Invalid BUFFER argument to `start-process'",
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
718 buffer);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
719 if (!NILP (XCDR (XCDR (buffer))))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
720 invalid_argument ("Invalid BUFFER argument to `start-process'",
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
721 buffer);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
722 stderr_buffer = XCAR (XCDR (buffer));
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
723 buffer = XCAR (buffer);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
724 separate_stderr = 1;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
725 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
726 else
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
727 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
728 stderr_buffer = Qnil;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
729 separate_stderr = 0;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
730 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
731
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 if (!NILP (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 buffer = Fget_buffer_create (buffer);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
734 if (!NILP (stderr_buffer))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
735 stderr_buffer = Fget_buffer_create (stderr_buffer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 CHECK_STRING (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 CHECK_STRING (program);
910
34362f9d6d61 [xemacs-hg @ 2002-07-09 11:56:04 by michaels]
michaels
parents: 867
diff changeset
739 for (i = 3; i < nargs; ++i)
34362f9d6d61 [xemacs-hg @ 2002-07-09 11:56:04 by michaels]
michaels
parents: 867
diff changeset
740 CHECK_STRING (args[i]);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 /* Make sure that the child will be able to chdir to the current
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 444
diff changeset
743 buffer's current directory, or its unhandled equivalent. [[ We
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 can't just have the child check for an error when it does the
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 444
diff changeset
745 chdir, since it's in a vfork. ]] -- not any more, we don't use
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 444
diff changeset
746 vfork. -ben
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 444
diff changeset
748 Note: These calls are spread out to insure that the return values
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 444
diff changeset
749 of the calls (which may be newly-created strings) are properly
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 444
diff changeset
750 GC-protected. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 current_dir = current_buffer->directory;
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 444
diff changeset
752 /* If the current dir has no terminating slash, we'll get undesirable
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 444
diff changeset
753 results, so put the slash back. */
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 444
diff changeset
754 current_dir = Ffile_name_as_directory (current_dir);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 current_dir = Funhandled_file_name_directory (current_dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 current_dir = expand_and_dir_to_file (current_dir, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 #if 0 /* This loser breaks ange-ftp */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 /* dmoore - if you re-enable this code, you have to gcprotect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 current_buffer through the above calls. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 if (NILP (Ffile_accessible_directory_p (current_dir)))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
762 signal_error (Qprocess_error, "Setting current directory",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
763 current_buffer->directory);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 #endif /* 0 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 /* If program file name is not absolute, search our path for it */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 816
diff changeset
767 if (!IS_DIRECTORY_SEP (string_byte (program, 0))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 && !(XSTRING_LENGTH (program) > 1
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 816
diff changeset
769 && IS_DEVICE_SEP (string_byte (program, 1))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 struct gcpro ngcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 tem = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 NGCPRO1 (tem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 locate_file (Vexec_path, program, Vlisp_EXEC_SUFFIXES, &tem, X_OK);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 if (NILP (tem))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
777 signal_error (Qprocess_error, "Searching for program", program);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 program = Fexpand_file_name (tem, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 NUNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
783 /* we still need to canonicalize it and ensure it has the proper
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
784 ending, e.g. .exe */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
785 struct gcpro ngcpro1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
786
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
787 tem = Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
788 NGCPRO1 (tem);
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4932
diff changeset
789 locate_file (list1 (build_ascstring ("")), program, Vlisp_EXEC_SUFFIXES,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
790 &tem, X_OK);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
791 if (NILP (tem))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
792 signal_error (Qprocess_error, "Searching for program", program);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
793 program = tem;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
794 NUNGCPRO;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
797 if (!NILP (Ffile_directory_p (program)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
798 invalid_operation ("Specified program for new process is a directory",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
799 program);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
800
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
801 process = make_process_internal (name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
803 XPROCESS (process)->buffer = buffer;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
804 XPROCESS (process)->stderr_buffer = stderr_buffer;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
805 XPROCESS (process)->separate_stderr = separate_stderr;
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
806 XPROCESS (process)->command = Flist (nargs - 2, args + 2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 /* Make the process marker point into the process buffer (if any). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 if (!NILP (buffer))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
810 Fset_marker (XPROCESS (process)->mark,
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5438
diff changeset
811 make_fixnum (BUF_ZV (XBUFFER (buffer))), buffer);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
812 if (!NILP (stderr_buffer))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
813 Fset_marker (XPROCESS (process)->stderr_mark,
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5438
diff changeset
814 make_fixnum (BUF_ZV (XBUFFER (stderr_buffer))), stderr_buffer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 /* If an error occurs and we can't start the process, we want to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 remove it from the process list. This means that each error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 check in create_process doesn't need to call remove_process
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 itself; it's all taken care of here. */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
820 record_unwind_protect (start_process_unwind, process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
822 create_process (process, args + 3, nargs - 3, program, current_dir,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
823 separate_stderr);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 UNGCPRO;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
826 return unbind_to_1 (speccount, process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 #ifdef HAVE_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 /* #### The network support is fairly synthetical. What we actually
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 need is a single function, which supports all datagram, stream and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 packet stream connections, arbitrary protocol families should they
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 be supported by the target system, multicast groups, in both data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 and control rooted/nonrooted flavors, service quality etc whatever
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 is supported by the underlying network.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 It must accept a property list describing the connection. The current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 functions must then go to lisp and provide a suitable list for the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 generalized connection function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 Both UNIX and Win32 support BSD sockets, and there are many extensions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 available (Sockets 2 spec).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 A todo is define a consistent set of properties abstracting a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 network connection. -kkm
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 /* open a TCP network connection to a given HOST/SERVICE. Treated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 exactly like a normal process when reading and writing. Only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 differences are in status display and process deletion. A network
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 connection has no PID; you cannot signal it. All you can do is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 deactivate and close it via delete-process */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857
5814
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
858 DEFUN ("open-network-stream-internal", Fopen_network_stream_internal, 4, 6,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
859 0, /*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 Open a TCP connection for a service to a host.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
861 Return a process object to represent the connection.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 Input and output work as for subprocesses; `delete-process' closes it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 NAME is name for process. It is modified if necessary to make it unique.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 BUFFER is the buffer (or buffer-name) to associate with the process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 Process output goes at end of that buffer, unless you specify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 an output stream or filter function to handle the output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 BUFFER may also be nil, meaning that this process is not associated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 with any buffer.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
870 Third arg HOST (a string) is the name of the host to connect to,
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
871 or its IP address.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
872 Fourth arg SERVICE is the name of the service desired (a string),
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
873 or an integer specifying a port number to connect to.
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 3017
diff changeset
874 Optional fifth arg PROTOCOL is a network protocol. Currently only `tcp'
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 3017
diff changeset
875 (Transmission Control Protocol) and `udp' (User Datagram Protocol) are
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 3017
diff changeset
876 supported. When omitted, `tcp' is assumed.
5814
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
877 Optional sixth arg TLS is a boolean. If it is NIL, a standard network stream
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
878 is opened. If it is non-NIL, a TLS network stream is opened if TLS support
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
879 is available; otherwise an error is signaled.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
881 Output via `process-send-string' and input via buffer or filter (see
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 `set-process-filter') are stream-oriented. That means UDP datagrams are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 not guaranteed to be sent and received in discrete packets. (But small
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 datagrams around 500 bytes that are not truncated by `process-send-string'
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
885 are usually fine.) Note further that the UDP protocol does not guard
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
886 against lost packets.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 */
5814
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
888 (name, buffer, host, service, protocol, tls))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 /* This function can GC */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
891 Lisp_Object process = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, ngcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 void *inch, *outch;
5814
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
894 int flags;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 GCPRO5 (name, buffer, host, service, protocol);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 CHECK_STRING (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
899 if (NILP (protocol))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 protocol = Qtcp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 CHECK_SYMBOL (protocol);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 /* Since this code is inside HAVE_SOCKETS, existence of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 open_network_stream is mandatory */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 PROCMETH (open_network_stream, (name, host, service, protocol,
5814
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
907 &inch, &outch, !NILP(tls)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 if (!NILP (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 buffer = Fget_buffer_create (buffer);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
911 process = make_process_internal (name);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
912 NGCPRO1 (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
914 XPROCESS (process)->pid = Fcons (service, host);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
915 XPROCESS (process)->buffer = buffer;
5814
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
916 flags = STREAM_NETWORK_CONNECTION;
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
917 if (!NILP (tls))
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
918 flags |= STREAM_USE_TLS;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
919 init_process_io_handles (XPROCESS (process), (void *) inch, (void *) outch,
5814
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
920 (void *) -1, flags);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
922 event_stream_select_process (XPROCESS (process), 1, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 934
diff changeset
924 NUNGCPRO;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 UNGCPRO;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
926 return process;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928
5814
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
929 DEFUN ("tls-negotiate", Ftls_negotiate, 3, 3, 0, /*
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
930 "Negotiate a SSL/TLS connection. Returns PROCESS if negotiation is
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
931 successful, NIL otherwise.
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
932
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
933 PROCESS is a process returned by `open-network-stream'.
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
934 HOSTNAME is the remote hostname. It must be a valid string.
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
935 KEYLIST is an alist of (client key file, client cert file) pairs.
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
936 */
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
937 (process, hostname, keylist))
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
938 {
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
939 Lisp_Process *p;
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
940 Lstream *in, *out;
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
941 Extbyte *ext_host;
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
942
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
943 CHECK_PROCESS (process);
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
944 CHECK_STRING (hostname);
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
945 p = XPROCESS (process);
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
946 in = XLSTREAM (DATA_INSTREAM (p));
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
947 out = XLSTREAM (DATA_OUTSTREAM (p));
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
948 ext_host = LISP_STRING_TO_EXTERNAL (hostname, Qunix_host_name_encoding);
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
949 return Lstream_tls_negotiate (in, out, ext_host, keylist) ? process : Qnil;
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
950 }
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
951
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 #ifdef HAVE_MULTICAST
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 DEFUN ("open-multicast-group-internal", Fopen_multicast_group_internal, 5, 5, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 Open a multicast connection on the specified dest/port/ttl.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
956 Return a process object to represent the connection.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 Input and output work as for subprocesses; `delete-process' closes it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 NAME is name for process. It is modified if necessary to make it unique.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 BUFFER is the buffer (or buffer-name) to associate with the process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 Process output goes at end of that buffer, unless you specify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 an output stream or filter function to handle the output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 BUFFER may also be nil, meaning that this process is not associated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 with any buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 Third, fourth and fifth args are the multicast destination group, port and ttl.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 dest must be an internet address between 224.0.0.0 and 239.255.255.255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 port is a communication port like in traditional unicast
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 ttl is the time-to-live (15 for site, 63 for region and 127 for world)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 (name, buffer, dest, port, ttl))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 /* This function can GC */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
973 Lisp_Object process = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 void *inch, *outch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 CHECK_STRING (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 /* Since this code is inside HAVE_MULTICAST, existence of
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
980 open_multicast_group is mandatory */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 PROCMETH (open_multicast_group, (name, dest, port, ttl,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 &inch, &outch));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 if (!NILP (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 buffer = Fget_buffer_create (buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
987 process = make_process_internal (name);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
988 GCPRO1 (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
990 XPROCESS (process)->pid = Fcons (port, dest);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
991 XPROCESS (process)->buffer = buffer;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
992 init_process_io_handles (XPROCESS (process), (void *) inch, (void *) outch,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
993 (void *) -1,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 STREAM_NETWORK_CONNECTION);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
996 event_stream_select_process (XPROCESS (process), 1, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 UNGCPRO;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
999 return process;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 #endif /* HAVE_MULTICAST */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 #endif /* HAVE_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 canonicalize_host_name (Lisp_Object host)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 return PROCMETH_OR_GIVEN (canonicalize_host_name, (host), host);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 DEFUN ("set-process-window-size", Fset_process_window_size, 3, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 Tell PROCESS that it has logical window size HEIGHT and WIDTH.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1015 (process, height, width))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1017 CHECK_PROCESS (process);
5736
3192994c49ca Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents: 5588
diff changeset
1018 check_integer_range (height, Qzero, make_fixnum (MOST_POSITIVE_FIXNUM));
3192994c49ca Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents: 5588
diff changeset
1019 check_integer_range (width, Qzero, make_fixnum (MOST_POSITIVE_FIXNUM));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 return
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1021 MAYBE_INT_PROCMETH (set_window_size,
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5438
diff changeset
1022 (XPROCESS (process), XFIXNUM (height), XFIXNUM (width))) <= 0
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 ? Qnil : Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 /* Process I/O */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1031 /* Set up PROCESS's buffer for insertion of process data at PROCESS's
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1032 mark.
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1033
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1034 Sets the current buffer to PROCESS's buffer, inhibits read only,
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1035 remembers current point, sets point to PROCESS'S mark, widens if
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1036 necessary.
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1037 */
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1038 static int
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1039 process_setup_for_insertion (Lisp_Object process, int read_stderr)
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1040 {
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1041 Lisp_Process *p = XPROCESS (process);
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1042 int spec = specpdl_depth ();
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1043 Lisp_Object buffer = read_stderr ? p->stderr_buffer : p->buffer;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1044 Lisp_Object mark = read_stderr ? p->stderr_mark : p->mark;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1045 struct buffer *buf = XBUFFER (buffer);
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1046 Charbpos output_pt;
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1047
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1048 if (buf != current_buffer)
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1049 {
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1050 record_unwind_protect (save_current_buffer_restore,
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1051 Fcurrent_buffer ());
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1052 set_buffer_internal (buf);
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1053 }
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1054
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1055 record_unwind_protect (save_excursion_restore, save_excursion_save ());
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1056 specbind (Qinhibit_read_only, Qt);
854
1d8fb2eee1bb [xemacs-hg @ 2002-05-28 16:06:58 by didierv]
didierv
parents: 853
diff changeset
1057
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1058 /* Insert new output into buffer
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1059 at the current end-of-output marker,
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1060 thus preserving logical ordering of input and output. */
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1061 if (XMARKER (mark)->buffer)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1062 output_pt = marker_position (mark);
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1063 else
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1064 output_pt = BUF_ZV (buf);
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1065
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1066 /* If the output marker is outside of the visible region, save
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1067 the restriction and widen. */
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1068 if (! (BUF_BEGV (buf) <= output_pt && output_pt <= BUF_ZV (buf)))
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1069 {
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1070 record_unwind_protect (save_restriction_restore,
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1071 save_restriction_save (buf));
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1072 Fwiden (wrap_buffer (buf));
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1073 }
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1074
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1075 BUF_SET_PT (buf, output_pt);
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1076 return spec;
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1077 }
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1078
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 /* Read pending output from the process channel,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 starting with our buffered-ahead character if we have one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 Yield number of characters read.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 This function reads at most 1024 bytes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 If you want to read all available subprocess output,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 you must call it repeatedly until it returns zero. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 Charcount
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1088 read_process_output (Lisp_Object process, int read_stderr)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 Bytecount nbytes, nchars;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 863
diff changeset
1092 Ibyte chars[1025];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 Lisp_Object outstream;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1094 Lisp_Process *p = XPROCESS (process);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1095 Lisp_Object filter = read_stderr ? p->stderr_filter : p->filter;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1096 Lisp_Object buffer = read_stderr ? p->stderr_buffer : p->buffer;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1097 Lisp_Object mark = read_stderr ? p->stderr_mark : p->mark;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 /* If there is a lot of output from the subprocess, the loop in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 execute_internal_event() might call read_process_output() more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 than once. If the filter that was executed from one of these
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 calls set the filter to t, we have to stop now. Return -1 rather
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 than 0 so execute_internal_event() doesn't close the process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 Really, the loop in execute_internal_event() should check itself
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 for a process-filter change, like in status_notify(); but the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 struct Lisp_Process is not exported outside of this file. */
863
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
1107 if (!PROCESS_READABLE_P (p))
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1108 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1109 errno = 0;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1110 return -1; /* already closed */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1111 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1113 if (!NILP (filter) && (p->filter_does_read))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 Lisp_Object filter_result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 /* Some weird FSFmacs crap here with
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1118 Vdeactivate_mark and current_buffer->keymap.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1119 Some FSF junk with running_asynch_code, to preserve the match
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1120 data. Not necessary because we don't call process filters
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1121 asynchronously (i.e. from within QUIT). */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1122 /* Don't catch errors here; we're not in any critical code. */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1123 filter_result = call2 (filter, process, Qnil);
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5438
diff changeset
1124 CHECK_FIXNUM (filter_result);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5438
diff changeset
1125 return XFIXNUM (filter_result);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1128 nbytes = Lstream_read (read_stderr ? XLSTREAM (DATA_ERRSTREAM (p)) :
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1129 XLSTREAM (DATA_INSTREAM (p)), chars,
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1130 sizeof (chars) - 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 if (nbytes <= 0) return nbytes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1133 if (debug_process_io)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1134 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1135 chars[nbytes] = '\0';
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1136 stderr_out ("Read: %s\n", chars);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1137 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1138
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1139 /* !!#### if the coding system changed as a result of reading, we
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1140 need to change the output coding system accordingly. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 nchars = bytecount_to_charcount (chars, nbytes);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1142 outstream = filter;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 if (!NILP (outstream))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 {
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1145 /* Some FSF junk with running_asynch_code, to preserve the match
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1146 data. Not necessary because we don't call process filters
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1147 asynchronously (i.e. from within QUIT). */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1148 /* Don't catch errors here; we're not in any critical code. */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1149 call2 (outstream, process, make_string (chars, nbytes));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 return nchars;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 /* If no filter, write into buffer if it isn't dead. */
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1154 if (!NILP (buffer) && BUFFER_LIVE_P (XBUFFER (buffer)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 {
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1156 struct gcpro gcpro1;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1157 struct buffer *buf = XBUFFER (buffer);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1158 int spec = process_setup_for_insertion (process, read_stderr);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1160 GCPRO1 (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 /* This screws up initial display of the window. jla */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 /* Insert before markers in case we are inserting where
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 the buffer's mark is, and the user's next command is Meta-y. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 buffer_insert_raw_string_1 (buf, -1, chars,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 nbytes, INSDEL_BEFORE_MARKERS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 buffer_insert_raw_string (buf, chars, nbytes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5438
diff changeset
1173 Fset_marker (mark, make_fixnum (BUF_PT (buf)), buffer);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1174
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 MARK_MODELINE_CHANGED;
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1176 unbind_to (spec);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 return nchars;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 }
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1181
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1182 int
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1183 process_has_separate_stderr (Lisp_Object process)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1184 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1185 return XPROCESS (process)->separate_stderr;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1186 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1187
859
84762348c6f9 [xemacs-hg @ 2002-06-01 08:06:46 by ben]
ben
parents: 854
diff changeset
1188 DEFUN ("process-has-separate-stderr-p", Fprocess_has_separate_stderr_p, 1, 1,
84762348c6f9 [xemacs-hg @ 2002-06-01 08:06:46 by ben]
ben
parents: 854
diff changeset
1189 0, /*
84762348c6f9 [xemacs-hg @ 2002-06-01 08:06:46 by ben]
ben
parents: 854
diff changeset
1190 Return non-nil if process has stderr separate from stdout.
84762348c6f9 [xemacs-hg @ 2002-06-01 08:06:46 by ben]
ben
parents: 854
diff changeset
1191 */
84762348c6f9 [xemacs-hg @ 2002-06-01 08:06:46 by ben]
ben
parents: 854
diff changeset
1192 (process))
84762348c6f9 [xemacs-hg @ 2002-06-01 08:06:46 by ben]
ben
parents: 854
diff changeset
1193 {
84762348c6f9 [xemacs-hg @ 2002-06-01 08:06:46 by ben]
ben
parents: 854
diff changeset
1194 CHECK_PROCESS (process);
84762348c6f9 [xemacs-hg @ 2002-06-01 08:06:46 by ben]
ben
parents: 854
diff changeset
1195 return process_has_separate_stderr (process) ? Qt : Qnil;
84762348c6f9 [xemacs-hg @ 2002-06-01 08:06:46 by ben]
ben
parents: 854
diff changeset
1196 }
84762348c6f9 [xemacs-hg @ 2002-06-01 08:06:46 by ben]
ben
parents: 854
diff changeset
1197
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 /* Sending data to subprocess */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1201 /* send some data to process PROCESS. If NONRELOCATABLE is non-NULL, it
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 specifies the address of the data. Otherwise, the data comes from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 object RELOCATABLE (either a string or a buffer). START and LEN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 specify the offset and length of the data to send.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 563
diff changeset
1206 Note that START and LEN are in Charbpos's if RELOCATABLE is a buffer,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 and in Bytecounts otherwise. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1210 send_process (Lisp_Object process,
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 863
diff changeset
1211 Lisp_Object relocatable, const Ibyte *nonrelocatable,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 int start, int len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 struct gcpro gcpro1, gcpro2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 Lisp_Object lstream = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1218 GCPRO2 (process, lstream);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1220 if (NILP (DATA_OUTSTREAM (XPROCESS (process))))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
1221 invalid_operation ("Process not open for writing", process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 if (nonrelocatable)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 lstream =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 make_fixed_buffer_input_stream (nonrelocatable + start, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 else if (BUFFERP (relocatable))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 lstream = make_lisp_buffer_input_stream (XBUFFER (relocatable),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 start, start + len, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 lstream = make_lisp_string_input_stream (relocatable, start, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1232 if (debug_process_io)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1233 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1234 if (nonrelocatable)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1235 stderr_out ("Writing: %s\n", nonrelocatable);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1236 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1237 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1238 stderr_out ("Writing: ");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1239 print_internal (relocatable, Qexternal_debugging_output, 0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1240 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1241 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1242
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1243 PROCMETH (send_process, (process, XLSTREAM (lstream)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 Lstream_delete (XLSTREAM (lstream));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 DEFUN ("process-tty-name", Fprocess_tty_name, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 Return the name of the terminal PROCESS uses, or nil if none.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 This is the terminal that the process itself reads and writes on,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 not the name of the pty that Emacs uses to talk with that terminal.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1254 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1256 CHECK_PROCESS (process);
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 934
diff changeset
1257 return XPROCESS (process)->tty_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 DEFUN ("set-process-buffer", Fset_process_buffer, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 Set buffer associated with PROCESS to BUFFER (a buffer, or nil).
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 1726
diff changeset
1262 Output from PROCESS is inserted in this buffer unless PROCESS has a filter.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1264 (process, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1266 CHECK_PROCESS (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 if (!NILP (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 CHECK_BUFFER (buffer);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1269 XPROCESS (process)->buffer = buffer;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 return buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 DEFUN ("process-buffer", Fprocess_buffer, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 Return the buffer PROCESS is associated with.
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 1726
diff changeset
1275 Output from PROCESS is inserted in this buffer unless PROCESS has a filter.
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 1726
diff changeset
1276 Set the buffer with `set-process-buffer'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1278 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1280 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1281 return XPROCESS (process)->buffer;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1284 DEFUN ("set-process-stderr-buffer", Fset_process_stderr_buffer, 2, 2, 0, /*
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 1726
diff changeset
1285 Output from the stderr of PROCESS is inserted in this buffer unless
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 1726
diff changeset
1286 PROCESS has a stderr filter.
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1287 Set stderr buffer associated with PROCESS to BUFFER (a buffer, or nil).
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1288 */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1289 (process, buffer))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1290 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1291 CHECK_PROCESS (process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1292 if (!XPROCESS (process)->separate_stderr)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1293 invalid_change ("stdout and stderr not separate", process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1294 if (!NILP (buffer))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1295 CHECK_BUFFER (buffer);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1296 XPROCESS (process)->stderr_buffer = buffer;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1297 return buffer;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1298 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1299
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1300 DEFUN ("process-stderr-buffer", Fprocess_stderr_buffer, 1, 1, 0, /*
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1301 Return the stderr buffer PROCESS is associated with.
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 1726
diff changeset
1302 Output from the stderr of PROCESS is inserted in this buffer unless PROCESS
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 1726
diff changeset
1303 has a stderr filter. Set the buffer with `set-process-stderr-buffer'.
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1304 */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1305 (process))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1306 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1307 CHECK_PROCESS (process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1308 if (!XPROCESS (process)->separate_stderr)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1309 invalid_change ("stdout and stderr not separate", process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1310 return XPROCESS (process)->stderr_buffer;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1311 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1312
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 DEFUN ("process-mark", Fprocess_mark, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 Return the marker for the end of the last output from PROCESS.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1316 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1318 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1319 return XPROCESS (process)->mark;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1320 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1322 DEFUN ("process-stderr-mark", Fprocess_stderr_mark, 1, 1, 0, /*
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1323 Return the marker for the end of the last stderr output from PROCESS.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1324 */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1325 (process))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1326 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1327 CHECK_PROCESS (process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1328 if (!XPROCESS (process)->separate_stderr)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1329 invalid_operation ("stdout and stderr not separate", process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1330 return XPROCESS (process)->stderr_mark;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1331 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1332
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 void
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1334 set_process_filter (Lisp_Object process, Lisp_Object filter,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1335 int filter_does_read, int set_stderr)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1337 CHECK_PROCESS (process);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1338 if (set_stderr && !XPROCESS (process)->separate_stderr)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1339 invalid_change ("stdout and stderr not separate", process);
863
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
1340 if (PROCESS_READABLE_P (XPROCESS (process)))
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1341 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1342 if (EQ (filter, Qt))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1343 event_stream_unselect_process (XPROCESS (process), !set_stderr,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1344 set_stderr);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1345 else
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1346 event_stream_select_process (XPROCESS (process), !set_stderr,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1347 set_stderr);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1348 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1350 if (set_stderr)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1351 XPROCESS (process)->stderr_filter = filter;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1352 else
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1353 XPROCESS (process)->filter = filter;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1354 XPROCESS (process)->filter_does_read = filter_does_read;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 DEFUN ("set-process-filter", Fset_process_filter, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 Give PROCESS the filter function FILTER; nil means no filter.
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1359 t means stop accepting output from the process. (If process was created
854
1d8fb2eee1bb [xemacs-hg @ 2002-05-28 16:06:58 by didierv]
didierv
parents: 853
diff changeset
1360 with
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1361 When a process has a filter, each time it does output
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1362 the entire string of output is passed to the filter.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1363 The filter gets two arguments: the process and the string of output.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1364 If the process has a filter, its buffer is not used for output.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1365 */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1366 (process, filter))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1367 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1368 set_process_filter (process, filter, 0, 0);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1369 return filter;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1370 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1371
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1372 DEFUN ("set-process-stderr-filter", Fset_process_stderr_filter, 2, 2, 0, /*
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1373 Give PROCESS the stderr filter function FILTER; nil means no filter.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 t means stop accepting output from the process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 When a process has a filter, each time it does output
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376 the entire string of output is passed to the filter.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 The filter gets two arguments: the process and the string of output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 If the process has a filter, its buffer is not used for output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1380 (process, filter))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 {
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1382 set_process_filter (process, filter, 0, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 return filter;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 DEFUN ("process-filter", Fprocess_filter, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 Return the filter function of PROCESS; nil if none.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 See `set-process-filter' for more info on filter functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1390 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1392 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1393 return XPROCESS (process)->filter;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1396 DEFUN ("process-stderr-filter", Fprocess_stderr_filter, 1, 1, 0, /*
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1397 Return the filter function of PROCESS; nil if none.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1398 See `set-process-stderr-filter' for more info on filter functions.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1399 */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1400 (process))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1401 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1402 CHECK_PROCESS (process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1403 if (!XPROCESS (process)->separate_stderr)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1404 invalid_operation ("stdout and stderr not separate", process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1405 return XPROCESS (process)->stderr_filter;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1406 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1407
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1408 DEFUN ("process-send-region", Fprocess_send_region, 3, 4, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1409 Send current contents of the region between START and END as input to PROCESS.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1410 PROCESS may be a process or the name of a process, or a buffer or the
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1411 name of a buffer, in which case the buffer's process is used. If it
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1412 is nil, the current buffer's process is used.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1413 BUFFER specifies the buffer to look in; if nil, the current buffer is used.
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1414 If the region is more than 100 or so characters long, it may be sent in
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1415 several chunks. This may happen even for shorter regions. Output
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1416 from processes can arrive in between chunks.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1418 (process, start, end, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 /* This function can GC */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 563
diff changeset
1421 Charbpos bstart, bend;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1422 struct buffer *buf = decode_buffer (buffer, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 784
diff changeset
1424 buffer = wrap_buffer (buf);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1425 process = get_process (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1426 get_buffer_range_char (buf, start, end, &bstart, &bend, 0);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1427
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1428 send_process (process, buffer, 0, bstart, bend - bstart);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 DEFUN ("process-send-string", Fprocess_send_string, 2, 4, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 Send PROCESS the contents of STRING as input.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1434 PROCESS may be a process or the name of a process, or a buffer or the
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1435 name of a buffer, in which case the buffer's process is used. If it
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1436 is nil, the current buffer's process is used.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1437 Optional arguments START and END specify part of STRING; see `substring'.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1438 If STRING is more than 100 or so characters long, it may be sent in
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1439 several chunks. This may happen even for shorter strings. Output
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1440 from processes can arrive in between chunks.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1442 (process, string, start, end))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 /* This function can GC */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1445 Bytecount bstart, bend;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1447 process = get_process (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 CHECK_STRING (string);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1449 get_string_range_byte (string, start, end, &bstart, &bend,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 GB_HISTORICAL_STRING_BEHAVIOR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1452 send_process (process, string, 0, bstart, bend - bstart);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 DEFUN ("process-input-coding-system", Fprocess_input_coding_system, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458 Return PROCESS's input coding system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 (process))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462 process = get_process (process);
863
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
1463 CHECK_READABLE_PROCESS (process);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1464 return (coding_stream_detected_coding_system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1465 (XLSTREAM (XPROCESS (process)->coding_instream)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 DEFUN ("process-output-coding-system", Fprocess_output_coding_system, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 Return PROCESS's output coding system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 (process))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 process = get_process (process);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1474 CHECK_LIVE_PROCESS (process);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1475 return (coding_stream_coding_system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1476 (XLSTREAM (XPROCESS (process)->coding_outstream)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 DEFUN ("process-coding-system", Fprocess_coding_system, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 Return a pair of coding-system for decoding and encoding of PROCESS.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482 (process))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 process = get_process (process);
863
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
1485 CHECK_READABLE_PROCESS (process);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1486 return Fcons (coding_stream_detected_coding_system
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 (XLSTREAM (XPROCESS (process)->coding_instream)),
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1488 coding_stream_coding_system
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 (XLSTREAM (XPROCESS (process)->coding_outstream)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 DEFUN ("set-process-input-coding-system", Fset_process_input_coding_system,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 Set PROCESS's input coding system to CODESYS.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1495 This is used for reading data from PROCESS.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 (process, codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1499 codesys = get_coding_system_for_text_file (codesys, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 process = get_process (process);
863
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
1501 CHECK_READABLE_PROCESS (process);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1502
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1503 set_coding_stream_coding_system
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 (XLSTREAM (XPROCESS (process)->coding_instream), codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 DEFUN ("set-process-output-coding-system", Fset_process_output_coding_system,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 Set PROCESS's output coding system to CODESYS.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1511 This is used for writing data to PROCESS.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 (process, codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1515 codesys = get_coding_system_for_text_file (codesys, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 process = get_process (process);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1517 CHECK_LIVE_PROCESS (process);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1518
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1519 set_coding_stream_coding_system
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 (XLSTREAM (XPROCESS (process)->coding_outstream), codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 DEFUN ("set-process-coding-system", Fset_process_coding_system,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 1, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526 Set coding-systems of PROCESS to DECODING and ENCODING.
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1527 DECODING will be used to decode subprocess output and ENCODING to
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1528 encode subprocess input.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 (process, decoding, encoding))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 if (!NILP (decoding))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533 Fset_process_input_coding_system (process, decoding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 if (!NILP (encoding))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536 Fset_process_output_coding_system (process, encoding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1539 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543 /* process status */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 exec_sentinel_unwind (Lisp_Object datum)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 {
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1549 XPROCESS (XCAR (datum))->sentinel = XCDR (datum);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1550 free_cons (datum);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 static void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1555 exec_sentinel (Lisp_Object process, Lisp_Object reason)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 int speccount = specpdl_depth ();
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1559 Lisp_Process *p = XPROCESS (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 Lisp_Object sentinel = p->sentinel;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 if (NILP (sentinel))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 /* Some weird FSFmacs crap here with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 Vdeactivate_mark and current_buffer->keymap */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1568 /* Some FSF junk with running_asynch_code, to preserve the match
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1569 data. Not necessary because we don't call process filters
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1570 asynchronously (i.e. from within QUIT). */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1571
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572 /* Zilch the sentinel while it's running, to avoid recursive invocations;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1573 assure that it gets restored no matter how the sentinel exits.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1574
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1575 (#### Why is this necessary? Probably another relic of asynchronous
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1576 calling of process filters/sentinels.) */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 p->sentinel = Qnil;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1578 record_unwind_protect (exec_sentinel_unwind,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1579 noseeum_cons (process, sentinel));
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1580 /* Don't catch errors here; we're not in any critical code. */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1581 call2 (sentinel, process, reason);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1582 unbind_to (speccount);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 DEFUN ("set-process-sentinel", Fset_process_sentinel, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586 Give PROCESS the sentinel SENTINEL; nil for none.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587 The sentinel is called as a function when the process changes state.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588 It gets two arguments: the process, and a string describing the change.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1590 (process, sentinel))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1592 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1593 XPROCESS (process)->sentinel = sentinel;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 return sentinel;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597 DEFUN ("process-sentinel", Fprocess_sentinel, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598 Return the sentinel of PROCESS; nil if none.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 See `set-process-sentinel' for more info on sentinels.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1601 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1603 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1604 return XPROCESS (process)->sentinel;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1608 const char *
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 signal_name (int signum)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 if (signum >= 0 && signum < NSIG)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1612 return (const char *) sys_siglist[signum];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1614 return (const char *) GETTEXT ("unknown signal");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 update_process_status (Lisp_Object p,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619 Lisp_Object status_symbol,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620 int exit_code,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1621 int core_dumped)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623 XPROCESS (p)->tick++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624 process_tick++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625 XPROCESS (p)->status_symbol = status_symbol;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626 XPROCESS (p)->exit_code = exit_code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627 XPROCESS (p)->core_dumped = core_dumped;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 /* Return a string describing a process status list. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632 static Lisp_Object
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1633 status_message (Lisp_Process *p)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 Lisp_Object symbol = p->status_symbol;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636 int code = p->exit_code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 int coredump = p->core_dumped;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638 Lisp_Object string, string2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1639
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640 if (EQ (symbol, Qsignal) || EQ (symbol, Qstop))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 {
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
1642 string = build_cistring (signal_name (code));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643 if (coredump)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1644 string2 = build_msg_string (" (core dumped)\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645 else
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4932
diff changeset
1646 string2 = build_ascstring ("\n");
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 784
diff changeset
1647 set_string_char (string, 0,
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 863
diff changeset
1648 DOWNCASE (0, string_ichar (string, 0)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649 return concat2 (string, string2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1650 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651 else if (EQ (symbol, Qexit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 if (code == 0)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1654 return build_msg_string ("finished\n");
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5438
diff changeset
1655 string = Fnumber_to_string (make_fixnum (code));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656 if (coredump)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1657 string2 = build_msg_string (" (core dumped)\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 else
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4932
diff changeset
1659 string2 = build_ascstring ("\n");
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1660 return concat2 (build_msg_string ("exited abnormally with code "),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661 concat2 (string, string2));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 return Fcopy_sequence (Fsymbol_name (symbol));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 /* Tell status_notify() to check for terminated processes. We do this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668 because on some systems we sometimes miss SIGCHLD calls. (Not sure
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1669 why.) This is also used under Mswin. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672 kick_status_notify (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 process_tick++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678 /* Report all recent events of a change in process status
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 (either run the sentinel or output a message).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680 This is done while Emacs is waiting for keyboard input. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 status_notify (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686 Lisp_Object tail = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 Lisp_Object symbol = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688 Lisp_Object msg = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 struct gcpro gcpro1, gcpro2, gcpro3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 /* process_tick is volatile, so we have to remember it now.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1691 Otherwise, we get a race condition if SIGCHLD happens during
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692 this function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 (Actually, this is not the case anymore. The code to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695 update the process structures has been moved out of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696 SIGCHLD handler. But for the moment I'm leaving this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697 stuff in -- it can't hurt.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698 int temp_process_tick;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 MAYBE_PROCMETH (reap_exited_processes, ());
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 temp_process_tick = process_tick;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 if (update_tick == temp_process_tick)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707 /* We need to gcpro tail; if read_process_output calls a filter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708 which deletes a process and removes the cons to which tail points
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 from Vprocess_alist, and then causes a GC, tail is an unprotected
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 reference. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711 GCPRO3 (tail, symbol, msg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713 for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1715 Lisp_Object process = XCAR (tail);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1716 Lisp_Process *p = XPROCESS (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717 /* p->tick is also volatile. Same thing as above applies. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 int this_process_tick;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720 /* #### extra check for terminated processes, in case a SIGCHLD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 got missed (this seems to happen sometimes, I'm not sure why).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 */
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5438
diff changeset
1723 if (FIXNUMP (p->pid))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 MAYBE_PROCMETH (update_status_if_terminated, (p));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 this_process_tick = p->tick;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 if (this_process_tick != p->update_tick)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 p->update_tick = this_process_tick;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731 /* If process is still active, read any output that remains. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 while (!EQ (p->filter, Qt)
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1733 && read_process_output (process, 0) > 0)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1734 ;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1735 while (p->separate_stderr && !EQ (p->stderr_filter, Qt)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1736 && read_process_output (process, 1) > 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 ;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 /* Get the text to use for the message. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740 msg = status_message (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1741
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 /* If process is terminated, deactivate it or delete it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743 symbol = p->status_symbol;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745 if (EQ (symbol, Qsignal)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746 || EQ (symbol, Qexit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1747 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1748 if (delete_exited_processes)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1749 remove_process (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1750 else
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1751 deactivate_process (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754 /* Now output the message suitably. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 if (!NILP (p->sentinel))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1756 exec_sentinel (process, msg);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757 /* Don't bother with a message in the buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758 when a process becomes runnable. */
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1759 else if (!EQ (symbol, Qrun) && !NILP (p->buffer) &&
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1760 /* Avoid error if buffer is deleted
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1761 (probably that's why the process is dead, too) */
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1762 BUFFER_LIVE_P (XBUFFER (p->buffer)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 {
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1764 struct gcpro ngcpro1;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1765 int spec = process_setup_for_insertion (process, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1767 NGCPRO1 (process);
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
1768 buffer_insert_ascstring (current_buffer, "\nProcess ");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 Finsert (1, &p->name);
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
1770 buffer_insert_ascstring (current_buffer, " ");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1771 Finsert (1, &msg);
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5438
diff changeset
1772 Fset_marker (p->mark, make_fixnum (BUF_PT (current_buffer)),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773 p->buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1774
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1775 unbind_to (spec);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776 NUNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779 } /* end for */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1780
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781 /* in case buffers use %s in modeline-format */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782 MARK_MODELINE_CHANGED;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783 redisplay ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 update_tick = temp_process_tick;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 DEFUN ("process-status", Fprocess_status, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1791 Return the status of PROCESS.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792 This is a symbol, one of these:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794 run -- for a process that is running.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795 stop -- for a process stopped but continuable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1796 exit -- for a process that has exited.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 signal -- for a process that has got a fatal signal.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798 open -- for a network stream connection that is open.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799 closed -- for a network stream connection that is closed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1800 nil -- if arg is a process name and no such process exists.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802 PROCESS may be a process, a buffer, the name of a process or buffer, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 nil, indicating the current buffer's process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1805 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1806 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807 Lisp_Object status_symbol;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1809 if (STRINGP (process))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1810 process = Fget_process (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1811 else
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1812 process = get_process (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1813
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1814 if (NILP (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1817 status_symbol = XPROCESS (process)->status_symbol;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1818 if (network_connection_p (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1820 if (EQ (status_symbol, Qrun))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 status_symbol = Qopen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1822 else if (EQ (status_symbol, Qexit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1823 status_symbol = Qclosed;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1824 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825 return status_symbol;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1826 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1827
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1828 DEFUN ("process-exit-status", Fprocess_exit_status, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1829 Return the exit status of PROCESS or the signal number that killed it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830 If PROCESS has not yet exited or died, return 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1832 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1833 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1834 CHECK_PROCESS (process);
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5438
diff changeset
1835 return make_fixnum (XPROCESS (process)->exit_code);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1837
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1838
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1840 static int
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1841 decode_signal (Lisp_Object signal_)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1842 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5438
diff changeset
1843 if (FIXNUMP (signal_))
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5438
diff changeset
1844 return XFIXNUM (signal_);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1846 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 863
diff changeset
1847 Ibyte *name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1848
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1849 CHECK_SYMBOL (signal_);
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 784
diff changeset
1850 name = XSTRING_DATA (XSYMBOL (signal_)->name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 784
diff changeset
1852 #define handle_signal(sym) do { \
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
1853 if (!qxestrcmp_ascii ( name, #sym)) \
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 784
diff changeset
1854 return sym; \
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1855 } while (0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857 handle_signal (SIGINT); /* ANSI */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 handle_signal (SIGILL); /* ANSI */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859 handle_signal (SIGABRT); /* ANSI */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 handle_signal (SIGFPE); /* ANSI */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 handle_signal (SIGSEGV); /* ANSI */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862 handle_signal (SIGTERM); /* ANSI */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 #ifdef SIGHUP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865 handle_signal (SIGHUP); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 #ifdef SIGQUIT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 handle_signal (SIGQUIT); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870 #ifdef SIGTRAP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 handle_signal (SIGTRAP); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873 #ifdef SIGKILL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 handle_signal (SIGKILL); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 #ifdef SIGUSR1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 handle_signal (SIGUSR1); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879 #ifdef SIGUSR2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880 handle_signal (SIGUSR2); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882 #ifdef SIGPIPE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1883 handle_signal (SIGPIPE); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 #ifdef SIGALRM
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886 handle_signal (SIGALRM); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888 #ifdef SIGCHLD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 handle_signal (SIGCHLD); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891 #ifdef SIGCONT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 handle_signal (SIGCONT); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894 #ifdef SIGSTOP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 handle_signal (SIGSTOP); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 #ifdef SIGTSTP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 handle_signal (SIGTSTP); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900 #ifdef SIGTTIN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901 handle_signal (SIGTTIN); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1902 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1903 #ifdef SIGTTOU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904 handle_signal (SIGTTOU); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1906
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1907 #ifdef SIGBUS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1908 handle_signal (SIGBUS); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910 #ifdef SIGPOLL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911 handle_signal (SIGPOLL); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913 #ifdef SIGPROF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1914 handle_signal (SIGPROF); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916 #ifdef SIGSYS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917 handle_signal (SIGSYS); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1918 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919 #ifdef SIGURG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920 handle_signal (SIGURG); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 #ifdef SIGXCPU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1923 handle_signal (SIGXCPU); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1924 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1925 #ifdef SIGXFSZ
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 handle_signal (SIGXFSZ); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928 #ifdef SIGVTALRM
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1929 handle_signal (SIGVTALRM); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1930 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1931
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 #ifdef SIGIO
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933 handle_signal (SIGIO); /* BSD 4.2 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1935 #ifdef SIGWINCH
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936 handle_signal (SIGWINCH); /* BSD 4.3 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1937 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1938
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1939 #ifdef SIGEMT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1940 handle_signal (SIGEMT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1941 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1942 #ifdef SIGINFO
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943 handle_signal (SIGINFO);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 #ifdef SIGHWE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946 handle_signal (SIGHWE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948 #ifdef SIGPRE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1949 handle_signal (SIGPRE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951 #ifdef SIGUME
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1952 handle_signal (SIGUME);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 #ifdef SIGDLK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 handle_signal (SIGDLK);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1957 #ifdef SIGCPULIM
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958 handle_signal (SIGCPULIM);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1959 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 #ifdef SIGIOT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961 handle_signal (SIGIOT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963 #ifdef SIGLOST
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964 handle_signal (SIGLOST);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966 #ifdef SIGSTKFLT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 handle_signal (SIGSTKFLT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969 #ifdef SIGUNUSED
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 handle_signal (SIGUNUSED);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972 #ifdef SIGDANGER
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1973 handle_signal (SIGDANGER); /* AIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1974 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1975 #ifdef SIGMSG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976 handle_signal (SIGMSG);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1977 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978 #ifdef SIGSOUND
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 handle_signal (SIGSOUND);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981 #ifdef SIGRETRACT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982 handle_signal (SIGRETRACT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984 #ifdef SIGGRANT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985 handle_signal (SIGGRANT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1986 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987 #ifdef SIGPWR
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1988 handle_signal (SIGPWR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1991 #undef handle_signal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
1993 invalid_constant ("Undefined signal name", signal_);
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 934
diff changeset
1994 RETURN_NOT_REACHED (0);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1995 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1996 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1997
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1998 /* Send signal number SIGNO to PROCESS.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1999 CURRENT-GROUP non-nil means send signal to the current
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2000 foreground process group of the process's controlling terminal rather
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2001 than to the process's own process group.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2002 This is used for various commands in shell mode.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2003 If NOMSG is zero, insert signal-announcements into process's buffers
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2004 right away.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2005
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2006 If we can, we try to signal PROCESS by sending control characters
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2007 down the pty. This allows us to signal inferiors who have changed
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2008 their uid, for which kill() would return an EPERM error, or to
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2009 processes running on another computer through a remote login. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2010
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2011 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2012 process_send_signal (Lisp_Object process, int signo,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2013 int current_group, int nomsg)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2014 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2015 /* This function can GC */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2016 process = get_process (process);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2017
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2018 if (network_connection_p (process))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2019 invalid_operation ("Network connection is not a subprocess", process);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2020 CHECK_LIVE_PROCESS (process);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2021
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2022 MAYBE_PROCMETH (kill_child_process, (process, signo, current_group, nomsg));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2023 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2024
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2025 DEFUN ("process-send-signal", Fprocess_send_signal, 1, 3, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2026 Send signal SIGNAL to process PROCESS.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2027 SIGNAL may be an integer, or a symbol naming a signal, like `SIGSEGV'.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2028 PROCESS may be a process, a buffer, the name of a process or buffer, or
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2029 nil, indicating the current buffer's process.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2030 Third arg CURRENT-GROUP non-nil means send signal to the current
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2031 foreground process group of the process's controlling terminal rather
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2032 than to the process's own process group.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2033 If the process is a shell that supports job control, this means
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2034 send the signal to the current subjob rather than the shell.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2035 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2036 (signal_, process, current_group))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2037 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2038 /* This function can GC */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2039 process_send_signal (process, decode_signal (signal_),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2040 !NILP (current_group), 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2041 return process;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2042 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2043
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2044 DEFUN ("interrupt-process", Finterrupt_process, 0, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2045 Interrupt process PROCESS.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2046 See function `process-send-signal' for more details on usage.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2047 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2048 (process, current_group))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2049 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2050 /* This function can GC */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2051 process_send_signal (process, SIGINT, !NILP (current_group), 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2052 return process;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2053 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2054
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2055 DEFUN ("kill-process", Fkill_process, 0, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2056 Kill process PROCESS.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2057 See function `process-send-signal' for more details on usage.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2058 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2059 (process, current_group))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2060 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2061 /* This function can GC */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2062 #ifdef SIGKILL
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2063 process_send_signal (process, SIGKILL, !NILP (current_group), 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2064 #else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2065 signal_error (Qunimplemented,
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2066 "kill-process: Not supported on this system",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2067 Qunbound);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2068 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2069 return process;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2070 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2071
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2072 DEFUN ("quit-process", Fquit_process, 0, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2073 Send QUIT signal to process PROCESS.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2074 See function `process-send-signal' for more details on usage.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2075 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2076 (process, current_group))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2077 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2078 /* This function can GC */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2079 #ifdef SIGQUIT
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2080 process_send_signal (process, SIGQUIT, !NILP (current_group), 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2081 #else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2082 signal_error (Qunimplemented,
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2083 "quit-process: Not supported on this system",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2084 Qunbound);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2085 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2086 return process;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2087 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2088
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2089 DEFUN ("stop-process", Fstop_process, 0, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2090 Stop process PROCESS.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2091 See function `process-send-signal' for more details on usage.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2092 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2093 (process, current_group))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2094 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2095 /* This function can GC */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2096 #ifdef SIGTSTP
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2097 process_send_signal (process, SIGTSTP, !NILP (current_group), 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2098 #else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2099 signal_error (Qunimplemented,
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2100 "stop-process: Not supported on this system",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2101 Qunbound);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2102 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2103 return process;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2104 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2105
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2106 DEFUN ("continue-process", Fcontinue_process, 0, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2107 Continue process PROCESS.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2108 See function `process-send-signal' for more details on usage.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2109 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2110 (process, current_group))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2111 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2112 /* This function can GC */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2113 #ifdef SIGCONT
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2114 process_send_signal (process, SIGCONT, !NILP (current_group), 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2115 #else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2116 signal_error (Qunimplemented,
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2117 "continue-process: Not supported on this system",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2118 Qunbound);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2119 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2120 return process;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2121 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2122
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2123 DEFUN ("signal-process", Fsignal_process, 2, 2,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2124 "nProcess number: \nnSignal code: ", /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2125 Send the process with process id PID the signal with code SIGNAL.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2126 PID must be an integer. The process need not be a child of this Emacs.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2127 SIGNAL may be an integer, or a symbol naming a signal, like `SIGSEGV'.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2128 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2129 (pid, signal_))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2130 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5438
diff changeset
2131 CHECK_FIXNUM (pid);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5438
diff changeset
2132
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5438
diff changeset
2133 return make_fixnum (PROCMETH_OR_GIVEN (kill_process_by_pid,
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5438
diff changeset
2134 (XFIXNUM (pid), decode_signal (signal_)),
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2135 -1));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2136 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2138 DEFUN ("process-send-eof", Fprocess_send_eof, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2139 Make PROCESS see end-of-file in its input.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2140 PROCESS may be a process, a buffer, the name of a process or buffer, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2141 nil, indicating the current buffer's process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2142 If PROCESS is a network connection, or is a process communicating
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2143 through a pipe (as opposed to a pty), then you cannot send any more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2144 text to PROCESS after you call this function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2145 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2146 (process))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2147 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2148 /* This function can GC */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2149 process = get_process (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2150
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2151 /* Make sure the process is really alive. */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2152 if (! EQ (XPROCESS (process)->status_symbol, Qrun))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2153 invalid_operation ("Process not running", process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2154
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2155 if (!MAYBE_INT_PROCMETH (process_send_eof, (process)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2156 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2157 if (!NILP (DATA_OUTSTREAM (XPROCESS (process))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2158 {
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2159 USID humpty, dumpty;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2160 Lstream_close (XLSTREAM (DATA_OUTSTREAM (XPROCESS (process))));
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2161 event_stream_delete_io_streams (Qnil,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2162 XPROCESS (process)->pipe_outstream,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2163 Qnil, &humpty, &dumpty);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2164 XPROCESS (process)->pipe_outstream = Qnil;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2165 XPROCESS (process)->coding_outstream = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2166 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2167 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2168
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2169 return process;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2170 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2173 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2174 /* deleting a process */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2175 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2176
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2177 void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2178 deactivate_process (Lisp_Object process)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2179 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2180 Lisp_Process *p = XPROCESS (process);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2181 USID in_usid, err_usid;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2183 /* It's possible that we got as far in the process-creation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2184 process as creating the descriptors but didn't get so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2185 far as selecting the process for input. In this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2186 case, p->pid is nil: p->pid is set at the same time that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2187 the process is selected for input. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2188 /* #### The comment does not look correct. event_stream_unselect_process
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2189 is guarded by process->*_selected, so this is not a problem. - kkm*/
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2190 /* Must call this before setting the streams to nil */
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2191 event_stream_unselect_process (p, 1, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2192
5588
2dbefd79b3d3 Prevent SIGPIPEs in deactivate_process().
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5581
diff changeset
2193 /* We can get here in case of a crash in the external process, and then
2dbefd79b3d3 Prevent SIGPIPEs in deactivate_process().
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5581
diff changeset
2194 the Lstream_close on output will cause a SIGPIPE, which we're not ready
2dbefd79b3d3 Prevent SIGPIPEs in deactivate_process().
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5581
diff changeset
2195 for here. It looks to me like all cases where this function is called
2dbefd79b3d3 Prevent SIGPIPEs in deactivate_process().
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5581
diff changeset
2196 we know the process has exited (but I'm not 100% sure for the call in
2dbefd79b3d3 Prevent SIGPIPEs in deactivate_process().
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5581
diff changeset
2197 execute_internal_event (event-stream.c)), so it should be OK to use
2dbefd79b3d3 Prevent SIGPIPEs in deactivate_process().
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5581
diff changeset
2198 Lstream_close_noflush.
2dbefd79b3d3 Prevent SIGPIPEs in deactivate_process().
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5581
diff changeset
2199
2dbefd79b3d3 Prevent SIGPIPEs in deactivate_process().
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5581
diff changeset
2200 #### The layering here needs a rethink. We should just be able
2dbefd79b3d3 Prevent SIGPIPEs in deactivate_process().
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5581
diff changeset
2201 to call Lstream_close, and let the Lstream's implementation decide
2dbefd79b3d3 Prevent SIGPIPEs in deactivate_process().
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5581
diff changeset
2202 if it can flush safely or not. The immediate problem is that the
2dbefd79b3d3 Prevent SIGPIPEs in deactivate_process().
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5581
diff changeset
2203 Lstream needs to know the process's status, but I don't think it has
2dbefd79b3d3 Prevent SIGPIPEs in deactivate_process().
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5581
diff changeset
2204 a handle to the process. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2205 if (!NILP (DATA_OUTSTREAM (p)))
5588
2dbefd79b3d3 Prevent SIGPIPEs in deactivate_process().
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5581
diff changeset
2206 Lstream_close_noflush (XLSTREAM (DATA_OUTSTREAM (p)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2207 if (!NILP (DATA_INSTREAM (p)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2208 Lstream_close (XLSTREAM (DATA_INSTREAM (p)));
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2209 if (!NILP (DATA_ERRSTREAM (p)))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2210 Lstream_close (XLSTREAM (DATA_ERRSTREAM (p)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2211
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2212 /* Provide minimal implementation for deactivate_process
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2213 if there's no process-specific one */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2214 if (HAS_PROCMETH_P (deactivate_process))
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2215 PROCMETH (deactivate_process, (p, &in_usid, &err_usid));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2216 else
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2217 event_stream_delete_io_streams (p->pipe_instream,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2218 p->pipe_outstream,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2219 p->pipe_errstream,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2220 &in_usid, &err_usid);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2221
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2222 if (in_usid != USID_DONTHASH)
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2223 remhash ((const void *) in_usid, usid_to_process);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2224 if (err_usid != USID_DONTHASH)
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2225 remhash ((const void *) err_usid, usid_to_process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2226
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2227 p->pipe_instream = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2228 p->pipe_outstream = Qnil;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2229 p->pipe_errstream = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2230 p->coding_instream = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2231 p->coding_outstream = Qnil;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2232 p->coding_errstream = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2233 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2234
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2235 static void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2236 remove_process (Lisp_Object process)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2237 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2238 Vprocess_list = delq_no_quit (process, Vprocess_list);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2239
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2240 deactivate_process (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2241 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2243 DEFUN ("delete-process", Fdelete_process, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2244 Delete PROCESS: kill it and forget about it immediately.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2245 PROCESS may be a process or the name of one, or a buffer name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2246 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2247 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2248 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2249 /* This function can GC */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
2250 Lisp_Process *p;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2251 process = get_process (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2252 p = XPROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2253 if (network_connection_p (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2254 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2255 p->status_symbol = Qexit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2256 p->exit_code = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2257 p->core_dumped = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2258 p->tick++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2259 process_tick++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2260 }
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
2261 else if (PROCESS_LIVE_P (p))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2262 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2263 Fkill_process (process, Qnil);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2264 /* Do this now, since remove_process will make sigchld_handler do nothing. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2265 p->status_symbol = Qsignal;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2266 p->exit_code = SIGKILL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2267 p->core_dumped = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2268 p->tick++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2269 process_tick++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2270 status_notify ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2271 }
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2272 remove_process (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2273 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2274 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2276 /* Kill all processes associated with `buffer'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2277 If `buffer' is nil, kill all processes */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2279 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2280 kill_buffer_processes (Lisp_Object buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2281 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2282 LIST_LOOP_2 (process, Vprocess_list)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2283 if ((NILP (buffer) || EQ (XPROCESS (process)->buffer, buffer)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2284 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2285 if (network_connection_p (process))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2286 Fdelete_process (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2287 else if (PROCESS_LIVE_P (XPROCESS (process)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2288 process_send_signal (process, SIGHUP, 0, 1);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2289 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2290 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2291
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2292 DEFUN ("process-kill-without-query", Fprocess_kill_without_query, 1, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2293 Say no query needed if PROCESS is running when Emacs is exited.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2294 Optional second argument if non-nil says to require a query.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2295 Value is t if a query was formerly required.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2296 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2297 (process, require_query_p))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2298 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2299 int tem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2300
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2301 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2302 tem = XPROCESS (process)->kill_without_query;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2303 XPROCESS (process)->kill_without_query = NILP (require_query_p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2305 return tem ? Qnil : Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2306 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2307
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2308 DEFUN ("process-kill-without-query-p", Fprocess_kill_without_query_p, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2309 Return t if PROCESS will be killed without query when emacs is exited.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2310 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2311 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2312 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2313 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2314 return XPROCESS (process)->kill_without_query ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2315 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2316
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2318 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2319
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 816
diff changeset
2320 DEFUN ("process-connection", Fprocess_connection, 0, 1, 0, /*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2321 Return the connection type of `PROCESS'. This can be nil (pipe),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2322 t or pty (pty) or stream (socket connection).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2323 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2324 (process))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2325 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2326 return XPROCESS (process)->type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2327 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2329 #endif /* 0 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2330
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2331
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2332 static int
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 863
diff changeset
2333 getenv_internal (const Ibyte *var,
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2334 Bytecount varlen,
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 863
diff changeset
2335 Ibyte **value,
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2336 Bytecount *valuelen)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2337 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2338 Lisp_Object scan;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2339
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2340 assert (env_initted);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2341
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2342 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2343 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2344 Lisp_Object entry = XCAR (scan);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2345
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2346 if (STRINGP (entry)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2347 && XSTRING_LENGTH (entry) > varlen
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 816
diff changeset
2348 && string_byte (entry, varlen) == '='
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2349 #ifdef WIN32_NATIVE
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2350 /* NT environment variables are case insensitive. */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2351 && ! memicmp (XSTRING_DATA (entry), var, varlen)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2352 #else /* not WIN32_NATIVE */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2353 && ! memcmp (XSTRING_DATA (entry), var, varlen)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2354 #endif /* not WIN32_NATIVE */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2355 )
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2356 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2357 *value = XSTRING_DATA (entry) + (varlen + 1);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2358 *valuelen = XSTRING_LENGTH (entry) - (varlen + 1);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2359 return 1;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2360 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2361 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2362
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2363 return 0;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2364 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2365
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2366 static void
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 863
diff changeset
2367 putenv_internal (const Ibyte *var,
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2368 Bytecount varlen,
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 863
diff changeset
2369 const Ibyte *value,
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2370 Bytecount valuelen)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2371 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2372 Lisp_Object scan;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2373
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2374 assert (env_initted);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2375
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2376 for (scan = Vprocess_environment; CONSP (scan); scan = XCDR (scan))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2377 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2378 Lisp_Object entry = XCAR (scan);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2379
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2380 if (STRINGP (entry)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2381 && XSTRING_LENGTH (entry) > varlen
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 816
diff changeset
2382 && string_byte (entry, varlen) == '='
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2383 #ifdef WIN32_NATIVE
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2384 /* NT environment variables are case insensitive. */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2385 && ! memicmp (XSTRING_DATA (entry), var, varlen)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2386 #else /* not WIN32_NATIVE */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2387 && ! memcmp (XSTRING_DATA (entry), var, varlen)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2388 #endif /* not WIN32_NATIVE */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2389 )
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2390 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2391 XCAR (scan) = concat3 (make_string (var, varlen),
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4932
diff changeset
2392 build_ascstring ("="),
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2393 make_string (value, valuelen));
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2394 return;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2395 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2396 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2397
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2398 Vprocess_environment = Fcons (concat3 (make_string (var, varlen),
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4932
diff changeset
2399 build_ascstring ("="),
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2400 make_string (value, valuelen)),
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2401 Vprocess_environment);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2402 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2403
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2404 /* NOTE:
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2405
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2406 FSF has this as a Lisp function, as follows. Generally moving things
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2407 out of C and into Lisp is a good idea, but in this case the Lisp
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2408 function is used so early in the startup sequence that it would be ugly
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2409 to rearrange the early dumped code to accommodate this.
854
1d8fb2eee1bb [xemacs-hg @ 2002-05-28 16:06:58 by didierv]
didierv
parents: 853
diff changeset
2410
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2411 (defun getenv (variable)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2412 "Get the value of environment variable VARIABLE.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2413 VARIABLE should be a string. Value is nil if VARIABLE is undefined in
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2414 the environment. Otherwise, value is a string.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2415
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2416 This function consults the variable `process-environment'
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2417 for its value."
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2418 (interactive (list (read-envvar-name "Get environment variable: " t)))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2419 (let ((value (getenv-internal variable)))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2420 (when (interactive-p)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2421 (message "%s" (if value value "Not set")))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2422 value))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2423 */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2424
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2425 DEFUN ("getenv", Fgetenv, 1, 2, "sEnvironment variable: \np", /*
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2426 Return the value of environment variable VAR, as a string.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2427 VAR is a string, the name of the variable.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2428 When invoked interactively, prints the value in the echo area.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2429 */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2430 (var, interactivep))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2431 {
4932
8b63e21b0436 fix compile issues with gcc 4
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
2432 Ibyte *value = NULL;
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2433 Bytecount valuelen;
5883
d93195c2c906 Escape quotation marks when printing values interactively, #'getenv
Aidan Kehoe <kehoea@parhasard.net>
parents: 5814
diff changeset
2434 Lisp_Object v = Qnil, formatted = Qnil;
d93195c2c906 Escape quotation marks when printing values interactively, #'getenv
Aidan Kehoe <kehoea@parhasard.net>
parents: 5814
diff changeset
2435 struct gcpro gcpro1, gcpro2;
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2436
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2437 CHECK_STRING (var);
5883
d93195c2c906 Escape quotation marks when printing values interactively, #'getenv
Aidan Kehoe <kehoea@parhasard.net>
parents: 5814
diff changeset
2438 GCPRO2 (v, formatted);
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2439 if (getenv_internal (XSTRING_DATA (var), XSTRING_LENGTH (var),
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2440 &value, &valuelen))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2441 v = make_string (value, valuelen);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2442 if (!NILP (interactivep))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2443 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2444 if (NILP (v))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2445 message ("%s not defined in environment", XSTRING_DATA (var));
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2446 else
5883
d93195c2c906 Escape quotation marks when printing values interactively, #'getenv
Aidan Kehoe <kehoea@parhasard.net>
parents: 5814
diff changeset
2447 {
d93195c2c906 Escape quotation marks when printing values interactively, #'getenv
Aidan Kehoe <kehoea@parhasard.net>
parents: 5814
diff changeset
2448 /* Backslash any quotation marks. */
d93195c2c906 Escape quotation marks when printing values interactively, #'getenv
Aidan Kehoe <kehoea@parhasard.net>
parents: 5814
diff changeset
2449 formatted = Fprin1_to_string (v, Qnil);
d93195c2c906 Escape quotation marks when printing values interactively, #'getenv
Aidan Kehoe <kehoea@parhasard.net>
parents: 5814
diff changeset
2450 message_internal (NULL, formatted, 0, -1);
d93195c2c906 Escape quotation marks when printing values interactively, #'getenv
Aidan Kehoe <kehoea@parhasard.net>
parents: 5814
diff changeset
2451 }
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2452 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2453 RETURN_UNGCPRO (v);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2454 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2455
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2456 /* A version of getenv that consults Vprocess_environment, easily
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2457 callable from C.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2458
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2459 (At init time, Vprocess_environment is initialized from the
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2460 environment, stored in the global variable environ. [Note that
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2461 at startup time, `environ' should be the same as the envp parameter
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2462 passed to main(); however, later calls to putenv() may change
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2463 `environ', making the envp parameter inaccurate.] Calls to getenv()
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2464 and putenv() consult and modify `environ'. However, once
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2465 Vprocess_environment is initted, XEmacs C code should *NEVER* call
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2466 getenv() or putenv() directly, because (1) Lisp code that modifies
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2467 the environment only modifies Vprocess_environment, not `environ';
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2468 and (2) Vprocess_environment is in internal format but `environ'
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2469 is in some external format, and getenv()/putenv() are not Mule-
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2470 encapsulated.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2471
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2472 WARNING: This value points into Lisp string data and thus will become
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2473 invalid after a GC. */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2474
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 863
diff changeset
2475 Ibyte *
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 863
diff changeset
2476 egetenv (const CIbyte *var)
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2477 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2478 /* This cannot GC -- 7-28-00 ben */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 863
diff changeset
2479 Ibyte *value;
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2480 Bytecount valuelen;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2481
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 863
diff changeset
2482 if (getenv_internal ((const Ibyte *) var, strlen (var), &value, &valuelen))
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2483 return value;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2484 else
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2485 return 0;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2486 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2487
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2488 void
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 863
diff changeset
2489 eputenv (const CIbyte *var, const CIbyte *value)
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2490 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 863
diff changeset
2491 putenv_internal ((Ibyte *) var, strlen (var), (Ibyte *) value,
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2492 strlen (value));
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2493 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2494
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2495
5255
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
2496 void
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
2497 reinit_process_early (void)
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
2498 {
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
2499 OBJECT_HAS_METHOD (process, getprop);
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
2500 OBJECT_HAS_METHOD (process, putprop);
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
2501 OBJECT_HAS_METHOD (process, remprop);
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
2502 OBJECT_HAS_METHOD (process, plist);
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
2503 OBJECT_HAS_METHOD (process, setplist);
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
2504 }
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
2505
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2506 /* This is not named init_process in order to avoid a conflict with NS 3.3 */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2507 void
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2508 init_xemacs_process (void)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2509 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2510 /* This function can GC */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2511
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2512 MAYBE_PROCMETH (init_process, ());
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2513
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2514 Vprocess_list = Qnil;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2515
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2516 if (usid_to_process)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2517 clrhash (usid_to_process);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2518 else
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2519 usid_to_process = make_hash_table (32);
854
1d8fb2eee1bb [xemacs-hg @ 2002-05-28 16:06:58 by didierv]
didierv
parents: 853
diff changeset
2520
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2521 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2522 /* jwz: always initialize Vprocess_environment, so that egetenv()
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2523 works in temacs. */
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2524 Extbyte **envp;
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2525 Vprocess_environment = Qnil;
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2526 #ifdef WIN32_NATIVE
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2527 _wgetenv (L""); /* force initialization of _wenviron */
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2528 for (envp = (Extbyte **) _wenviron; envp && *envp; envp++)
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2529 Vprocess_environment =
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
2530 Fcons (build_extstring (*envp, Qmswindows_unicode),
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2531 Vprocess_environment);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2532 #else
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2533 for (envp = environ; envp && *envp; envp++)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2534 Vprocess_environment =
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
2535 Fcons (build_extstring (*envp, Qenvironment_variable_encoding),
4834
b3ea9c582280 Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents: 4759
diff changeset
2536 Vprocess_environment);
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2537 #endif
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2538 /* This gets set back to 0 in disksave_object_finalization() */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2539 env_initted = 1;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2540 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2541
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2542 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2543 /* Initialize shell-file-name from environment variables or best guess. */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2544 #ifdef WIN32_NATIVE
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 863
diff changeset
2545 const Ibyte *shell = egetenv ("SHELL");
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2546 if (!shell) shell = egetenv ("COMSPEC");
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2547 /* Should never happen! */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2548 if (!shell) shell =
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 863
diff changeset
2549 (Ibyte *) (GetVersion () & 0x80000000 ? "command" : "cmd");
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2550 #else /* not WIN32_NATIVE */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 863
diff changeset
2551 const Ibyte *shell = egetenv ("SHELL");
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 863
diff changeset
2552 if (!shell) shell = (Ibyte *) "/bin/sh";
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2553 #endif
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2554
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2555 #if 0 /* defined (WIN32_NATIVE) */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2556 /* BAD BAD BAD. We do not wanting to be passing an XEmacs-created
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2557 SHELL var down to some inferior Cygwin process, which might get
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2558 screwed up.
854
1d8fb2eee1bb [xemacs-hg @ 2002-05-28 16:06:58 by didierv]
didierv
parents: 853
diff changeset
2559
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2560 There are a few broken apps (eterm/term.el, eterm/tshell.el,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2561 os-utils/terminal.el, texinfo/tex-mode.el) where this will
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2562 cause problems. Those broken apps don't look at
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2563 shell-file-name, instead just at explicit-shell-file-name,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2564 ESHELL and SHELL. They are apparently attempting to borrow
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2565 what `M-x shell' uses, but that latter also looks at
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2566 shell-file-name. What we want is for all of these apps to look
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2567 at shell-file-name, so that the user can change the value of
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2568 shell-file-name and everything will work out hunky-dorey.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2569 */
854
1d8fb2eee1bb [xemacs-hg @ 2002-05-28 16:06:58 by didierv]
didierv
parents: 853
diff changeset
2570
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2571 if (!egetenv ("SHELL"))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2572 {
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2573 Ibyte *faux_var = alloca_ibytes (7 + qxestrlen (shell));
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2574 qxesprintf (faux_var, "SHELL=%s", shell);
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
2575 Vprocess_environment = Fcons (build_istring (faux_var),
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2576 Vprocess_environment);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2577 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2578 #endif /* 0 */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2579
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
2580 Vshell_file_name = build_istring (shell);
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2581 }
5255
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
2582
b5611afbcc76 Support process plists, for greater GNU compatibility.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
2583 reinit_process_early ();
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2584 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2585
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2586 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2587 syms_of_process (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2588 {
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3025
diff changeset
2589 INIT_LISP_OBJECT (process);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2590
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2591 DEFSYMBOL (Qprocessp);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2592 DEFSYMBOL (Qprocess_live_p);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2593 DEFSYMBOL (Qrun);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2594 DEFSYMBOL (Qstop);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2595 DEFSYMBOL (Qopen);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2596 DEFSYMBOL (Qclosed);
863
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
2597 #if 0
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
2598 /* see comment at Fprocess_readable_p */
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
2599 DEFSYMBOL (&Qprocess_readable_p);
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
2600 #endif
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2601 DEFSYMBOL (Qtcp);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2602 DEFSYMBOL (Qudp);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2603
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2604 #ifdef HAVE_MULTICAST
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2605 DEFSYMBOL (Qmulticast); /* Used for occasional warnings */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2606 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2607
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2608 DEFERROR_STANDARD (Qprocess_error, Qio_error);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2609 DEFERROR_STANDARD (Qnetwork_error, Qio_error);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2610
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2611 DEFSUBR (Fprocessp);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
2612 DEFSUBR (Fprocess_live_p);
863
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
2613 #if 0
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
2614 /* see comment at Fprocess_readable_p */
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
2615 DEFSUBR (Fprocess_readable_p);
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 862
diff changeset
2616 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2617 DEFSUBR (Fget_process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2618 DEFSUBR (Fget_buffer_process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2619 DEFSUBR (Fdelete_process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2620 DEFSUBR (Fprocess_status);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2621 DEFSUBR (Fprocess_exit_status);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2622 DEFSUBR (Fprocess_id);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2623 DEFSUBR (Fprocess_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2624 DEFSUBR (Fprocess_tty_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2625 DEFSUBR (Fprocess_command);
859
84762348c6f9 [xemacs-hg @ 2002-06-01 08:06:46 by ben]
ben
parents: 854
diff changeset
2626 DEFSUBR (Fprocess_has_separate_stderr_p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2627 DEFSUBR (Fset_process_buffer);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2628 DEFSUBR (Fset_process_stderr_buffer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2629 DEFSUBR (Fprocess_buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2630 DEFSUBR (Fprocess_mark);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2631 DEFSUBR (Fprocess_stderr_buffer);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2632 DEFSUBR (Fprocess_stderr_mark);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2633 DEFSUBR (Fset_process_filter);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2634 DEFSUBR (Fprocess_filter);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2635 DEFSUBR (Fset_process_stderr_filter);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2636 DEFSUBR (Fprocess_stderr_filter);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2637 DEFSUBR (Fset_process_window_size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2638 DEFSUBR (Fset_process_sentinel);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2639 DEFSUBR (Fprocess_sentinel);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2640 DEFSUBR (Fprocess_kill_without_query);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2641 DEFSUBR (Fprocess_kill_without_query_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2642 DEFSUBR (Fprocess_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2643 DEFSUBR (Fstart_process_internal);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2644 #ifdef HAVE_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2645 DEFSUBR (Fopen_network_stream_internal);
5814
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5736
diff changeset
2646 DEFSUBR (Ftls_negotiate);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2647 #ifdef HAVE_MULTICAST
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2648 DEFSUBR (Fopen_multicast_group_internal);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2649 #endif /* HAVE_MULTICAST */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2650 #endif /* HAVE_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2651 DEFSUBR (Fprocess_send_region);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2652 DEFSUBR (Fprocess_send_string);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2653 DEFSUBR (Fprocess_send_signal);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2654 DEFSUBR (Finterrupt_process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2655 DEFSUBR (Fkill_process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2656 DEFSUBR (Fquit_process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2657 DEFSUBR (Fstop_process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2658 DEFSUBR (Fcontinue_process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2659 DEFSUBR (Fprocess_send_eof);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2660 DEFSUBR (Fsignal_process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2661 /* DEFSUBR (Fprocess_connection); */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2662 DEFSUBR (Fprocess_input_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2663 DEFSUBR (Fprocess_output_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2664 DEFSUBR (Fset_process_input_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2665 DEFSUBR (Fset_process_output_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2666 DEFSUBR (Fprocess_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2667 DEFSUBR (Fset_process_coding_system);
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2668 DEFSUBR (Fgetenv);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2669 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2670
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2671 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2672 vars_of_process (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2673 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2674 Fprovide (intern ("subprocesses"));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2675 #ifdef HAVE_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2676 Fprovide (intern ("network-streams"));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2677 #ifdef HAVE_MULTICAST
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2678 Fprovide (intern ("multicast"));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2679 #endif /* HAVE_MULTICAST */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2680 #endif /* HAVE_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2681 staticpro (&Vprocess_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2682
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2683 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2684 *Non-nil means delete processes immediately when they exit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2685 nil means don't delete them until `list-processes' is run.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2686 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2687
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2688 delete_exited_processes = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2689
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2690 DEFVAR_CONST_LISP ("null-device", &Vnull_device /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2691 Name of the null device, which differs from system to system.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2692 The null device is a filename that acts as a sink for arbitrary amounts of
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2693 data, which is discarded, or as a source for a zero-length file.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2694 It is available on all the systems that we currently support, but with
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2695 different names (typically either `/dev/null' or `nul').
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2696
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2697 Note that there is also a /dev/zero on most modern Unix versions (including
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2698 Cygwin), which acts like /dev/null when used as a sink, but as a source
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2699 it sends a non-ending stream of zero bytes. It's used most often along
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2700 with memory-mapping. We don't provide a Lisp variable for this because
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2701 the operations needing this are lower level than what ELisp programs
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2702 typically do, and in any case no equivalent exists under native MS Windows.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2703 */ );
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4932
diff changeset
2704 Vnull_device = build_ascstring (NULL_DEVICE);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2705
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2706 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2707 Control type of device used to communicate with subprocesses.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2708 Values are nil to use a pipe, or t or `pty' to use a pty.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2709 The value has no effect if the system has no ptys or if all ptys are busy:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2710 then a pipe is used in any case.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2711 The value takes effect when `start-process' is called.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2712 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2713 Vprocess_connection_type = Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2714
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2715 DEFVAR_BOOL ("windowed-process-io", &windowed_process_io /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2716 Enables input/output on standard handles of a windowed process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2717 When this variable is nil (the default), XEmacs does not attempt to read
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2718 standard output handle of a windowed process. Instead, the process is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2719 immediately marked as exited immediately upon successful launching. This is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2720 done because normal windowed processes do not use standard I/O, as they are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2721 not connected to any console.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2722
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2723 When launching a specially crafted windowed process, which expects to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2724 launched by XEmacs, or by other program which pipes its standard input and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2725 output, this variable must be set to non-nil, in which case XEmacs will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2726 treat this process just like a console process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2727
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2728 NOTE: You should never set this variable, only bind it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2729
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2730 Only Windows processes can be "windowed" or "console". This variable has no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2731 effect on UNIX processes, because all UNIX processes are "console".
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2732 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2733 windowed_process_io = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2734
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2735 DEFVAR_INT ("debug-process-io", &debug_process_io /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2736 If non-zero, display data sent to or received from a process.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2737 */ );
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2738 debug_process_io = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2739
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2740 DEFVAR_LISP ("default-process-coding-system",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2741 &Vdefault_process_coding_system /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2742 Cons of coding systems used for process I/O by default.
4729
428d7c571110 Fix issue145: accept nil in default-process-coding-system.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4693
diff changeset
2743 May also be nil, interpreted as (nil . nil).
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2744 The car part is used for reading (decoding) data from a process, and
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2745 the cdr part is used for writing (encoding) data to a process.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2746 */ );
4729
428d7c571110 Fix issue145: accept nil in default-process-coding-system.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4693
diff changeset
2747 /* Better, system-dependent defaults are set in code-init.el. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2748 Vdefault_process_coding_system = Fcons (Qundecided, Qnil);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2749
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2750 DEFVAR_LISP ("default-network-coding-system",
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2751 &Vdefault_network_coding_system /*
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2752 Cons of coding systems used for network I/O by default.
4729
428d7c571110 Fix issue145: accept nil in default-process-coding-system.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4693
diff changeset
2753 May also be nil, interpreted as (nil . nil).
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2754 The car part is used for reading (decoding) data from a process, and
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2755 the cdr part is used for writing (encoding) data to a process.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2756 */ );
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2757 Vdefault_network_coding_system = Fcons (Qundecided, Qnil);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2758
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2759 #ifdef PROCESS_IO_BLOCKING
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2760 DEFVAR_LISP ("network-stream-blocking-port-list", &network_stream_blocking_port_list /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2761 List of port numbers or port names to set a blocking I/O mode with connection.
862
278c743f1578 [xemacs-hg @ 2002-06-03 12:23:49 by ben]
ben
parents: 859
diff changeset
2762 Nil value means to set a default (non-blocking) I/O mode.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2763 The value takes effect when `open-network-stream-internal' is called.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2764 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2765 network_stream_blocking_port_list = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2766 #endif /* PROCESS_IO_BLOCKING */
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2767
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2768 /* This function can GC */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2769 DEFVAR_LISP ("shell-file-name", &Vshell_file_name /*
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2770 *File name to load inferior shells from.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2771 Initialized from the SHELL environment variable.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2772 */ );
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2773
4729
428d7c571110 Fix issue145: accept nil in default-process-coding-system.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4693
diff changeset
2774 /* ben? thinks the format of this variable is "semi-bogus".
428d7c571110 Fix issue145: accept nil in default-process-coding-system.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4693
diff changeset
2775 sjt doesn't agree, since it captures a restriction that is
428d7c571110 Fix issue145: accept nil in default-process-coding-system.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4693
diff changeset
2776 present in POSIX shells, after all. */
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2777 DEFVAR_LISP ("process-environment", &Vprocess_environment /*
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2778 List of environment variables for subprocesses to inherit.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2779 Each element should be a string of the form ENVVARNAME=VALUE.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2780 The environment which Emacs inherits is placed in this variable
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2781 when Emacs starts.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2782 */ );
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2783
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4932
diff changeset
2784 Vlisp_EXEC_SUFFIXES = build_ascstring (EXEC_SUFFIXES);
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2785 staticpro (&Vlisp_EXEC_SUFFIXES);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2786 }