annotate src/process.c @ 853:2b6fa2618f76

[xemacs-hg @ 2002-05-28 08:44:22 by ben] merge my stderr-proc ws make-docfile.c: Fix places where we forget to check for EOF. code-init.el: Don't use CRLF conversion by default on process output. CMD.EXE and friends work both ways but Cygwin programs don't like the CRs. code-process.el, multicast.el, process.el: Removed. Improvements to call-process-internal: -- allows a buffer to be specified for input and stderr output -- use it on all systems -- implement C-g as documented -- clean up and comment call-process-region uses new call-process facilities; no temp file. remove duplicate funs in process.el. comment exactly how coding systems work and fix various problems. open-multicast-group now does similar coding-system frobbing to open-network-stream. dumped-lisp.el, faces.el, msw-faces.el: Fix some hidden errors due to code not being defined at the right time. xemacs.mak: Add -DSTRICT. ================================================================ ALLOW SEPARATION OF STDOUT AND STDERR IN PROCESSES ================================================================ Standard output and standard error can be processed separately in a process. Each can have its own buffer, its own mark in that buffer, and its filter function. You can specify a separate buffer for stderr in `start-process' to get things started, or use the new primitives: set-process-stderr-buffer process-stderr-buffer process-stderr-mark set-process-stderr-filter process-stderr-filter Also, process-send-region takes a 4th optional arg, a buffer. Currently always uses a pipe() under Unix to read the error output. (#### Would a PTY be better?) sysdep.h, sysproc.h, unexfreebsd.c, unexsunos4.c, nt.c, emacs.c, callproc.c, symsinit.h, sysdep.c, Makefile.in.in, process-unix.c: Delete callproc.c. Move child_setup() to process-unix.c. wait_for_termination() now only needed on a few really old systems. console-msw.h, event-Xt.c, event-msw.c, event-stream.c, event-tty.c, event-unixoid.c, events.h, process-nt.c, process-unix.c, process.c, process.h, procimpl.h: Rewrite the process methods to handle a separate channel for error input. Create Lstreams for reading in the error channel. Many process methods need change. In general the changes are fairly clear as they involve duplicating what's used for reading the normal stdout and changing for stderr -- although tedious, as such changes are required throughout the entire process code. Rewrote the code that reads process output to do two loops, one for stdout and one for stderr. gpmevent.c, tooltalk.c: set_process_filter takes an argument for stderr. ================================================================ NEW ERROR-TRAPPING MECHANISM ================================================================ Totally rewrite error trapping code to be unified and support more features. Basic function is call_trapping_problems(), which lets you specify, by means of flags, what sorts of problems you want trapped. these can include -- quit -- errors -- throws past the function -- creation of "display objects" (e.g. buffers) -- deletion of already-existing "display objects" (e.g. buffers) -- modification of already-existing buffers -- entering the debugger -- gc -- errors->warnings (ala suspended errors) etc. All other error funs rewritten in terms of this one. Various older mechanisms removed or rewritten. window.c, insdel.c, console.c, buffer.c, device.c, frame.c: When creating a display object, added call to note_object_created(), for use with trapping_problems mechanism. When deleting, call check_allowed_operation() and note_object deleted(). The trapping-problems code records the objects created since the call-trapping-problems began. Those objects can be deleted, but none others (i.e. previously existing ones). bytecode.c, cmdloop.c: internal_catch takes another arg. eval.c: Add long comments describing the "five lists" used to maintain state (backtrace, gcpro, specbind, etc.) in the Lisp engine. backtrace.h, eval.c: Implement trapping-problems mechanism, eliminate old mechanisms or redo in terms of new one. frame.c, gutter.c: Flush out the concept of "critical display section", defined by the in_display() var. Use an internal_bind() to get it reset, rather than just doing it at end, because there may be a non-local exit. event-msw.c, event-stream.c, console-msw.h, device.c, dialog-msw.c, frame.c, frame.h, intl.c, toolbar.c, menubar-msw.c, redisplay.c, alloc.c, menubar-x.c: Make use of new trapping-errors stuff and rewrite code based on old mechanisms. glyphs-widget.c, redisplay.h: Protect calling Lisp in redisplay. insdel.c: Protect hooks against deleting existing buffers. frame-msw.c: Use EQ, not EQUAL in hash tables whose keys are just numbers. Otherwise we run into stickiness in redisplay because internal_equal() can QUIT. ================================================================ SIGNAL, C-G CHANGES ================================================================ Here we change the way that C-g interacts with event reading. The idea is that a C-g occurring while we're reading a user event should be read as C-g, but elsewhere should be a QUIT. The former code did all sorts of bizarreness -- requiring that no QUIT occurs anywhere in event-reading code (impossible to enforce given the stuff called or Lisp code invoked), and having some weird system involving enqueue/dequeue of a C-g and interaction with Vquit_flag -- and it didn't work. Now, we simply enclose all code where we want C-g read as an event with {begin/end}_dont_check_for_quit(). This completely turns off the mechanism that checks (and may remove or alter) C-g in the read-ahead queues, so we just get the C-g normal. Signal.c documents this very carefully. cmdloop.c: Correct use of dont_check_for_quit to new scheme, remove old out-of-date comments. event-stream.c: Fix C-g handling to actually work. device-x.c: Disable quit checking when err out. signal.c: Cleanup. Add large descriptive comment. process-unix.c, process-nt.c, sysdep.c: Use QUIT instead of REALLY_QUIT. It's not necessary to use REALLY_QUIT and just confuses the issue. lisp.h: Comment quit handlers. ================================================================ CONS CHANGES ================================================================ free_cons() now takes a Lisp_Object not the result of XCONS(). car and cdr have been renamed so that they don't get used directly; go through XCAR(), XCDR() instead. alloc.c, dired.c, editfns.c, emodules.c, fns.c, glyphs-msw.c, glyphs-x.c, glyphs.c, keymap.c, minibuf.c, search.c, eval.c, lread.c, lisp.h: Correct free_cons calling convention: now takes Lisp_Object, not Lisp_Cons chartab.c: Eliminate direct use of ->car, ->cdr, should be black box. callint.c: Rewrote using EXTERNAL_LIST_LOOP to avoid use of Lisp_Cons. ================================================================ USE INTERNAL-BIND-* ================================================================ eval.c: Cleanups of these funs. alloc.c, fileio.c, undo.c, specifier.c, text.c, profile.c, lread.c, redisplay.c, menubar-x.c, macros.c: Rewrote to use internal_bind_int() and internal_bind_lisp_object() in place of whatever varied and cumbersome mechanisms were formerly there. ================================================================ SPECBIND SANITY ================================================================ backtrace.h: - Improved comments backtrace.h, bytecode.c, eval.c: Add new mechanism check_specbind_stack_sanity() for sanity checking code each time the catchlist or specbind stack change. Removed older prototype of same mechanism. ================================================================ MISC ================================================================ lisp.h, insdel.c, window.c, device.c, console.c, buffer.c: Fleshed out authorship. device-msw.c: Correct bad Unicode-ization. print.c: Be more careful when not initialized or in fatal error handling. search.c: Eliminate running_asynch_code, an FSF holdover. alloc.c: Added comments about gc-cons-threshold. dialog-x.c: Use begin_gc_forbidden() around code to build up a widget value tree, like in menubar-x.c. gui.c: Use Qunbound not Qnil as the default for gethash. lisp-disunion.h, lisp-union.h: Added warnings on use of VOID_TO_LISP(). lisp.h: Use ERROR_CHECK_STRUCTURES to turn on ERROR_CHECK_TRAPPING_PROBLEMS and ERROR_CHECK_TYPECHECK lisp.h: Add assert_with_message. lisp.h: Add macros for gcproing entire arrays. (You could do this before but it required manual twiddling the gcpro structure.) lisp.h: Add prototypes for new functions defined elsewhere.
author ben
date Tue, 28 May 2002 08:45:36 +0000
parents 047d37eb70d7
children 1d8fb2eee1bb
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.
784
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
5 Copyright (C) 1995, 1996, 2001, 2002 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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 XEmacs is free software; you can redistribute it and/or modify it
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 later version.
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
24 /* This file has been Mule-ized. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 /* 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
27 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
28 the original author(s).
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
29
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
30 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
31 callproc.c, 4-3-02, Ben Wing.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
32
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
33 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
34 */
428
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 <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
38 #if defined (NO_SUBPROCESSES)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
39 #error "We don't support this anymore."
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
40 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 #include "commands.h"
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
46 #include "device.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 #include "events.h"
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
48 #include "file-coding.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 #include "frame.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 #include "hash.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 #include "insdel.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 #include "lstream.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 #include "opaque.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 #include "process.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 #include "procimpl.h"
816
39b1580316c8 [xemacs-hg @ 2002-04-15 09:42:17 by ben]
ben
parents: 814
diff changeset
56 #include "sysdep.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 #include "window.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 #include "sysfile.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 #include "sysproc.h"
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
61 #include "syssignal.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 #include "systime.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 #include "systty.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 #include "syswait.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
66 Lisp_Object Qprocessp, Qprocess_live_p;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 /* Process methods */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 struct process_methods the_process_methods;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 /* 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
72 (name of name of port we are connected to . foreign host name) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 /* Valid values of process->status_symbol */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 Lisp_Object Qrun, Qstop;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 /* Qrun => Qopen, Qexit => Qclosed for "network connection" processes */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 Lisp_Object Qopen, Qclosed;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 /* Protocol families */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 Lisp_Object Qtcp, Qudp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 #ifdef HAVE_MULTICAST
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 Lisp_Object Qmulticast; /* Will be used for occasional warnings */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 /* t means use pty, nil means use a pipe,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 maybe other values to come. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 Lisp_Object Vprocess_connection_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 /* Read comments to DEFVAR of this */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 int windowed_process_io;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 #ifdef PROCESS_IO_BLOCKING
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 /* 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
94 Nil means set a non-blocking I/O mode [default]. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 Lisp_Object network_stream_blocking_port_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 #endif /* PROCESS_IO_BLOCKING */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 /* Number of events of change of status of a process. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 volatile int process_tick;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 /* Number of events for which the user or sentinel has been notified. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 static int update_tick;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 /* Nonzero means delete a process right away if it exits. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 int delete_exited_processes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
107 /* 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
108 process objects. Processes are not GC-protected through this! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 struct hash_table *usid_to_process;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 /* List of process objects. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 Lisp_Object Vprocess_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
114 Lisp_Object Vnull_device;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
116 /* Cons of coding systems used to initialize process I/O on a newly-
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
117 created process. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
118 Lisp_Object Vdefault_process_coding_system;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
119 /* Same for a network connection. */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
120 Lisp_Object Vdefault_network_coding_system;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
121
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
122 Lisp_Object Qprocess_error;
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
123 Lisp_Object Qnetwork_error;
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
124
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
125 Fixnum debug_process_io;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
126
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
127 Lisp_Object Vshell_file_name;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
128
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
129 /* The environment to pass to all subprocesses when they are started.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
130 This is in the semi-bogus format of ("VAR=VAL" "VAR2=VAL2" ... )
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
131 */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
132 Lisp_Object Vprocess_environment;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
133
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
134 /* Make sure egetenv() not called too soon */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
135 int env_initted;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
136
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
137 Lisp_Object Vlisp_EXEC_SUFFIXES;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
138
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 static Lisp_Object
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
142 mark_process (Lisp_Object object)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
144 Lisp_Process *process = XPROCESS (object);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
145 MAYBE_PROCMETH (mark_process_data, (process));
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
146 mark_object (process->name);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
147 mark_object (process->command);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
148 mark_object (process->filter);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
149 mark_object (process->stderr_filter);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
150 mark_object (process->sentinel);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
151 mark_object (process->buffer);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
152 mark_object (process->mark);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
153 mark_object (process->stderr_buffer);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
154 mark_object (process->stderr_mark);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
155 mark_object (process->pid);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
156 mark_object (process->pipe_instream);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
157 mark_object (process->pipe_outstream);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
158 mark_object (process->pipe_errstream);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
159 mark_object (process->coding_instream);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
160 mark_object (process->coding_outstream);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
161 mark_object (process->coding_errstream);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
162 return process->status_symbol;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 static void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
166 print_process (Lisp_Object object, Lisp_Object printcharfun, int escapeflag)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
168 Lisp_Process *process = XPROCESS (object);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 if (print_readably)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
171 printing_unreadable_object ("#<process %s>", XSTRING_DATA (process->name));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 if (!escapeflag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
175 print_internal (process->name, printcharfun, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
179 int netp = network_connection_p (object);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 816
diff changeset
180 write_c_string (printcharfun,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 816
diff changeset
181 netp ? GETTEXT ("#<network connection ") :
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 816
diff changeset
182 GETTEXT ("#<process "));
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
183 print_internal (process->name, printcharfun, 1);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 816
diff changeset
184 write_c_string (printcharfun, (netp ? " " : " pid "));
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
185 print_internal (process->pid, printcharfun, 1);
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
186 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
187 MAYBE_PROCMETH (print_process_data, (process, printcharfun));
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 816
diff changeset
188 write_c_string (printcharfun, ">");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 #ifdef HAVE_WINDOW_SYSTEM
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
193 extern void debug_process_finalization (Lisp_Process *p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 #endif /* HAVE_WINDOW_SYSTEM */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 finalize_process (void *header, int for_disksave)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 /* #### this probably needs to be tied into the tty event loop */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 /* #### when there is one */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
201 Lisp_Process *p = (Lisp_Process *) header;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 #ifdef HAVE_WINDOW_SYSTEM
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 if (!for_disksave)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 debug_process_finalization (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 #endif /* HAVE_WINDOW_SYSTEM */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 if (p->process_data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 MAYBE_PROCMETH (finalize_process_data, (p, for_disksave));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 if (!for_disksave)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 xfree (p->process_data);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 DEFINE_LRECORD_IMPLEMENTATION ("process", process,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 mark_process, print_process, finalize_process,
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
219 0, 0, 0, Lisp_Process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 /* basic process accessors */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
225 /* 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
226 process, rather than en/decoding streams */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 void
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
228 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
229 Lisp_Object *errstr)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 assert (p);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
232 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
233 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
234 assert (NILP (p->pipe_errstream) || LSTREAMP (p->pipe_errstream));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 *instr = p->pipe_instream;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 *outstr = p->pipe_outstream;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
237 *errstr = p->pipe_errstream;
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
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
240 /* 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
241 return the associated process. */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
242 Lisp_Process *
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 get_process_from_usid (USID usid)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
245 const void *vval;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 assert (usid != USID_ERROR && usid != USID_DONTHASH);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
249 if (gethash ((const void*)usid, usid_to_process, &vval))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
251 Lisp_Object process;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 816
diff changeset
252 process = VOID_TO_LISP (vval);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
253 return XPROCESS (process);
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 int
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
260 get_process_selected_p (Lisp_Process *p, int do_err)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 {
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
262 return do_err ? p->err_selected : p->in_selected;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 void
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
266 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
267 {
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
268 p->in_selected = !!in_selected;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
269 p->err_selected = !!err_selected;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 int
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
273 connected_via_filedesc_p (Lisp_Process *p)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 return MAYBE_INT_PROCMETH (tooltalk_connection_p, (p));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 #ifdef HAVE_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 network_connection_p (Lisp_Object process)
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 return CONSP (XPROCESS (process)->pid);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 DEFUN ("processp", Fprocessp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 Return t if OBJECT is a process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
289 (object))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
291 return PROCESSP (object) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
294 DEFUN ("process-live-p", Fprocess_live_p, 1, 1, 0, /*
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
295 Return t if OBJECT is a process that is alive.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
296 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
297 (object))
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
298 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
299 return PROCESSP (object) && PROCESS_LIVE_P (XPROCESS (object))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
300 ? Qt : Qnil;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
301 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
302
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 DEFUN ("process-list", Fprocess_list, 0, 0, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 Return a list of all processes.
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 ())
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 return Fcopy_sequence (Vprocess_list);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 DEFUN ("get-process", Fget_process, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
312 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
313 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
314 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
315 (process_name))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
317 if (PROCESSP (process_name))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
318 return process_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 if (!gc_in_progress)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 /* 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
322 of a signal or crash. */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
323 CHECK_STRING (process_name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
325 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
326 LIST_LOOP_2 (process, Vprocess_list)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
327 if (internal_equal (process_name, XPROCESS (process)->name, 0))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
328 return process;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
329 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 DEFUN ("get-buffer-process", Fget_buffer_process, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 Return the (or, a) process associated with BUFFER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 BUFFER may be a buffer or the name of one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
337 (buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
339 if (NILP (buffer)) return Qnil;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
340 buffer = Fget_buffer (buffer);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
341 if (NILP (buffer)) return Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
343 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
344 LIST_LOOP_2 (process, Vprocess_list)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
345 if (EQ (XPROCESS (process)->buffer, buffer))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
346 return process;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
347 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 /* This is how commands for the user decode process arguments. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 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
353 Buffers denote the first process in the buffer, and nil denotes the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 current buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 get_process (Lisp_Object name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
359 Lisp_Object buffer;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 #ifdef I18N3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 /* #### Look more closely into translating process names. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 /* This may be called during a GC from process_send_signal() from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 kill_buffer_processes() if emacs decides to abort(). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 if (PROCESSP (name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 return name;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
369 else if (STRINGP (name))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
371 Lisp_Object object = Fget_process (name);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
372 if (PROCESSP (object))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
373 return object;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
374
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
375 buffer = Fget_buffer (name);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
376 if (BUFFERP (buffer))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
377 goto have_buffer_object;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
378
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
379 invalid_argument ("Process does not exist", name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 else if (NILP (name))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
382 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
383 buffer = Fcurrent_buffer ();
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
384 goto have_buffer_object;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
385 }
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
386 else if (BUFFERP (name))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
387 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
388 Lisp_Object process;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
389 buffer = name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
391 have_buffer_object:
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
392 process = Fget_buffer_process (buffer);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
393 if (PROCESSP (process))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
394 return process;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
395
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
396 invalid_argument ("Buffer has no process", buffer);
428
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 else
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
399 return get_process (Fsignal (Qwrong_type_argument,
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
400 (list2 (build_msg_string ("process or buffer or nil"),
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
401 name))));
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 DEFUN ("process-id", Fprocess_id, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 Return the process id of PROCESS.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 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
407 For a network connection, this value is a cons of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 (foreign-network-port . foreign-host-name).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
410 (process))
428
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 Lisp_Object pid;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
413 CHECK_PROCESS (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
415 pid = XPROCESS (process)->pid;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
416 if (network_connection_p (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 /* return Qnil; */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 return Fcons (Fcar (pid), Fcdr (pid));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 return pid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 DEFUN ("process-name", Fprocess_name, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 Return the name of PROCESS, as a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 This is the name of the program invoked in PROCESS,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 possibly modified to make it unique among process names.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
428 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
430 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
431 return XPROCESS (process)->name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 DEFUN ("process-command", Fprocess_command, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 Return the command that was executed to start PROCESS.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 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
437 and the rest of the strings being the arguments given to it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
439 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
441 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
442 return XPROCESS (process)->command;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 /* creating a process */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
450 DOESNT_RETURN
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
451 report_process_error (const char *string, Lisp_Object data)
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
452 {
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
453 report_error_with_errno (Qprocess_error, string, data);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
454 }
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
455
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
456 DOESNT_RETURN
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
457 report_network_error (const char *string, Lisp_Object data)
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
458 {
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
459 report_error_with_errno (Qnetwork_error, string, data);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
460 }
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
461
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 make_process_internal (Lisp_Object name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 Lisp_Object val, name1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 int i;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
467 Lisp_Process *p = alloc_lcrecord_type (Lisp_Process, &lrecord_process);
428
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 /* If name is already in use, modify it until it is unused. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 name1 = name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 for (i = 1; ; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 char suffix[10];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 Lisp_Object tem = Fget_process (name1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 if (NILP (tem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 sprintf (suffix, "<%d>", i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 name1 = concat2 (name, build_string (suffix));
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 name = name1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 p->name = name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 p->command = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 p->filter = Qnil;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
485 p->stderr_filter = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 p->sentinel = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 p->buffer = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 p->mark = Fmake_marker ();
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
489 p->stderr_buffer = Qnil;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
490 p->stderr_mark = Fmake_marker ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 p->pid = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 p->status_symbol = Qrun;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 p->exit_code = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 p->core_dumped = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 p->filter_does_read = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 p->kill_without_query = 0;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
497 p->separate_stderr = 0;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
498 p->in_selected = 0;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
499 p->err_selected = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 p->tick = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 p->update_tick = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 p->pipe_instream = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 p->pipe_outstream = Qnil;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
504 p->pipe_errstream = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 p->coding_instream = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 p->coding_outstream = Qnil;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
507 p->coding_errstream = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 p->process_data = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 MAYBE_PROCMETH (alloc_process_data, (p));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 784
diff changeset
512 val = wrap_process (p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 Vprocess_list = Fcons (val, Vprocess_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 return val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 void
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
519 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
520 int flags)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 {
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
522 USID in_usid, err_usid;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
523 Lisp_Object incode, outcode;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
524
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
525 if (flags & STREAM_NETWORK_CONNECTION)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
526 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
527 if (!CONSP (Vdefault_network_coding_system) ||
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
528 NILP (incode = (find_coding_system_for_text_file
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
529 (Fcar (Vdefault_network_coding_system), 1))) ||
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
530 NILP (outcode = (find_coding_system_for_text_file
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
531 (Fcdr (Vdefault_network_coding_system), 0))))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
532 signal_error (Qinvalid_state,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
533 "Bogus value for `default-network-coding-system'",
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
534 Vdefault_network_coding_system);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
535 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
536 else
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
537 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
538 if (!CONSP (Vdefault_process_coding_system) ||
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
539 NILP (incode = (find_coding_system_for_text_file
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
540 (Fcar (Vdefault_process_coding_system), 1))) ||
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
541 NILP (outcode = (find_coding_system_for_text_file
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
542 (Fcdr (Vdefault_process_coding_system), 0))))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
543 signal_error (Qinvalid_state,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
544 "Bogus value for `default-process-coding-system'",
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
545 Vdefault_process_coding_system);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
546 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
547
784
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
548 if (!NILP (Vcoding_system_for_read) &&
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
549 NILP (incode = (find_coding_system_for_text_file
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
550 (Vcoding_system_for_read, 1))))
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
551 signal_error (Qinvalid_state,
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
552 "Bogus value for `coding-system-for-read'",
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
553 Vcoding_system_for_read);
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
554
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
555 if (!NILP (Vcoding_system_for_write) &&
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
556 NILP (outcode = (find_coding_system_for_text_file
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
557 (Vcoding_system_for_write, 0))))
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
558 signal_error (Qinvalid_state,
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
559 "Bogus value for `coding-system-for-write'",
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
560 Vcoding_system_for_write);
11e10b9141d0 [xemacs-hg @ 2002-03-19 03:12:46 by ben]
ben
parents: 771
diff changeset
561
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
562 event_stream_create_io_streams (in, out, err,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
563 &p->pipe_instream,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
564 &p->pipe_outstream,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
565 &p->pipe_errstream,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
566 &in_usid, &err_usid,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
567 flags);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
569 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
570 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
571 wrap_process (p));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
573 if (in_usid != USID_DONTHASH)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
575 Lisp_Object process = Qnil;
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 784
diff changeset
576 process = wrap_process (p);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
577 puthash ((const void*) in_usid, LISP_TO_VOID (process), usid_to_process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
580 if (err_usid != USID_DONTHASH)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
581 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
582 Lisp_Object process = Qnil;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
583 process = wrap_process (p);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
584 puthash ((const void*) err_usid, LISP_TO_VOID (process),
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
585 usid_to_process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
586 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
587
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
588 MAYBE_PROCMETH (init_process_io_handles, (p, in, out, err, flags));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
590 p->coding_instream =
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
591 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
592 CODING_DECODE, 0);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
593 if (!NILP (p->pipe_errstream))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
594 p->coding_errstream =
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
595 make_coding_input_stream
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
596 (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
597 p->coding_outstream =
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
598 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
599 CODING_ENCODE, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 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
604 Lisp_Object program, Lisp_Object cur_dir,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
605 int separate_err)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
607 Lisp_Process *p = XPROCESS (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 int pid;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 /* *_create_process may change status_symbol, if the process
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 is a kind of "fire-and-forget" (no I/O, unwaitable) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 p->status_symbol = Qrun;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 p->exit_code = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
615 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
616 separate_err));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 p->pid = make_int (pid);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
619 if (PROCESS_LIVE_P (p))
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
620 event_stream_select_process (p, 1, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 /* 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
624 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
625 an error and the process wasn't started successfully, so we should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 remove it from the process list. */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
627 static void remove_process (Lisp_Object process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 static Lisp_Object
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
629 start_process_unwind (Lisp_Object process)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
631 /* Was PROCESS started successfully? */
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
632 if (EQ (XPROCESS (process)->pid, Qnil))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
633 remove_process (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 return Qnil;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 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
638 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
639 Lisp callers should use `start-process' instead.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
640
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
641 Returns the process object for it.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 Args are NAME BUFFER PROGRAM &rest PROGRAM-ARGS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 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
644 BUFFER is the buffer or (buffer-name) to associate with the process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 Process output goes at end of that buffer, unless you specify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 an output stream or filter function to handle the output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 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
648 with any buffer.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
649 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
650 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
651 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
652 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
653 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
654 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
655 changed, even by setting a stderr filter.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 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
657 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
658
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
659 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
660 `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
661 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
662 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
663 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
664 `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
665
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
666 See also `set-process-filter' and `set-process-stderr-filter'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 /* This function can call lisp */
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
671 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
672 int separate_stderr;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 Lisp_Object tem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 int speccount = specpdl_depth ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 struct gcpro gcpro1, gcpro2, gcpro3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 name = args[0];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 buffer = args[1];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 program = args[2];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 current_dir = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 /* Protect against various file handlers doing GCs below. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 GCPRO3 (buffer, program, current_dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
685 if (CONSP (buffer))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
686 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
687 if (!CONSP (XCDR (buffer)))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
688 invalid_argument ("Invalid BUFFER argument to `start-process'",
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
689 buffer);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
690 if (!NILP (XCDR (XCDR (buffer))))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
691 invalid_argument ("Invalid BUFFER argument to `start-process'",
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
692 buffer);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
693 stderr_buffer = XCAR (XCDR (buffer));
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
694 buffer = XCAR (buffer);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
695 separate_stderr = 1;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
696 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
697 else
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
698 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
699 stderr_buffer = Qnil;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
700 separate_stderr = 0;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
701 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
702
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 if (!NILP (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 buffer = Fget_buffer_create (buffer);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
705 if (!NILP (stderr_buffer))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
706 stderr_buffer = Fget_buffer_create (stderr_buffer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 CHECK_STRING (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 CHECK_STRING (program);
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 /* 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
712 buffer's current directory, or its unhandled equivalent. [[ We
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 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
714 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
715 vfork. -ben
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 444
diff changeset
717 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
718 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
719 GC-protected. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 current_dir = current_buffer->directory;
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 444
diff changeset
721 /* 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
722 results, so put the slash back. */
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 444
diff changeset
723 current_dir = Ffile_name_as_directory (current_dir);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 current_dir = Funhandled_file_name_directory (current_dir);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 current_dir = expand_and_dir_to_file (current_dir, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 #if 0 /* This loser breaks ange-ftp */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 /* dmoore - if you re-enable this code, you have to gcprotect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 current_buffer through the above calls. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 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
731 signal_error (Qprocess_error, "Setting current directory",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
732 current_buffer->directory);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 #endif /* 0 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 /* 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
736 if (!IS_DIRECTORY_SEP (string_byte (program, 0))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 && !(XSTRING_LENGTH (program) > 1
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 816
diff changeset
738 && IS_DEVICE_SEP (string_byte (program, 1))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 struct gcpro ngcpro1;
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 tem = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 NGCPRO1 (tem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 locate_file (Vexec_path, program, Vlisp_EXEC_SUFFIXES, &tem, X_OK);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 if (NILP (tem))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
746 signal_error (Qprocess_error, "Searching for program", program);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 program = Fexpand_file_name (tem, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 NUNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
752 /* 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
753 ending, e.g. .exe */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
754 struct gcpro ngcpro1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
755
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
756 tem = Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
757 NGCPRO1 (tem);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
758 locate_file (list1 (build_string ("")), program, Vlisp_EXEC_SUFFIXES,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
759 &tem, X_OK);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
760 if (NILP (tem))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
761 signal_error (Qprocess_error, "Searching for program", program);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
762 program = tem;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
763 NUNGCPRO;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
766 if (!NILP (Ffile_directory_p (program)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
767 invalid_operation ("Specified program for new process is a directory",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
768 program);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
769
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
770 process = make_process_internal (name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
772 XPROCESS (process)->buffer = buffer;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
773 XPROCESS (process)->stderr_buffer = stderr_buffer;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
774 XPROCESS (process)->separate_stderr = separate_stderr;
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
775 XPROCESS (process)->command = Flist (nargs - 2, args + 2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 /* Make the process marker point into the process buffer (if any). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 if (!NILP (buffer))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
779 Fset_marker (XPROCESS (process)->mark,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 make_int (BUF_ZV (XBUFFER (buffer))), buffer);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
781 if (!NILP (stderr_buffer))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
782 Fset_marker (XPROCESS (process)->stderr_mark,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
783 make_int (BUF_ZV (XBUFFER (stderr_buffer))), stderr_buffer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 /* 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
786 remove it from the process list. This means that each error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 check in create_process doesn't need to call remove_process
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 itself; it's all taken care of here. */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
789 record_unwind_protect (start_process_unwind, process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
791 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
792 separate_stderr);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 UNGCPRO;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
795 return unbind_to_1 (speccount, process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 #ifdef HAVE_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 /* #### The network support is fairly synthetical. What we actually
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 need is a single function, which supports all datagram, stream and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 packet stream connections, arbitrary protocol families should they
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 be supported by the target system, multicast groups, in both data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 and control rooted/nonrooted flavors, service quality etc whatever
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 is supported by the underlying network.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 It must accept a property list describing the connection. The current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 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
811 generalized connection function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 Both UNIX and Win32 support BSD sockets, and there are many extensions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 available (Sockets 2 spec).
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 A todo is define a consistent set of properties abstracting a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 network connection. -kkm
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 /* open a TCP network connection to a given HOST/SERVICE. Treated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 exactly like a normal process when reading and writing. Only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 differences are in status display and process deletion. A network
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 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
825 deactivate and close it via delete-process */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
827 DEFUN ("open-network-stream-internal", Fopen_network_stream_internal, 4, 5,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
828 0, /*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 Open a TCP connection for a service to a host.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
830 Return a process object to represent the connection.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 Input and output work as for subprocesses; `delete-process' closes it.
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 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
834 BUFFER is the buffer (or buffer-name) to associate with the process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 Process output goes at end of that buffer, unless you specify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 an output stream or filter function to handle the output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 BUFFER may also be nil, meaning that this process is not associated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 with any buffer.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
839 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
840 or its IP address.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
841 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
842 or an integer specifying a port number to connect to.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
843 Optional fifth arg PROTOCOL is a network protocol. Currently only 'tcp
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 (Transmission Control Protocol) and 'udp (User Datagram Protocol) are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 supported. When omitted, 'tcp is assumed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
847 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
848 `set-process-filter') are stream-oriented. That means UDP datagrams are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 not guaranteed to be sent and received in discrete packets. (But small
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 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
851 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
852 against lost packets.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 (name, buffer, host, service, protocol))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 /* This function can GC */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
857 Lisp_Object process = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5, ngcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 void *inch, *outch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 GCPRO5 (name, buffer, host, service, protocol);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 CHECK_STRING (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
864 if (NILP (protocol))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 protocol = Qtcp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 CHECK_SYMBOL (protocol);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 /* Since this code is inside HAVE_SOCKETS, existence of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 open_network_stream is mandatory */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 PROCMETH (open_network_stream, (name, host, service, protocol,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 &inch, &outch));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 if (!NILP (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 buffer = Fget_buffer_create (buffer);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
876 process = make_process_internal (name);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
877 NGCPRO1 (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
879 XPROCESS (process)->pid = Fcons (service, host);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
880 XPROCESS (process)->buffer = buffer;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
881 init_process_io_handles (XPROCESS (process), (void *) inch, (void *) outch,
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
882 (void *) -1,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 STREAM_NETWORK_CONNECTION);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
885 event_stream_select_process (XPROCESS (process), 1, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 NUNGCPRO;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
889 return process;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 #ifdef HAVE_MULTICAST
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 DEFUN ("open-multicast-group-internal", Fopen_multicast_group_internal, 5, 5, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 Open a multicast connection on the specified dest/port/ttl.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
896 Return a process object to represent the connection.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 Input and output work as for subprocesses; `delete-process' closes it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 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
900 BUFFER is the buffer (or buffer-name) to associate with the process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 Process output goes at end of that buffer, unless you specify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 an output stream or filter function to handle the output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 BUFFER may also be nil, meaning that this process is not associated
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 with any buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 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
906 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
907 port is a communication port like in traditional unicast
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 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
909 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 (name, buffer, dest, port, ttl))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 /* This function can GC */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
913 Lisp_Object process = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 void *inch, *outch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 CHECK_STRING (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 /* 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
920 open_multicast_group is mandatory */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 PROCMETH (open_multicast_group, (name, dest, port, ttl,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 &inch, &outch));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 if (!NILP (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 buffer = Fget_buffer_create (buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
927 process = make_process_internal (name);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
928 GCPRO1 (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
930 XPROCESS (process)->pid = Fcons (port, dest);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
931 XPROCESS (process)->buffer = buffer;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
932 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
933 (void *) -1,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 STREAM_NETWORK_CONNECTION);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
936 event_stream_select_process (XPROCESS (process), 1, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 UNGCPRO;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
939 return process;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 #endif /* HAVE_MULTICAST */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 #endif /* HAVE_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 canonicalize_host_name (Lisp_Object host)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 return PROCMETH_OR_GIVEN (canonicalize_host_name, (host), host);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 DEFUN ("set-process-window-size", Fset_process_window_size, 3, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 Tell PROCESS that it has logical window size HEIGHT and WIDTH.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
955 (process, height, width))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
957 CHECK_PROCESS (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 CHECK_NATNUM (height);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 CHECK_NATNUM (width);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 return
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
961 MAYBE_INT_PROCMETH (set_window_size,
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
962 (XPROCESS (process), XINT (height), XINT (width))) <= 0
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 ? Qnil : Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 /* Process I/O */
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
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
971 /* 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
972 mark.
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
973
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
974 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
975 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
976 necessary.
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
977 */
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
978 static int
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
979 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
980 {
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
981 Lisp_Process *p = XPROCESS (process);
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
982 int spec = specpdl_depth ();
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
983 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
984 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
985 struct buffer *buf = XBUFFER (buffer);
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
986 Charbpos output_pt;
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
987
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
988 if (buf != current_buffer)
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
989 {
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
990 record_unwind_protect (save_current_buffer_restore,
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
991 Fcurrent_buffer ());
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
992 set_buffer_internal (buf);
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
993 }
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
994
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
995 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
996 specbind (Qinhibit_read_only, Qt);
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
997
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
998 /* Insert new output into buffer
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
999 at the current end-of-output marker,
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1000 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
1001 if (XMARKER (mark)->buffer)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1002 output_pt = marker_position (mark);
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1003 else
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1004 output_pt = BUF_ZV (buf);
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1005
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1006 /* 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
1007 the restriction and widen. */
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1008 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
1009 {
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1010 record_unwind_protect (save_restriction_restore,
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1011 save_restriction_save (buf));
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1012 Fwiden (wrap_buffer (buf));
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1013 }
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1014
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1015 BUF_SET_PT (buf, output_pt);
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1016 return spec;
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1017 }
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1018
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 /* Read pending output from the process channel,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 starting with our buffered-ahead character if we have one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 Yield number of characters read.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 This function reads at most 1024 bytes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 If you want to read all available subprocess output,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 you must call it repeatedly until it returns zero. */
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 Charcount
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1028 read_process_output (Lisp_Object process, int read_stderr)
428
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 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 Bytecount nbytes, nchars;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1032 Intbyte chars[1025];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 Lisp_Object outstream;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1034 Lisp_Process *p = XPROCESS (process);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1035 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
1036 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
1037 Lisp_Object mark = read_stderr ? p->stderr_mark : p->mark;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 /* 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
1040 execute_internal_event() might call read_process_output() more
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 than once. If the filter that was executed from one of these
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 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
1043 than 0 so execute_internal_event() doesn't close the process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 Really, the loop in execute_internal_event() should check itself
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 for a process-filter change, like in status_notify(); but the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 struct Lisp_Process is not exported outside of this file. */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1047 if (!PROCESS_LIVE_P (p))
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1048 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1049 errno = 0;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1050 return -1; /* already closed */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1051 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1053 if (!NILP (filter) && (p->filter_does_read))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 Lisp_Object filter_result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 /* Some weird FSFmacs crap here with
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1058 Vdeactivate_mark and current_buffer->keymap.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1059 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
1060 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
1061 asynchronously (i.e. from within QUIT). */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1062 /* 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
1063 filter_result = call2 (filter, process, Qnil);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 CHECK_INT (filter_result);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 return XINT (filter_result);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1068 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
1069 XLSTREAM (DATA_INSTREAM (p)), chars,
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1070 sizeof (chars) - 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 if (nbytes <= 0) return nbytes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1073 if (debug_process_io)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1074 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1075 chars[nbytes] = '\0';
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1076 stderr_out ("Read: %s\n", chars);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1077 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1078
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1079 /* !!#### 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
1080 need to change the output coding system accordingly. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 nchars = bytecount_to_charcount (chars, nbytes);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1082 outstream = filter;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 if (!NILP (outstream))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 {
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1085 /* 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
1086 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
1087 asynchronously (i.e. from within QUIT). */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1088 /* 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
1089 call2 (outstream, process, make_string (chars, nbytes));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 return nchars;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 /* 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
1094 if (!NILP (buffer) && BUFFER_LIVE_P (XBUFFER (buffer)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 {
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1096 struct gcpro gcpro1;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1097 struct buffer *buf = XBUFFER (buffer);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1098 int spec = process_setup_for_insertion (process, read_stderr);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1100 GCPRO1 (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 /* This screws up initial display of the window. jla */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 /* Insert before markers in case we are inserting where
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 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
1107 buffer_insert_raw_string_1 (buf, -1, chars,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 nbytes, INSDEL_BEFORE_MARKERS);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 buffer_insert_raw_string (buf, chars, nbytes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 #endif
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 Fset_marker (mark, make_int (BUF_PT (buf)), buffer);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1114
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 MARK_MODELINE_CHANGED;
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1116 unbind_to (spec);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 return nchars;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 }
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1121
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1122 int
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1123 process_has_separate_stderr (Lisp_Object process)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1124 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1125 return XPROCESS (process)->separate_stderr;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1126 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1127
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 /* Sending data to subprocess */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1131 /* 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
1132 specifies the address of the data. Otherwise, the data comes from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 object RELOCATABLE (either a string or a buffer). START and LEN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 specify the offset and length of the data to send.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 563
diff changeset
1136 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
1137 and in Bytecounts otherwise. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1140 send_process (Lisp_Object process,
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 563
diff changeset
1141 Lisp_Object relocatable, const Intbyte *nonrelocatable,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 int start, int len)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 struct gcpro gcpro1, gcpro2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 Lisp_Object lstream = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1148 GCPRO2 (process, lstream);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1150 if (NILP (DATA_OUTSTREAM (XPROCESS (process))))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
1151 invalid_operation ("Process not open for writing", process);
428
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 (nonrelocatable)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 lstream =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 make_fixed_buffer_input_stream (nonrelocatable + start, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 else if (BUFFERP (relocatable))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 lstream = make_lisp_buffer_input_stream (XBUFFER (relocatable),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 start, start + len, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 lstream = make_lisp_string_input_stream (relocatable, start, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1162 if (debug_process_io)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1163 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1164 if (nonrelocatable)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1165 stderr_out ("Writing: %s\n", nonrelocatable);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1166 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1167 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1168 stderr_out ("Writing: ");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1169 print_internal (relocatable, Qexternal_debugging_output, 0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1170 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1171 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1172
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1173 PROCMETH (send_process, (process, XLSTREAM (lstream)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 Lstream_delete (XLSTREAM (lstream));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 }
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 DEFUN ("process-tty-name", Fprocess_tty_name, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 Return the name of the terminal PROCESS uses, or nil if none.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 This is the terminal that the process itself reads and writes on,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 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
1183 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1184 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1186 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1187 return MAYBE_LISP_PROCMETH (get_tty_name, (XPROCESS (process)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 DEFUN ("set-process-buffer", Fset_process_buffer, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 Set buffer associated with PROCESS to BUFFER (a buffer, or nil).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1193 (process, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1195 CHECK_PROCESS (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 if (!NILP (buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 CHECK_BUFFER (buffer);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1198 XPROCESS (process)->buffer = buffer;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 return buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 DEFUN ("process-buffer", Fprocess_buffer, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 Return the buffer PROCESS is associated with.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 Output from PROCESS is inserted in this buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 unless PROCESS has a filter.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1207 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1209 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1210 return XPROCESS (process)->buffer;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1213 DEFUN ("set-process-stderr-buffer", Fset_process_stderr_buffer, 2, 2, 0, /*
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1214 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
1215 */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1216 (process, buffer))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1217 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1218 CHECK_PROCESS (process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1219 if (!XPROCESS (process)->separate_stderr)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1220 invalid_change ("stdout and stderr not separate", process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1221 if (!NILP (buffer))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1222 CHECK_BUFFER (buffer);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1223 XPROCESS (process)->stderr_buffer = buffer;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1224 return buffer;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1225 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1226
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1227 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
1228 Return the stderr buffer PROCESS is associated with.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1229 Output from the stderr of PROCESS is inserted in this buffer
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1230 unless PROCESS has a stderr filter.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1231 */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1232 (process))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1233 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1234 CHECK_PROCESS (process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1235 if (!XPROCESS (process)->separate_stderr)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1236 invalid_change ("stdout and stderr not separate", process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1237 return XPROCESS (process)->stderr_buffer;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1238 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1239
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 DEFUN ("process-mark", Fprocess_mark, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 Return the marker for the end of the last output from PROCESS.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1243 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1245 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1246 return XPROCESS (process)->mark;
428
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
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1249 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
1250 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
1251 */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1252 (process))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1253 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1254 CHECK_PROCESS (process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1255 if (!XPROCESS (process)->separate_stderr)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1256 invalid_operation ("stdout and stderr not separate", process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1257 return XPROCESS (process)->stderr_mark;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1258 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1259
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 void
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1261 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
1262 int filter_does_read, int set_stderr)
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 CHECK_PROCESS (process);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1265 if (set_stderr && !XPROCESS (process)->separate_stderr)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1266 invalid_change ("stdout and stderr not separate", process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1267 if (PROCESS_LIVE_P (XPROCESS (process)))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1268 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1269 if (EQ (filter, Qt))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1270 event_stream_unselect_process (XPROCESS (process), !set_stderr,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1271 set_stderr);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1272 else
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1273 event_stream_select_process (XPROCESS (process), !set_stderr,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1274 set_stderr);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1275 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1277 if (set_stderr)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1278 XPROCESS (process)->stderr_filter = filter;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1279 else
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1280 XPROCESS (process)->filter = filter;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1281 XPROCESS (process)->filter_does_read = filter_does_read;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 DEFUN ("set-process-filter", Fset_process_filter, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 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
1286 t means stop accepting output from the process. (If process was created
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1287 with
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1288 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
1289 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
1290 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
1291 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
1292 */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1293 (process, filter))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1294 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1295 set_process_filter (process, filter, 0, 0);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1296 return filter;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1297 }
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 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
1300 Give PROCESS the stderr filter function FILTER; nil means no filter.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301 t means stop accepting output from the process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 When a process has a filter, each time it does output
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 the entire string of output is passed to the filter.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 The filter gets two arguments: the process and the string of output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 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
1306 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1307 (process, filter))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 {
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1309 set_process_filter (process, filter, 0, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 return filter;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 DEFUN ("process-filter", Fprocess_filter, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 Return the filter function of PROCESS; nil if none.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 See `set-process-filter' for more info on filter functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1317 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1319 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1320 return XPROCESS (process)->filter;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1323 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
1324 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
1325 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
1326 */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1327 (process))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1328 {
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1329 CHECK_PROCESS (process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1330 if (!XPROCESS (process)->separate_stderr)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1331 invalid_operation ("stdout and stderr not separate", process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1332 return XPROCESS (process)->stderr_filter;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1333 }
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1334
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1335 DEFUN ("process-send-region", Fprocess_send_region, 3, 4, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1336 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
1337 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
1338 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
1339 is nil, the current buffer's process is used.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1340 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
1341 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
1342 several chunks. This may happen even for shorter regions. Output
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1343 from processes can arrive in between chunks.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1345 (process, start, end, buffer))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 /* This function can GC */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 563
diff changeset
1348 Charbpos bstart, bend;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1349 struct buffer *buf = decode_buffer (buffer, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 784
diff changeset
1351 buffer = wrap_buffer (buf);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1352 process = get_process (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1353 get_buffer_range_char (buf, start, end, &bstart, &bend, 0);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1354
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1355 send_process (process, buffer, 0, bstart, bend - bstart);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 DEFUN ("process-send-string", Fprocess_send_string, 2, 4, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 Send PROCESS the contents of STRING as input.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1361 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
1362 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
1363 is nil, the current buffer's process is used.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1364 Optional arguments START and END specify part of STRING; see `substring'.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1365 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
1366 several chunks. This may happen even for shorter strings. Output
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1367 from processes can arrive in between chunks.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1369 (process, string, start, end))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 /* This function can GC */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1372 Bytecount bstart, bend;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1374 process = get_process (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 CHECK_STRING (string);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1376 get_string_range_byte (string, start, end, &bstart, &bend,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 GB_HISTORICAL_STRING_BEHAVIOR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1379 send_process (process, string, 0, bstart, bend - bstart);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384 DEFUN ("process-input-coding-system", Fprocess_input_coding_system, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 Return PROCESS's input coding system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 (process))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 process = get_process (process);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1390 CHECK_LIVE_PROCESS (process);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1391 return (coding_stream_detected_coding_system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1392 (XLSTREAM (XPROCESS (process)->coding_instream)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393 }
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 DEFUN ("process-output-coding-system", Fprocess_output_coding_system, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 Return PROCESS's output coding system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 (process))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 process = get_process (process);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1401 CHECK_LIVE_PROCESS (process);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1402 return (coding_stream_coding_system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1403 (XLSTREAM (XPROCESS (process)->coding_outstream)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 DEFUN ("process-coding-system", Fprocess_coding_system, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 Return a pair of coding-system for decoding and encoding of PROCESS.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 (process))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411 process = get_process (process);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1412 CHECK_LIVE_PROCESS (process);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1413 return Fcons (coding_stream_detected_coding_system
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 (XLSTREAM (XPROCESS (process)->coding_instream)),
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1415 coding_stream_coding_system
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 (XLSTREAM (XPROCESS (process)->coding_outstream)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 DEFUN ("set-process-input-coding-system", Fset_process_input_coding_system,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 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
1422 This is used for reading data from PROCESS.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 (process, codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1426 codesys = get_coding_system_for_text_file (codesys, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 process = get_process (process);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1428 CHECK_LIVE_PROCESS (process);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1429
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1430 set_coding_stream_coding_system
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 (XLSTREAM (XPROCESS (process)->coding_instream), codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 DEFUN ("set-process-output-coding-system", Fset_process_output_coding_system,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 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
1438 This is used for writing data to PROCESS.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 (process, codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1442 codesys = get_coding_system_for_text_file (codesys, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 process = get_process (process);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1444 CHECK_LIVE_PROCESS (process);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1445
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1446 set_coding_stream_coding_system
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447 (XLSTREAM (XPROCESS (process)->coding_outstream), codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451 DEFUN ("set-process-coding-system", Fset_process_coding_system,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452 1, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1453 Set coding-systems of PROCESS to DECODING and ENCODING.
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1454 DECODING will be used to decode subprocess output and ENCODING to
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1455 encode subprocess input.
428
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 (process, decoding, encoding))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 if (!NILP (decoding))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 Fset_process_input_coding_system (process, decoding);
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 if (!NILP (encoding))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 Fset_process_output_coding_system (process, encoding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 return Qnil;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 /* process status */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 /************************************************************************/
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 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 exec_sentinel_unwind (Lisp_Object datum)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 {
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1476 XPROCESS (XCAR (datum))->sentinel = XCDR (datum);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1477 free_cons (datum);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 static void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1482 exec_sentinel (Lisp_Object process, Lisp_Object reason)
428
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 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 int speccount = specpdl_depth ();
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1486 Lisp_Process *p = XPROCESS (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 Lisp_Object sentinel = p->sentinel;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 if (NILP (sentinel))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 return;
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 /* Some weird FSFmacs crap here with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 Vdeactivate_mark and current_buffer->keymap */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1495 /* 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
1496 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
1497 asynchronously (i.e. from within QUIT). */
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1498
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 /* 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
1500 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
1501
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1502 (#### 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
1503 calling of process filters/sentinels.) */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 p->sentinel = Qnil;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1505 record_unwind_protect (exec_sentinel_unwind,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1506 noseeum_cons (process, sentinel));
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1507 /* 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
1508 call2 (sentinel, process, reason);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1509 unbind_to (speccount);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 DEFUN ("set-process-sentinel", Fset_process_sentinel, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 Give PROCESS the sentinel SENTINEL; nil for none.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 The sentinel is called as a function when the process changes state.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 It gets two arguments: the process, and a string describing the change.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1517 (process, sentinel))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1519 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1520 XPROCESS (process)->sentinel = sentinel;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 return sentinel;
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 ("process-sentinel", Fprocess_sentinel, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 Return the sentinel of PROCESS; nil if none.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526 See `set-process-sentinel' for more info on sentinels.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1528 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1530 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1531 return XPROCESS (process)->sentinel;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1535 const char *
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536 signal_name (int signum)
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 if (signum >= 0 && signum < NSIG)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1539 return (const char *) sys_siglist[signum];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1541 return (const char *) GETTEXT ("unknown signal");
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545 update_process_status (Lisp_Object p,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 Lisp_Object status_symbol,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 int exit_code,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 int core_dumped)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 XPROCESS (p)->tick++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 process_tick++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 XPROCESS (p)->status_symbol = status_symbol;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553 XPROCESS (p)->exit_code = exit_code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 XPROCESS (p)->core_dumped = core_dumped;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555 }
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 /* Return a string describing a process status list. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559 static Lisp_Object
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
1560 status_message (Lisp_Process *p)
428
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 Lisp_Object symbol = p->status_symbol;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563 int code = p->exit_code;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564 int coredump = p->core_dumped;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 Lisp_Object string, string2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567 if (EQ (symbol, Qsignal) || EQ (symbol, Qstop))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569 string = build_string (signal_name (code));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570 if (coredump)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1571 string2 = build_msg_string (" (core dumped)\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573 string2 = build_string ("\n");
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 784
diff changeset
1574 set_string_char (string, 0,
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 816
diff changeset
1575 DOWNCASE (0, string_emchar (string, 0)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576 return concat2 (string, string2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1578 else if (EQ (symbol, Qexit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580 if (code == 0)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1581 return build_msg_string ("finished\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582 string = Fnumber_to_string (make_int (code));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583 if (coredump)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1584 string2 = build_msg_string (" (core dumped)\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586 string2 = build_string ("\n");
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1587 return concat2 (build_msg_string ("exited abnormally with code "),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588 concat2 (string, string2));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591 return Fcopy_sequence (Fsymbol_name (symbol));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 /* Tell status_notify() to check for terminated processes. We do this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595 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
1596 why.) This is also used under Mswin. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 kick_status_notify (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 process_tick++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 /* Report all recent events of a change in process status
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 (either run the sentinel or output a message).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 This is done while Emacs is waiting for keyboard input. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 status_notify (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613 Lisp_Object tail = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614 Lisp_Object symbol = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 Lisp_Object msg = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 struct gcpro gcpro1, gcpro2, gcpro3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 /* 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
1618 Otherwise, we get a race condition if SIGCHLD happens during
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619 this function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1621 (Actually, this is not the case anymore. The code to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622 update the process structures has been moved out of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623 SIGCHLD handler. But for the moment I'm leaving this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624 stuff in -- it can't hurt.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625 int temp_process_tick;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627 MAYBE_PROCMETH (reap_exited_processes, ());
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 temp_process_tick = process_tick;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 if (update_tick == temp_process_tick)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 /* We need to gcpro tail; if read_process_output calls a filter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 which deletes a process and removes the cons to which tail points
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636 from Vprocess_alist, and then causes a GC, tail is an unprotected
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 reference. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638 GCPRO3 (tail, symbol, msg);
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 for (tail = Vprocess_list; CONSP (tail); tail = XCDR (tail))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1642 Lisp_Object process = XCAR (tail);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1643 Lisp_Process *p = XPROCESS (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1644 /* p->tick is also volatile. Same thing as above applies. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645 int this_process_tick;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1646
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1647 /* #### extra check for terminated processes, in case a SIGCHLD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648 got missed (this seems to happen sometimes, I'm not sure why).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1650 if (INTP (p->pid))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651 MAYBE_PROCMETH (update_status_if_terminated, (p));
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 this_process_tick = p->tick;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654 if (this_process_tick != p->update_tick)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656 p->update_tick = this_process_tick;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 /* If process is still active, read any output that remains. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659 while (!EQ (p->filter, Qt)
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1660 && read_process_output (process, 0) > 0)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1661 ;
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1662 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
1663 && read_process_output (process, 1) > 0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 ;
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 /* Get the text to use for the message. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 msg = status_message (p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669 /* If process is terminated, deactivate it or delete it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670 symbol = p->status_symbol;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672 if (EQ (symbol, Qsignal)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 || EQ (symbol, Qexit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 if (delete_exited_processes)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1676 remove_process (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1677 else
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1678 deactivate_process (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 /* Now output the message suitably. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682 if (!NILP (p->sentinel))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1683 exec_sentinel (process, msg);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 /* Don't bother with a message in the buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 when a process becomes runnable. */
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1686 else if (!EQ (symbol, Qrun) && !NILP (p->buffer) &&
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1687 /* Avoid error if buffer is deleted
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1688 (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
1689 BUFFER_LIVE_P (XBUFFER (p->buffer)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 {
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1691 struct gcpro ngcpro1;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
1692 int spec = process_setup_for_insertion (process, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1694 NGCPRO1 (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695 buffer_insert_c_string (current_buffer, "\nProcess ");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696 Finsert (1, &p->name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697 buffer_insert_c_string (current_buffer, " ");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698 Finsert (1, &msg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 Fset_marker (p->mark, make_int (BUF_PT (current_buffer)),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 p->buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 826
diff changeset
1702 unbind_to (spec);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 NUNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706 } /* end for */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708 /* in case buffers use %s in modeline-format */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 MARK_MODELINE_CHANGED;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 redisplay ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 update_tick = temp_process_tick;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717 DEFUN ("process-status", Fprocess_status, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 Return the status of PROCESS.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719 This is a symbol, one of these:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 run -- for a process that is running.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 stop -- for a process stopped but continuable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723 exit -- for a process that has exited.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 signal -- for a process that has got a fatal signal.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725 open -- for a network stream connection that is open.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 closed -- for a network stream connection that is closed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 nil -- if arg is a process name and no such process exists.
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 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
1730 nil, indicating the current buffer's process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1732 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734 Lisp_Object status_symbol;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1736 if (STRINGP (process))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1737 process = Fget_process (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738 else
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1739 process = get_process (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1741 if (NILP (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1744 status_symbol = XPROCESS (process)->status_symbol;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1745 if (network_connection_p (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1747 if (EQ (status_symbol, Qrun))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1748 status_symbol = Qopen;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1749 else if (EQ (status_symbol, Qexit))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1750 status_symbol = Qclosed;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1751 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752 return status_symbol;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 DEFUN ("process-exit-status", Fprocess_exit_status, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756 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
1757 If PROCESS has not yet exited or died, return 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1759 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1761 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1762 return make_int (XPROCESS (process)->exit_code);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1767 static int
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1768 decode_signal (Lisp_Object signal_)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1770 if (INTP (signal_))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1771 return XINT (signal_);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1772 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 563
diff changeset
1774 Intbyte *name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1775
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1776 CHECK_SYMBOL (signal_);
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 784
diff changeset
1777 name = XSTRING_DATA (XSYMBOL (signal_)->name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1778
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 784
diff changeset
1779 #define handle_signal(sym) do { \
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 784
diff changeset
1780 if (!qxestrcmp_c ( name, #sym)) \
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 784
diff changeset
1781 return sym; \
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1782 } while (0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784 handle_signal (SIGINT); /* ANSI */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 handle_signal (SIGILL); /* ANSI */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786 handle_signal (SIGABRT); /* ANSI */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 handle_signal (SIGFPE); /* ANSI */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788 handle_signal (SIGSEGV); /* ANSI */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789 handle_signal (SIGTERM); /* ANSI */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1791 #ifdef SIGHUP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792 handle_signal (SIGHUP); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794 #ifdef SIGQUIT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795 handle_signal (SIGQUIT); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1796 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 #ifdef SIGTRAP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798 handle_signal (SIGTRAP); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1800 #ifdef SIGKILL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801 handle_signal (SIGKILL); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 #ifdef SIGUSR1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 handle_signal (SIGUSR1); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1806 #ifdef SIGUSR2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807 handle_signal (SIGUSR2); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809 #ifdef SIGPIPE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810 handle_signal (SIGPIPE); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1811 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812 #ifdef SIGALRM
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1813 handle_signal (SIGALRM); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1814 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815 #ifdef SIGCHLD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816 handle_signal (SIGCHLD); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1817 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1818 #ifdef SIGCONT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819 handle_signal (SIGCONT); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1820 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 #ifdef SIGSTOP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1822 handle_signal (SIGSTOP); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1823 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1824 #ifdef SIGTSTP
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825 handle_signal (SIGTSTP); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1826 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1827 #ifdef SIGTTIN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1828 handle_signal (SIGTTIN); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1829 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830 #ifdef SIGTTOU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831 handle_signal (SIGTTOU); /* POSIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1832 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1833
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1834 #ifdef SIGBUS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1835 handle_signal (SIGBUS); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1837 #ifdef SIGPOLL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1838 handle_signal (SIGPOLL); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1840 #ifdef SIGPROF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1841 handle_signal (SIGPROF); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1842 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1843 #ifdef SIGSYS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1844 handle_signal (SIGSYS); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1846 #ifdef SIGURG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847 handle_signal (SIGURG); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1848 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849 #ifdef SIGXCPU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1850 handle_signal (SIGXCPU); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1852 #ifdef SIGXFSZ
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853 handle_signal (SIGXFSZ); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1854 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1855 #ifdef SIGVTALRM
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856 handle_signal (SIGVTALRM); /* XPG5 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859 #ifdef SIGIO
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 handle_signal (SIGIO); /* BSD 4.2 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862 #ifdef SIGWINCH
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863 handle_signal (SIGWINCH); /* BSD 4.3 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 #ifdef SIGEMT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 handle_signal (SIGEMT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869 #ifdef SIGINFO
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870 handle_signal (SIGINFO);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872 #ifdef SIGHWE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873 handle_signal (SIGHWE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875 #ifdef SIGPRE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 handle_signal (SIGPRE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878 #ifdef SIGUME
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879 handle_signal (SIGUME);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 #ifdef SIGDLK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882 handle_signal (SIGDLK);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1883 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884 #ifdef SIGCPULIM
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 handle_signal (SIGCPULIM);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887 #ifdef SIGIOT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888 handle_signal (SIGIOT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890 #ifdef SIGLOST
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891 handle_signal (SIGLOST);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893 #ifdef SIGSTKFLT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894 handle_signal (SIGSTKFLT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896 #ifdef SIGUNUSED
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 handle_signal (SIGUNUSED);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899 #ifdef SIGDANGER
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900 handle_signal (SIGDANGER); /* AIX */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1902 #ifdef SIGMSG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1903 handle_signal (SIGMSG);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905 #ifdef SIGSOUND
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1906 handle_signal (SIGSOUND);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1907 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1908 #ifdef SIGRETRACT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909 handle_signal (SIGRETRACT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911 #ifdef SIGGRANT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912 handle_signal (SIGGRANT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1914 #ifdef SIGPWR
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 handle_signal (SIGPWR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1918 #undef handle_signal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
1920 invalid_constant ("Undefined signal name", signal_);
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 800
diff changeset
1921 RETURN_NOT_REACHED (0)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1922 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1923 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1924
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1925 /* Send signal number SIGNO to PROCESS.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1926 CURRENT-GROUP non-nil means send signal to the current
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1927 foreground process group of the process's controlling terminal rather
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1928 than to the process's own process group.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1929 This is used for various commands in shell mode.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1930 If NOMSG is zero, insert signal-announcements into process's buffers
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1931 right away.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1932
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1933 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
1934 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
1935 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
1936 processes running on another computer through a remote login. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1937
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1938 static void
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1939 process_send_signal (Lisp_Object process, int signo,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1940 int current_group, int nomsg)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1941 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1942 /* This function can GC */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1943 process = get_process (process);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1944
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1945 if (network_connection_p (process))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
1946 invalid_operation ("Network connection is not a subprocess", process);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1947 CHECK_LIVE_PROCESS (process);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1948
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1949 MAYBE_PROCMETH (kill_child_process, (process, signo, current_group, nomsg));
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1950 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1951
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1952 DEFUN ("process-send-signal", Fprocess_send_signal, 1, 3, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1953 Send signal SIGNAL to process PROCESS.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1954 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
1955 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
1956 nil, indicating the current buffer's process.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1957 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
1958 foreground process group of the process's controlling terminal rather
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1959 than to the process's own process group.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1960 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
1961 send the signal to the current subjob rather than the shell.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1962 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1963 (signal_, process, current_group))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1964 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1965 /* This function can GC */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1966 process_send_signal (process, decode_signal (signal_),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1967 !NILP (current_group), 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1968 return process;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1969 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1970
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1971 DEFUN ("interrupt-process", Finterrupt_process, 0, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1972 Interrupt process PROCESS.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1973 See function `process-send-signal' for more details on usage.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1974 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1975 (process, current_group))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1976 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1977 /* This function can GC */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1978 process_send_signal (process, SIGINT, !NILP (current_group), 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1979 return process;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1980 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1981
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1982 DEFUN ("kill-process", Fkill_process, 0, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1983 Kill process PROCESS.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1984 See function `process-send-signal' for more details on usage.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1985 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1986 (process, current_group))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1987 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1988 /* This function can GC */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1989 #ifdef SIGKILL
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1990 process_send_signal (process, SIGKILL, !NILP (current_group), 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1991 #else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
1992 signal_error (Qunimplemented,
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
1993 "kill-process: Not supported on this system",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
1994 Qunbound);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1995 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1996 return process;
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1999 DEFUN ("quit-process", Fquit_process, 0, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2000 Send QUIT signal to process PROCESS.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2001 See function `process-send-signal' for more details on usage.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2002 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2003 (process, current_group))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2004 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2005 /* This function can GC */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2006 #ifdef SIGQUIT
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2007 process_send_signal (process, SIGQUIT, !NILP (current_group), 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2008 #else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2009 signal_error (Qunimplemented,
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2010 "quit-process: Not supported on this system",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2011 Qunbound);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2012 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2013 return process;
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
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2016 DEFUN ("stop-process", Fstop_process, 0, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2017 Stop process PROCESS.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2018 See function `process-send-signal' for more details on usage.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2019 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2020 (process, current_group))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2021 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2022 /* This function can GC */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2023 #ifdef SIGTSTP
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2024 process_send_signal (process, SIGTSTP, !NILP (current_group), 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2025 #else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2026 signal_error (Qunimplemented,
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2027 "stop-process: Not supported on this system",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2028 Qunbound);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2029 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2030 return process;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2031 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2032
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2033 DEFUN ("continue-process", Fcontinue_process, 0, 2, 0, /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2034 Continue process PROCESS.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2035 See function `process-send-signal' for more details on usage.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2036 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2037 (process, current_group))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2038 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2039 /* This function can GC */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2040 #ifdef SIGCONT
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2041 process_send_signal (process, SIGCONT, !NILP (current_group), 0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2042 #else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2043 signal_error (Qunimplemented,
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2044 "continue-process: Not supported on this system",
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2045 Qunbound);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2046 #endif
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2047 return process;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2048 }
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 DEFUN ("signal-process", Fsignal_process, 2, 2,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2051 "nProcess number: \nnSignal code: ", /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2052 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
2053 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
2054 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
2055 */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2056 (pid, signal_))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2057 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2058 CHECK_INT (pid);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2059
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2060 return make_int (PROCMETH_OR_GIVEN (kill_process_by_pid,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2061 (XINT (pid), decode_signal (signal_)),
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2062 -1));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2063 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2064
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2065 DEFUN ("process-send-eof", Fprocess_send_eof, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2066 Make PROCESS see end-of-file in its input.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2067 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
2068 nil, indicating the current buffer's process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2069 If PROCESS is a network connection, or is a process communicating
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2070 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
2071 text to PROCESS after you call this function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2072 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2073 (process))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2074 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2075 /* This function can GC */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2076 process = get_process (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2077
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2078 /* Make sure the process is really alive. */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2079 if (! EQ (XPROCESS (process)->status_symbol, Qrun))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2080 invalid_operation ("Process not running", process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2081
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2082 if (!MAYBE_INT_PROCMETH (process_send_eof, (process)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2083 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2084 if (!NILP (DATA_OUTSTREAM (XPROCESS (process))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2085 {
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2086 USID humpty, dumpty;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2087 Lstream_close (XLSTREAM (DATA_OUTSTREAM (XPROCESS (process))));
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2088 event_stream_delete_io_streams (Qnil,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2089 XPROCESS (process)->pipe_outstream,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2090 Qnil, &humpty, &dumpty);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2091 XPROCESS (process)->pipe_outstream = Qnil;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2092 XPROCESS (process)->coding_outstream = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2093 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2094 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2095
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2096 return process;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2097 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2098
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2099
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2100 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2101 /* deleting a process */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2102 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2104 void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2105 deactivate_process (Lisp_Object process)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2106 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2107 Lisp_Process *p = XPROCESS (process);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2108 USID in_usid, err_usid;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2109
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2110 /* It's possible that we got as far in the process-creation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2111 process as creating the descriptors but didn't get so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2112 far as selecting the process for input. In this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2113 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
2114 the process is selected for input. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2115 /* #### 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
2116 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
2117 /* 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
2118 event_stream_unselect_process (p, 1, 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2120 if (!NILP (DATA_OUTSTREAM (p)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2121 Lstream_close (XLSTREAM (DATA_OUTSTREAM (p)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2122 if (!NILP (DATA_INSTREAM (p)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2123 Lstream_close (XLSTREAM (DATA_INSTREAM (p)));
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2124 if (!NILP (DATA_ERRSTREAM (p)))
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2125 Lstream_close (XLSTREAM (DATA_ERRSTREAM (p)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2126
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2127 /* Provide minimal implementation for deactivate_process
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2128 if there's no process-specific one */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2129 if (HAS_PROCMETH_P (deactivate_process))
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2130 PROCMETH (deactivate_process, (p, &in_usid, &err_usid));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2131 else
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2132 event_stream_delete_io_streams (p->pipe_instream,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2133 p->pipe_outstream,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2134 p->pipe_errstream,
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2135 &in_usid, &err_usid);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2136
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2137 if (in_usid != USID_DONTHASH)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2138 remhash ((const void*)in_usid, usid_to_process);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2139 if (err_usid != USID_DONTHASH)
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2140 remhash ((const void*)err_usid, usid_to_process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2142 p->pipe_instream = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2143 p->pipe_outstream = Qnil;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2144 p->pipe_errstream = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2145 p->coding_instream = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2146 p->coding_outstream = Qnil;
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2147 p->coding_errstream = Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2148 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2149
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2150 static void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2151 remove_process (Lisp_Object process)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2152 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2153 Vprocess_list = delq_no_quit (process, Vprocess_list);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2154 Fset_marker (XPROCESS (process)->mark, Qnil, Qnil);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2155
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2156 deactivate_process (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2157 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2158
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2159 DEFUN ("delete-process", Fdelete_process, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2160 Delete PROCESS: kill it and forget about it immediately.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2161 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
2162 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2163 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2164 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2165 /* This function can GC */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
2166 Lisp_Process *p;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2167 process = get_process (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2168 p = XPROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2169 if (network_connection_p (process))
428
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 p->status_symbol = Qexit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2172 p->exit_code = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2173 p->core_dumped = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2174 p->tick++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2175 process_tick++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2176 }
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
2177 else if (PROCESS_LIVE_P (p))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2178 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2179 Fkill_process (process, Qnil);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2180 /* Do this now, since remove_process will make sigchld_handler do nothing. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2181 p->status_symbol = Qsignal;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2182 p->exit_code = SIGKILL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2183 p->core_dumped = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2184 p->tick++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2185 process_tick++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2186 status_notify ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2187 }
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2188 remove_process (process);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2189 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2190 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2192 /* Kill all processes associated with `buffer'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2193 If `buffer' is nil, kill all processes */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2195 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2196 kill_buffer_processes (Lisp_Object buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2197 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2198 LIST_LOOP_2 (process, Vprocess_list)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2199 if ((NILP (buffer) || EQ (XPROCESS (process)->buffer, buffer)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2200 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2201 if (network_connection_p (process))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2202 Fdelete_process (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2203 else if (PROCESS_LIVE_P (XPROCESS (process)))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2204 process_send_signal (process, SIGHUP, 0, 1);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2205 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2206 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2207
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2208 DEFUN ("process-kill-without-query", Fprocess_kill_without_query, 1, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2209 Say no query needed if PROCESS is running when Emacs is exited.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2210 Optional second argument if non-nil says to require a query.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2211 Value is t if a query was formerly required.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2212 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2213 (process, require_query_p))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2214 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2215 int tem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2216
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2217 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2218 tem = XPROCESS (process)->kill_without_query;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2219 XPROCESS (process)->kill_without_query = NILP (require_query_p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2221 return tem ? Qnil : Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2222 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2224 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
2225 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
2226 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2227 (process))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2228 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2229 CHECK_PROCESS (process);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2230 return XPROCESS (process)->kill_without_query ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2231 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2232
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 #if 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2235
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 816
diff changeset
2236 DEFUN ("process-connection", Fprocess_connection, 0, 1, 0, /*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2237 Return the connection type of `PROCESS'. This can be nil (pipe),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2238 t or pty (pty) or stream (socket connection).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2239 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2240 (process))
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 return XPROCESS (process)->type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2243 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2244
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2245 #endif /* 0 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2246
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2247
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2248 static int
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2249 getenv_internal (const Intbyte *var,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2250 Bytecount varlen,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2251 Intbyte **value,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2252 Bytecount *valuelen)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2253 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2254 Lisp_Object scan;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2255
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2256 assert (env_initted);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2257
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2258 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
2259 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2260 Lisp_Object entry = XCAR (scan);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2261
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2262 if (STRINGP (entry)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2263 && XSTRING_LENGTH (entry) > varlen
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 816
diff changeset
2264 && string_byte (entry, varlen) == '='
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2265 #ifdef WIN32_NATIVE
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2266 /* NT environment variables are case insensitive. */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2267 && ! memicmp (XSTRING_DATA (entry), var, varlen)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2268 #else /* not WIN32_NATIVE */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2269 && ! memcmp (XSTRING_DATA (entry), var, varlen)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2270 #endif /* not WIN32_NATIVE */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2271 )
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2272 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2273 *value = XSTRING_DATA (entry) + (varlen + 1);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2274 *valuelen = XSTRING_LENGTH (entry) - (varlen + 1);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2275 return 1;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2276 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2277 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2278
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2279 return 0;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2280 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2281
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2282 static void
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2283 putenv_internal (const Intbyte *var,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2284 Bytecount varlen,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2285 const Intbyte *value,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2286 Bytecount valuelen)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2287 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2288 Lisp_Object scan;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2289
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2290 assert (env_initted);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2291
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2292 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
2293 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2294 Lisp_Object entry = XCAR (scan);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2295
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2296 if (STRINGP (entry)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2297 && XSTRING_LENGTH (entry) > varlen
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 816
diff changeset
2298 && string_byte (entry, varlen) == '='
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2299 #ifdef WIN32_NATIVE
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2300 /* NT environment variables are case insensitive. */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2301 && ! memicmp (XSTRING_DATA (entry), var, varlen)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2302 #else /* not WIN32_NATIVE */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2303 && ! memcmp (XSTRING_DATA (entry), var, varlen)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2304 #endif /* not WIN32_NATIVE */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2305 )
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2306 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2307 XCAR (scan) = concat3 (make_string (var, varlen),
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2308 build_string ("="),
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2309 make_string (value, valuelen));
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2310 return;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2311 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2312 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2313
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2314 Vprocess_environment = Fcons (concat3 (make_string (var, varlen),
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2315 build_string ("="),
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2316 make_string (value, valuelen)),
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2317 Vprocess_environment);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2318 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2319
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2320 /* NOTE:
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2321
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2322 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
2323 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
2324 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
2325 to rearrange the early dumped code to accommodate this.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2326
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2327 (defun getenv (variable)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2328 "Get the value of environment variable VARIABLE.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2329 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
2330 the environment. Otherwise, value is a string.
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 This function consults the variable `process-environment'
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2333 for its value."
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2334 (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
2335 (let ((value (getenv-internal variable)))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2336 (when (interactive-p)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2337 (message "%s" (if value value "Not set")))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2338 value))
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
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2341 DEFUN ("getenv", Fgetenv, 1, 2, "sEnvironment variable: \np", /*
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2342 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
2343 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
2344 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
2345 */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2346 (var, interactivep))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2347 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2348 Intbyte *value;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2349 Bytecount valuelen;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2350 Lisp_Object v = Qnil;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2351 struct gcpro gcpro1;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2352
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2353 CHECK_STRING (var);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2354 GCPRO1 (v);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2355 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
2356 &value, &valuelen))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2357 v = make_string (value, valuelen);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2358 if (!NILP (interactivep))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2359 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2360 if (NILP (v))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2361 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
2362 else
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2363 /* #### Should use Fprin1_to_string or Fprin1 to handle string
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2364 containing quotes correctly. */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2365 message ("\"%s\"", value);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2366 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2367 RETURN_UNGCPRO (v);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2368 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2369
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2370 /* 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
2371 callable from C.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2372
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2373 (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
2374 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
2375 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
2376 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
2377 `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
2378 and putenv() consult and modify `environ'. However, once
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2379 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
2380 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
2381 the environment only modifies Vprocess_environment, not `environ';
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2382 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
2383 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
2384 encapsulated.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2385
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2386 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
2387 invalid after a GC. */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2388
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2389 Intbyte *
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2390 egetenv (const CIntbyte *var)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2391 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2392 /* This cannot GC -- 7-28-00 ben */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2393 Intbyte *value;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2394 Bytecount valuelen;
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 if (getenv_internal ((const Intbyte *) var, strlen (var), &value, &valuelen))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2397 return value;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2398 else
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2399 return 0;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2400 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2401
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2402 void
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2403 eputenv (const CIntbyte *var, const CIntbyte *value)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2404 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2405 putenv_internal ((Intbyte *) var, strlen (var), (Intbyte *) value,
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2406 strlen (value));
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2407 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2408
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2409
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2410 /* 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
2411 void
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2412 init_xemacs_process (void)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2413 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2414 /* This function can GC */
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 MAYBE_PROCMETH (init_process, ());
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2417
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2418 Vprocess_list = Qnil;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2419
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2420 if (usid_to_process)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2421 clrhash (usid_to_process);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2422 else
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2423 usid_to_process = make_hash_table (32);
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 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2426 /* jwz: always initialize Vprocess_environment, so that egetenv()
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2427 works in temacs. */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2428 char **envp;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2429 Vprocess_environment = Qnil;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2430 for (envp = environ; envp && *envp; envp++)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2431 Vprocess_environment =
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2432 Fcons (build_ext_string (*envp, Qnative), Vprocess_environment);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2433 /* 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
2434 env_initted = 1;
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2435 }
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 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2438 /* 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
2439 #ifdef WIN32_NATIVE
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2440 const Intbyte *shell = egetenv ("SHELL");
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2441 if (!shell) shell = egetenv ("COMSPEC");
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2442 /* Should never happen! */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2443 if (!shell) shell =
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2444 (Intbyte *) (GetVersion () & 0x80000000 ? "command" : "cmd");
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2445 #else /* not WIN32_NATIVE */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2446 const Intbyte *shell = egetenv ("SHELL");
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2447 if (!shell) shell = (Intbyte *) "/bin/sh";
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2448 #endif
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2449
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2450 #if 0 /* defined (WIN32_NATIVE) */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2451 /* 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
2452 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
2453 screwed up.
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 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
2456 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
2457 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
2458 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
2459 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
2460 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
2461 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
2462 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
2463 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
2464 */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2465
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2466 if (!egetenv ("SHELL"))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2467 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2468 Intbyte *faux_var = alloca_array (Intbyte, 7 + qxestrlen (shell));
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2469 qxesprintf (faux_var, "SHELL=%s", shell);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2470 Vprocess_environment = Fcons (build_intstring (faux_var),
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2471 Vprocess_environment);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2472 }
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2473 #endif /* 0 */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2474
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2475 Vshell_file_name = build_intstring (shell);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2476 }
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
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2479 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2480 syms_of_process (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2481 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2482 INIT_LRECORD_IMPLEMENTATION (process);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2483
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2484 DEFSYMBOL (Qprocessp);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2485 DEFSYMBOL (Qprocess_live_p);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2486 DEFSYMBOL (Qrun);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2487 DEFSYMBOL (Qstop);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2488 DEFSYMBOL (Qopen);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2489 DEFSYMBOL (Qclosed);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2490
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2491 DEFSYMBOL (Qtcp);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2492 DEFSYMBOL (Qudp);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2494 #ifdef HAVE_MULTICAST
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2495 DEFSYMBOL (Qmulticast); /* Used for occasional warnings */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2496 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2497
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2498 DEFERROR_STANDARD (Qprocess_error, Qio_error);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2499 DEFERROR_STANDARD (Qnetwork_error, Qio_error);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 502
diff changeset
2500
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2501 DEFSUBR (Fprocessp);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
2502 DEFSUBR (Fprocess_live_p);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2503 DEFSUBR (Fget_process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2504 DEFSUBR (Fget_buffer_process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2505 DEFSUBR (Fdelete_process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2506 DEFSUBR (Fprocess_status);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2507 DEFSUBR (Fprocess_exit_status);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2508 DEFSUBR (Fprocess_id);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2509 DEFSUBR (Fprocess_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2510 DEFSUBR (Fprocess_tty_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2511 DEFSUBR (Fprocess_command);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2512 DEFSUBR (Fset_process_buffer);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2513 DEFSUBR (Fset_process_stderr_buffer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2514 DEFSUBR (Fprocess_buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2515 DEFSUBR (Fprocess_mark);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2516 DEFSUBR (Fprocess_stderr_buffer);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2517 DEFSUBR (Fprocess_stderr_mark);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2518 DEFSUBR (Fset_process_filter);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2519 DEFSUBR (Fprocess_filter);
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2520 DEFSUBR (Fset_process_stderr_filter);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2521 DEFSUBR (Fprocess_stderr_filter);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2522 DEFSUBR (Fset_process_window_size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2523 DEFSUBR (Fset_process_sentinel);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2524 DEFSUBR (Fprocess_sentinel);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2525 DEFSUBR (Fprocess_kill_without_query);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2526 DEFSUBR (Fprocess_kill_without_query_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2527 DEFSUBR (Fprocess_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2528 DEFSUBR (Fstart_process_internal);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2529 #ifdef HAVE_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2530 DEFSUBR (Fopen_network_stream_internal);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2531 #ifdef HAVE_MULTICAST
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2532 DEFSUBR (Fopen_multicast_group_internal);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2533 #endif /* HAVE_MULTICAST */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2534 #endif /* HAVE_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2535 DEFSUBR (Fprocess_send_region);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2536 DEFSUBR (Fprocess_send_string);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2537 DEFSUBR (Fprocess_send_signal);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2538 DEFSUBR (Finterrupt_process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2539 DEFSUBR (Fkill_process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2540 DEFSUBR (Fquit_process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2541 DEFSUBR (Fstop_process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2542 DEFSUBR (Fcontinue_process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2543 DEFSUBR (Fprocess_send_eof);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2544 DEFSUBR (Fsignal_process);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2545 /* DEFSUBR (Fprocess_connection); */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2546 DEFSUBR (Fprocess_input_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2547 DEFSUBR (Fprocess_output_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2548 DEFSUBR (Fset_process_input_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2549 DEFSUBR (Fset_process_output_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2550 DEFSUBR (Fprocess_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2551 DEFSUBR (Fset_process_coding_system);
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2552 DEFSUBR (Fgetenv);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2553 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2554
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2555 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2556 vars_of_process (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2557 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2558 Fprovide (intern ("subprocesses"));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2559 #ifdef HAVE_SOCKETS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2560 Fprovide (intern ("network-streams"));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2561 #ifdef HAVE_MULTICAST
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2562 Fprovide (intern ("multicast"));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2563 #endif /* HAVE_MULTICAST */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2564 #endif /* HAVE_SOCKETS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2565 staticpro (&Vprocess_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2566
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2567 DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2568 *Non-nil means delete processes immediately when they exit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2569 nil means don't delete them until `list-processes' is run.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2570 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2571
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2572 delete_exited_processes = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2573
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2574 DEFVAR_CONST_LISP ("null-device", &Vnull_device /*
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2575 Name of the null device, which differs from system to system.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2576 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
2577 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
2578 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
2579 different names (typically either `/dev/null' or `nul').
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2580
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2581 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
2582 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
2583 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
2584 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
2585 the operations needing this are lower level than what ELisp programs
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2586 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
2587 */ );
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2588 Vnull_device = build_string (NULL_DEVICE);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2589
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2590 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2591 Control type of device used to communicate with subprocesses.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2592 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
2593 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
2594 then a pipe is used in any case.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2595 The value takes effect when `start-process' is called.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2596 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2597 Vprocess_connection_type = Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2598
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2599 DEFVAR_BOOL ("windowed-process-io", &windowed_process_io /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2600 Enables input/output on standard handles of a windowed process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2601 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
2602 standard output handle of a windowed process. Instead, the process is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2603 immediately marked as exited immediately upon successful launching. This is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2604 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
2605 not connected to any console.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2606
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2607 When launching a specially crafted windowed process, which expects to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2608 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
2609 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
2610 treat this process just like a console process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2611
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2612 NOTE: You should never set this variable, only bind it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2613
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2614 Only Windows processes can be "windowed" or "console". This variable has no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2615 effect on UNIX processes, because all UNIX processes are "console".
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2616 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2617 windowed_process_io = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2618
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2619 DEFVAR_INT ("debug-process-io", &debug_process_io /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2620 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
2621 */ );
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2622 debug_process_io = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2623
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2624 DEFVAR_LISP ("default-process-coding-system",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2625 &Vdefault_process_coding_system /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2626 Cons of coding systems used for process I/O by default.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2627 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
2628 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
2629 */ );
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2630 /* This below will get its default set correctly in code-init.el. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2631 Vdefault_process_coding_system = Fcons (Qundecided, Qnil);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2632
853
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2633 DEFVAR_LISP ("default-network-coding-system",
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2634 &Vdefault_network_coding_system /*
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2635 Cons of coding systems used for network I/O by default.
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2636 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
2637 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
2638 */ );
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2639 Vdefault_network_coding_system = Fcons (Qundecided, Qnil);
2b6fa2618f76 [xemacs-hg @ 2002-05-28 08:44:22 by ben]
ben
parents: 844
diff changeset
2640
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2641 #ifdef PROCESS_IO_BLOCKING
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2642 DEFVAR_LISP ("network-stream-blocking-port-list", &network_stream_blocking_port_list /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2643 List of port numbers or port names to set a blocking I/O mode with connection.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2644 Nil value means to set a default(non-blocking) I/O mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2645 The value takes effect when `open-network-stream-internal' is called.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2646 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2647 network_stream_blocking_port_list = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2648 #endif /* PROCESS_IO_BLOCKING */
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2649
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2650 /* This function can GC */
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2651 DEFVAR_LISP ("shell-file-name", &Vshell_file_name /*
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2652 *File name to load inferior shells from.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2653 Initialized from the SHELL environment variable.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2654 */ );
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2655
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2656 DEFVAR_LISP ("process-environment", &Vprocess_environment /*
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2657 List of environment variables for subprocesses to inherit.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2658 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
2659 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
2660 when Emacs starts.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2661 */ );
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2662
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2663 Vlisp_EXEC_SUFFIXES = build_string (EXEC_SUFFIXES);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2664 staticpro (&Vlisp_EXEC_SUFFIXES);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 801
diff changeset
2665 }