aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorStefan Monnier2010-07-23 17:23:09 +0200
committerStefan Monnier2010-07-23 17:23:09 +0200
commit0ee81a0ce066375eac701c06cdfbdebefe594fdc (patch)
treef0dccd24163316cfe688f927681a3032a9b1fe2f /src/process.c
parent894e369ddf48e191638b8e66ce732f24ff9abe2a (diff)
parent94da839793affa2a270bc26cee9c4d95d4dc4708 (diff)
downloademacs-0ee81a0ce066375eac701c06cdfbdebefe594fdc.tar.gz
emacs-0ee81a0ce066375eac701c06cdfbdebefe594fdc.zip
Merge from trunk
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c1541
1 files changed, 635 insertions, 906 deletions
diff --git a/src/process.c b/src/process.c
index 22b85ff5910..219098905cf 100644
--- a/src/process.c
+++ b/src/process.c
@@ -21,17 +21,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 21
22#include <config.h> 22#include <config.h>
23#include <signal.h> 23#include <signal.h>
24
25/* This file is split into two parts by the following preprocessor
26 conditional. The 'then' clause contains all of the support for
27 asynchronous subprocesses. The 'else' clause contains stub
28 versions of some of the asynchronous subprocess routines that are
29 often called elsewhere in Emacs, so we don't have to #ifdef the
30 sections that call them. */
31
32
33#ifdef subprocesses
34
35#include <stdio.h> 24#include <stdio.h>
36#include <errno.h> 25#include <errno.h>
37#include <setjmp.h> 26#include <setjmp.h>
@@ -51,6 +40,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
51#endif 40#endif
52#include <fcntl.h> 41#include <fcntl.h>
53 42
43/* Only MS-DOS does not define `subprocesses'. */
44#ifdef subprocesses
45
54#ifdef HAVE_SOCKETS /* TCP connection support, if kernel can do it */ 46#ifdef HAVE_SOCKETS /* TCP connection support, if kernel can do it */
55#include <sys/socket.h> 47#include <sys/socket.h>
56#include <netdb.h> 48#include <netdb.h>
@@ -101,6 +93,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
101#include <resolv.h> 93#include <resolv.h>
102#endif 94#endif
103 95
96#endif /* subprocesses */
97
104#include "lisp.h" 98#include "lisp.h"
105#include "systime.h" 99#include "systime.h"
106#include "systty.h" 100#include "systty.h"
@@ -119,11 +113,16 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
119#include "dispextern.h" 113#include "dispextern.h"
120#include "composite.h" 114#include "composite.h"
121#include "atimer.h" 115#include "atimer.h"
116#include "sysselect.h"
117#include "syssignal.h"
118#include "syswait.h"
122 119
123#if defined (USE_GTK) || defined (HAVE_GCONF) 120#if defined (USE_GTK) || defined (HAVE_GCONF)
124#include "xgselect.h" 121#include "xgselect.h"
125#endif /* defined (USE_GTK) || defined (HAVE_GCONF) */ 122#endif /* defined (USE_GTK) || defined (HAVE_GCONF) */
126 123
124#ifdef subprocesses
125
127Lisp_Object Qprocessp; 126Lisp_Object Qprocessp;
128Lisp_Object Qrun, Qstop, Qsignal; 127Lisp_Object Qrun, Qstop, Qsignal;
129Lisp_Object Qopen, Qclosed, Qconnect, Qfailed, Qlisten; 128Lisp_Object Qopen, Qclosed, Qconnect, Qfailed, Qlisten;
@@ -135,7 +134,7 @@ Lisp_Object Qipv6;
135Lisp_Object QCport, QCspeed, QCprocess; 134Lisp_Object QCport, QCspeed, QCprocess;
136Lisp_Object QCbytesize, QCstopbits, QCparity, Qodd, Qeven; 135Lisp_Object QCbytesize, QCstopbits, QCparity, Qodd, Qeven;
137Lisp_Object QCflowcontrol, Qhw, Qsw, QCsummary; 136Lisp_Object QCflowcontrol, Qhw, Qsw, QCsummary;
138Lisp_Object QCname, QCbuffer, QChost, QCservice, QCtype; 137Lisp_Object QCbuffer, QChost, QCservice;
139Lisp_Object QClocal, QCremote, QCcoding; 138Lisp_Object QClocal, QCremote, QCcoding;
140Lisp_Object QCserver, QCnowait, QCnoquery, QCstop; 139Lisp_Object QCserver, QCnowait, QCnoquery, QCstop;
141Lisp_Object QCsentinel, QClog, QCoptions, QCplist; 140Lisp_Object QCsentinel, QClog, QCoptions, QCplist;
@@ -151,11 +150,6 @@ extern Lisp_Object QCfamily;
151/* QCfilter is defined in keyboard.c. */ 150/* QCfilter is defined in keyboard.c. */
152extern Lisp_Object QCfilter; 151extern Lisp_Object QCfilter;
153 152
154Lisp_Object Qeuid, Qegid, Qcomm, Qstate, Qppid, Qpgrp, Qsess, Qttname, Qtpgid;
155Lisp_Object Qminflt, Qmajflt, Qcminflt, Qcmajflt, Qutime, Qstime, Qcstime;
156Lisp_Object Qcutime, Qpri, Qnice, Qthcount, Qstart, Qvsize, Qrss, Qargs;
157Lisp_Object Quser, Qgroup, Qetime, Qpcpu, Qpmem, Qtime, Qctime;
158
159#ifdef HAVE_SOCKETS 153#ifdef HAVE_SOCKETS
160#define NETCONN_P(p) (EQ (XPROCESS (p)->type, Qnetwork)) 154#define NETCONN_P(p) (EQ (XPROCESS (p)->type, Qnetwork))
161#define NETCONN1_P(p) (EQ ((p)->type, Qnetwork)) 155#define NETCONN1_P(p) (EQ ((p)->type, Qnetwork))
@@ -178,11 +172,7 @@ Lisp_Object Quser, Qgroup, Qetime, Qpcpu, Qpmem, Qtime, Qctime;
178#define SIGCHLD SIGCLD 172#define SIGCHLD SIGCLD
179#endif /* SIGCLD */ 173#endif /* SIGCLD */
180 174
181#include "syssignal.h" 175extern char *get_operating_system_release (void);
182
183#include "syswait.h"
184
185extern char *get_operating_system_release ();
186 176
187/* Serial processes require termios or Windows. */ 177/* Serial processes require termios or Windows. */
188#if defined (HAVE_TERMIOS) || defined (WINDOWSNT) 178#if defined (HAVE_TERMIOS) || defined (WINDOWSNT)
@@ -282,14 +272,11 @@ static Lisp_Object Vprocess_adaptive_read_buffering;
282#define process_output_delay_count 0 272#define process_output_delay_count 0
283#endif 273#endif
284 274
285 275static int keyboard_bit_set (SELECT_TYPE *);
286#include "sysselect.h" 276static void deactivate_process (Lisp_Object);
287 277static void status_notify (struct Lisp_Process *);
288static int keyboard_bit_set P_ ((SELECT_TYPE *)); 278static int read_process_output (Lisp_Object, int);
289static void deactivate_process P_ ((Lisp_Object)); 279static void create_pty (Lisp_Object);
290static void status_notify P_ ((struct Lisp_Process *));
291static int read_process_output P_ ((Lisp_Object, int));
292static void create_pty P_ ((Lisp_Object));
293 280
294/* If we support a window system, turn on the code to poll periodically 281/* If we support a window system, turn on the code to poll periodically
295 to detect C-g. It isn't actually used when doing interrupt input. */ 282 to detect C-g. It isn't actually used when doing interrupt input. */
@@ -297,11 +284,32 @@ static void create_pty P_ ((Lisp_Object));
297#define POLL_FOR_INPUT 284#define POLL_FOR_INPUT
298#endif 285#endif
299 286
300static Lisp_Object get_process (); 287static Lisp_Object get_process (register Lisp_Object name);
301static void exec_sentinel (); 288static void exec_sentinel (Lisp_Object proc, Lisp_Object reason);
289
290#endif /* subprocesses */
302 291
303extern int timers_run; 292extern int timers_run;
293
294Lisp_Object Qeuid, Qegid, Qcomm, Qstate, Qppid, Qpgrp, Qsess, Qttname, Qtpgid;
295Lisp_Object Qminflt, Qmajflt, Qcminflt, Qcmajflt, Qutime, Qstime, Qcstime;
296Lisp_Object Qcutime, Qpri, Qnice, Qthcount, Qstart, Qvsize, Qrss, Qargs;
297Lisp_Object Quser, Qgroup, Qetime, Qpcpu, Qpmem, Qtime, Qctime;
298Lisp_Object QCname, QCtype;
304 299
300/* Non-zero if keyboard input is on hold, zero otherwise. */
301
302static int kbd_is_on_hold;
303
304/* Nonzero means delete a process right away if it exits. */
305static int delete_exited_processes;
306
307/* Nonzero means don't run process sentinels. This is used
308 when exiting. */
309int inhibit_sentinels;
310
311#ifdef subprocesses
312
305/* Mask of bits indicating the descriptors that we wait for input on. */ 313/* Mask of bits indicating the descriptors that we wait for input on. */
306 314
307static SELECT_TYPE input_wait_mask; 315static SELECT_TYPE input_wait_mask;
@@ -329,9 +337,9 @@ static SELECT_TYPE connect_wait_mask;
329static int num_pending_connects; 337static int num_pending_connects;
330 338
331#define IF_NON_BLOCKING_CONNECT(s) s 339#define IF_NON_BLOCKING_CONNECT(s) s
332#else 340#else /* NON_BLOCKING_CONNECT */
333#define IF_NON_BLOCKING_CONNECT(s) 341#define IF_NON_BLOCKING_CONNECT(s)
334#endif 342#endif /* NON_BLOCKING_CONNECT */
335 343
336/* The largest descriptor currently in use for a process object. */ 344/* The largest descriptor currently in use for a process object. */
337static int max_process_desc; 345static int max_process_desc;
@@ -342,9 +350,6 @@ static int max_keyboard_desc;
342/* The largest descriptor currently in use for gpm mouse input. */ 350/* The largest descriptor currently in use for gpm mouse input. */
343static int max_gpm_desc; 351static int max_gpm_desc;
344 352
345/* Nonzero means delete a process right away if it exits. */
346static int delete_exited_processes;
347
348/* Indexed by descriptor, gives the process (if any) for that descriptor */ 353/* Indexed by descriptor, gives the process (if any) for that descriptor */
349Lisp_Object chan_process[MAXDESC]; 354Lisp_Object chan_process[MAXDESC];
350 355
@@ -380,10 +385,6 @@ struct sockaddr_and_len {
380/* Maximum number of bytes to send to a pty without an eof. */ 385/* Maximum number of bytes to send to a pty without an eof. */
381static int pty_max_bytes; 386static int pty_max_bytes;
382 387
383/* Nonzero means don't run process sentinels. This is used
384 when exiting. */
385int inhibit_sentinels;
386
387#ifdef HAVE_PTYS 388#ifdef HAVE_PTYS
388#ifdef HAVE_PTY_H 389#ifdef HAVE_PTY_H
389#include <pty.h> 390#include <pty.h>
@@ -399,8 +400,7 @@ static char pty_name[24];
399static Lisp_Object status_convert (int); 400static Lisp_Object status_convert (int);
400 401
401static void 402static void
402update_status (p) 403update_status (struct Lisp_Process *p)
403 struct Lisp_Process *p;
404{ 404{
405 eassert (p->raw_status_new); 405 eassert (p->raw_status_new);
406 p->status = status_convert (p->raw_status); 406 p->status = status_convert (p->raw_status);
@@ -429,11 +429,7 @@ status_convert (int w)
429 and store them individually through the three pointers. */ 429 and store them individually through the three pointers. */
430 430
431static void 431static void
432decode_status (l, symbol, code, coredump) 432decode_status (Lisp_Object l, Lisp_Object *symbol, int *code, int *coredump)
433 Lisp_Object l;
434 Lisp_Object *symbol;
435 int *code;
436 int *coredump;
437{ 433{
438 Lisp_Object tem; 434 Lisp_Object tem;
439 435
@@ -456,8 +452,7 @@ decode_status (l, symbol, code, coredump)
456/* Return a string describing a process status list. */ 452/* Return a string describing a process status list. */
457 453
458static Lisp_Object 454static Lisp_Object
459status_message (p) 455status_message (struct Lisp_Process *p)
460 struct Lisp_Process *p;
461{ 456{
462 Lisp_Object status = p->status; 457 Lisp_Object status = p->status;
463 Lisp_Object symbol; 458 Lisp_Object symbol;
@@ -519,7 +514,7 @@ status_message (p)
519 is left in the variable pty_name. */ 514 is left in the variable pty_name. */
520 515
521static int 516static int
522allocate_pty () 517allocate_pty (void)
523{ 518{
524 register int c, i; 519 register int c, i;
525 int fd; 520 int fd;
@@ -593,8 +588,7 @@ allocate_pty ()
593#endif /* HAVE_PTYS */ 588#endif /* HAVE_PTYS */
594 589
595static Lisp_Object 590static Lisp_Object
596make_process (name) 591make_process (Lisp_Object name)
597 Lisp_Object name;
598{ 592{
599 register Lisp_Object val, tem, name1; 593 register Lisp_Object val, tem, name1;
600 register struct Lisp_Process *p; 594 register struct Lisp_Process *p;
@@ -638,8 +632,7 @@ make_process (name)
638} 632}
639 633
640static void 634static void
641remove_process (proc) 635remove_process (register Lisp_Object proc)
642 register Lisp_Object proc;
643{ 636{
644 register Lisp_Object pair; 637 register Lisp_Object pair;
645 638
@@ -649,52 +642,17 @@ remove_process (proc)
649 deactivate_process (proc); 642 deactivate_process (proc);
650} 643}
651 644
652/* Setup coding systems of PROCESS. */
653
654void
655setup_process_coding_systems (process)
656 Lisp_Object process;
657{
658 struct Lisp_Process *p = XPROCESS (process);
659 int inch = p->infd;
660 int outch = p->outfd;
661 Lisp_Object coding_system;
662
663 if (inch < 0 || outch < 0)
664 return;
665
666 if (!proc_decode_coding_system[inch])
667 proc_decode_coding_system[inch]
668 = (struct coding_system *) xmalloc (sizeof (struct coding_system));
669 coding_system = p->decode_coding_system;
670 if (! NILP (p->filter))
671 ;
672 else if (BUFFERP (p->buffer))
673 {
674 if (NILP (XBUFFER (p->buffer)->enable_multibyte_characters))
675 coding_system = raw_text_coding_system (coding_system);
676 }
677 setup_coding_system (coding_system, proc_decode_coding_system[inch]);
678
679 if (!proc_encode_coding_system[outch])
680 proc_encode_coding_system[outch]
681 = (struct coding_system *) xmalloc (sizeof (struct coding_system));
682 setup_coding_system (p->encode_coding_system,
683 proc_encode_coding_system[outch]);
684}
685 645
686DEFUN ("processp", Fprocessp, Sprocessp, 1, 1, 0, 646DEFUN ("processp", Fprocessp, Sprocessp, 1, 1, 0,
687 doc: /* Return t if OBJECT is a process. */) 647 doc: /* Return t if OBJECT is a process. */)
688 (object) 648 (Lisp_Object object)
689 Lisp_Object object;
690{ 649{
691 return PROCESSP (object) ? Qt : Qnil; 650 return PROCESSP (object) ? Qt : Qnil;
692} 651}
693 652
694DEFUN ("get-process", Fget_process, Sget_process, 1, 1, 0, 653DEFUN ("get-process", Fget_process, Sget_process, 1, 1, 0,
695 doc: /* Return the process named NAME, or nil if there is none. */) 654 doc: /* Return the process named NAME, or nil if there is none. */)
696 (name) 655 (register Lisp_Object name)
697 register Lisp_Object name;
698{ 656{
699 if (PROCESSP (name)) 657 if (PROCESSP (name))
700 return name; 658 return name;
@@ -702,35 +660,13 @@ DEFUN ("get-process", Fget_process, Sget_process, 1, 1, 0,
702 return Fcdr (Fassoc (name, Vprocess_alist)); 660 return Fcdr (Fassoc (name, Vprocess_alist));
703} 661}
704 662
705DEFUN ("get-buffer-process", Fget_buffer_process, Sget_buffer_process, 1, 1, 0,
706 doc: /* Return the (or a) process associated with BUFFER.
707BUFFER may be a buffer or the name of one. */)
708 (buffer)
709 register Lisp_Object buffer;
710{
711 register Lisp_Object buf, tail, proc;
712
713 if (NILP (buffer)) return Qnil;
714 buf = Fget_buffer (buffer);
715 if (NILP (buf)) return Qnil;
716
717 for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail))
718 {
719 proc = Fcdr (XCAR (tail));
720 if (PROCESSP (proc) && EQ (XPROCESS (proc)->buffer, buf))
721 return proc;
722 }
723 return Qnil;
724}
725
726/* This is how commands for the user decode process arguments. It 663/* This is how commands for the user decode process arguments. It
727 accepts a process, a process name, a buffer, a buffer name, or nil. 664 accepts a process, a process name, a buffer, a buffer name, or nil.
728 Buffers denote the first process in the buffer, and nil denotes the 665 Buffers denote the first process in the buffer, and nil denotes the
729 current buffer. */ 666 current buffer. */
730 667
731static Lisp_Object 668static Lisp_Object
732get_process (name) 669get_process (register Lisp_Object name)
733 register Lisp_Object name;
734{ 670{
735 register Lisp_Object proc, obj; 671 register Lisp_Object proc, obj;
736 if (STRINGP (name)) 672 if (STRINGP (name))
@@ -776,8 +712,7 @@ DEFUN ("delete-process", Fdelete_process, Sdelete_process, 1, 1, 0,
776 doc: /* Delete PROCESS: kill it and forget about it immediately. 712 doc: /* Delete PROCESS: kill it and forget about it immediately.
777PROCESS may be a process, a buffer, the name of a process or buffer, or 713PROCESS may be a process, a buffer, the name of a process or buffer, or
778nil, indicating the current buffer's process. */) 714nil, indicating the current buffer's process. */)
779 (process) 715 (register Lisp_Object process)
780 register Lisp_Object process;
781{ 716{
782 register struct Lisp_Process *p; 717 register struct Lisp_Process *p;
783 718
@@ -844,8 +779,7 @@ failed -- when a non-blocking connection has failed.
844nil -- if arg is a process name and no such process exists. 779nil -- if arg is a process name and no such process exists.
845PROCESS may be a process, a buffer, the name of a process, or 780PROCESS may be a process, a buffer, the name of a process, or
846nil, indicating the current buffer's process. */) 781nil, indicating the current buffer's process. */)
847 (process) 782 (register Lisp_Object process)
848 register Lisp_Object process;
849{ 783{
850 register struct Lisp_Process *p; 784 register struct Lisp_Process *p;
851 register Lisp_Object status; 785 register Lisp_Object status;
@@ -880,8 +814,7 @@ DEFUN ("process-exit-status", Fprocess_exit_status, Sprocess_exit_status,
880 1, 1, 0, 814 1, 1, 0,
881 doc: /* Return the exit status of PROCESS or the signal number that killed it. 815 doc: /* Return the exit status of PROCESS or the signal number that killed it.
882If PROCESS has not yet exited or died, return 0. */) 816If PROCESS has not yet exited or died, return 0. */)
883 (process) 817 (register Lisp_Object process)
884 register Lisp_Object process;
885{ 818{
886 CHECK_PROCESS (process); 819 CHECK_PROCESS (process);
887 if (XPROCESS (process)->raw_status_new) 820 if (XPROCESS (process)->raw_status_new)
@@ -895,8 +828,7 @@ DEFUN ("process-id", Fprocess_id, Sprocess_id, 1, 1, 0,
895 doc: /* Return the process id of PROCESS. 828 doc: /* Return the process id of PROCESS.
896This is the pid of the external process which PROCESS uses or talks to. 829This is the pid of the external process which PROCESS uses or talks to.
897For a network connection, this value is nil. */) 830For a network connection, this value is nil. */)
898 (process) 831 (register Lisp_Object process)
899 register Lisp_Object process;
900{ 832{
901 /* Assignment to EMACS_INT stops GCC whining about limited range of 833 /* Assignment to EMACS_INT stops GCC whining about limited range of
902 data type. */ 834 data type. */
@@ -911,8 +843,7 @@ DEFUN ("process-name", Fprocess_name, Sprocess_name, 1, 1, 0,
911 doc: /* Return the name of PROCESS, as a string. 843 doc: /* Return the name of PROCESS, as a string.
912This is the name of the program invoked in PROCESS, 844This is the name of the program invoked in PROCESS,
913possibly modified to make it unique among process names. */) 845possibly modified to make it unique among process names. */)
914 (process) 846 (register Lisp_Object process)
915 register Lisp_Object process;
916{ 847{
917 CHECK_PROCESS (process); 848 CHECK_PROCESS (process);
918 return XPROCESS (process)->name; 849 return XPROCESS (process)->name;
@@ -924,8 +855,7 @@ This is a list of strings, the first string being the program executed
924and the rest of the strings being the arguments given to it. 855and the rest of the strings being the arguments given to it.
925For a network or serial process, this is nil (process is running) or t 856For a network or serial process, this is nil (process is running) or t
926\(process is stopped). */) 857\(process is stopped). */)
927 (process) 858 (register Lisp_Object process)
928 register Lisp_Object process;
929{ 859{
930 CHECK_PROCESS (process); 860 CHECK_PROCESS (process);
931 return XPROCESS (process)->command; 861 return XPROCESS (process)->command;
@@ -935,8 +865,7 @@ DEFUN ("process-tty-name", Fprocess_tty_name, Sprocess_tty_name, 1, 1, 0,
935 doc: /* Return the name of the terminal PROCESS uses, or nil if none. 865 doc: /* Return the name of the terminal PROCESS uses, or nil if none.
936This is the terminal that the process itself reads and writes on, 866This is the terminal that the process itself reads and writes on,
937not the name of the pty that Emacs uses to talk with that terminal. */) 867not the name of the pty that Emacs uses to talk with that terminal. */)
938 (process) 868 (register Lisp_Object process)
939 register Lisp_Object process;
940{ 869{
941 CHECK_PROCESS (process); 870 CHECK_PROCESS (process);
942 return XPROCESS (process)->tty_name; 871 return XPROCESS (process)->tty_name;
@@ -945,8 +874,7 @@ not the name of the pty that Emacs uses to talk with that terminal. */)
945DEFUN ("set-process-buffer", Fset_process_buffer, Sset_process_buffer, 874DEFUN ("set-process-buffer", Fset_process_buffer, Sset_process_buffer,
946 2, 2, 0, 875 2, 2, 0,
947 doc: /* Set buffer associated with PROCESS to BUFFER (a buffer, or nil). */) 876 doc: /* Set buffer associated with PROCESS to BUFFER (a buffer, or nil). */)
948 (process, buffer) 877 (register Lisp_Object process, Lisp_Object buffer)
949 register Lisp_Object process, buffer;
950{ 878{
951 struct Lisp_Process *p; 879 struct Lisp_Process *p;
952 880
@@ -965,8 +893,7 @@ DEFUN ("process-buffer", Fprocess_buffer, Sprocess_buffer,
965 1, 1, 0, 893 1, 1, 0,
966 doc: /* Return the buffer PROCESS is associated with. 894 doc: /* Return the buffer PROCESS is associated with.
967Output from PROCESS is inserted in this buffer unless PROCESS has a filter. */) 895Output from PROCESS is inserted in this buffer unless PROCESS has a filter. */)
968 (process) 896 (register Lisp_Object process)
969 register Lisp_Object process;
970{ 897{
971 CHECK_PROCESS (process); 898 CHECK_PROCESS (process);
972 return XPROCESS (process)->buffer; 899 return XPROCESS (process)->buffer;
@@ -975,8 +902,7 @@ Output from PROCESS is inserted in this buffer unless PROCESS has a filter. */)
975DEFUN ("process-mark", Fprocess_mark, Sprocess_mark, 902DEFUN ("process-mark", Fprocess_mark, Sprocess_mark,
976 1, 1, 0, 903 1, 1, 0,
977 doc: /* Return the marker for the end of the last output from PROCESS. */) 904 doc: /* Return the marker for the end of the last output from PROCESS. */)
978 (process) 905 (register Lisp_Object process)
979 register Lisp_Object process;
980{ 906{
981 CHECK_PROCESS (process); 907 CHECK_PROCESS (process);
982 return XPROCESS (process)->mark; 908 return XPROCESS (process)->mark;
@@ -998,8 +924,7 @@ The string argument is normally a multibyte string, except:
998- if `default-enable-multibyte-characters' is nil, it is a unibyte 924- if `default-enable-multibyte-characters' is nil, it is a unibyte
999 string (the result of converting the decoded input multibyte 925 string (the result of converting the decoded input multibyte
1000 string to unibyte with `string-make-unibyte'). */) 926 string to unibyte with `string-make-unibyte'). */)
1001 (process, filter) 927 (register Lisp_Object process, Lisp_Object filter)
1002 register Lisp_Object process, filter;
1003{ 928{
1004 struct Lisp_Process *p; 929 struct Lisp_Process *p;
1005 930
@@ -1041,8 +966,7 @@ DEFUN ("process-filter", Fprocess_filter, Sprocess_filter,
1041 1, 1, 0, 966 1, 1, 0,
1042 doc: /* Returns the filter function of PROCESS; nil if none. 967 doc: /* Returns the filter function of PROCESS; nil if none.
1043See `set-process-filter' for more info on filter functions. */) 968See `set-process-filter' for more info on filter functions. */)
1044 (process) 969 (register Lisp_Object process)
1045 register Lisp_Object process;
1046{ 970{
1047 CHECK_PROCESS (process); 971 CHECK_PROCESS (process);
1048 return XPROCESS (process)->filter; 972 return XPROCESS (process)->filter;
@@ -1053,8 +977,7 @@ DEFUN ("set-process-sentinel", Fset_process_sentinel, Sset_process_sentinel,
1053 doc: /* Give PROCESS the sentinel SENTINEL; nil for none. 977 doc: /* Give PROCESS the sentinel SENTINEL; nil for none.
1054The sentinel is called as a function when the process changes state. 978The sentinel is called as a function when the process changes state.
1055It gets two arguments: the process, and a string describing the change. */) 979It gets two arguments: the process, and a string describing the change. */)
1056 (process, sentinel) 980 (register Lisp_Object process, Lisp_Object sentinel)
1057 register Lisp_Object process, sentinel;
1058{ 981{
1059 struct Lisp_Process *p; 982 struct Lisp_Process *p;
1060 983
@@ -1071,8 +994,7 @@ DEFUN ("process-sentinel", Fprocess_sentinel, Sprocess_sentinel,
1071 1, 1, 0, 994 1, 1, 0,
1072 doc: /* Return the sentinel of PROCESS; nil if none. 995 doc: /* Return the sentinel of PROCESS; nil if none.
1073See `set-process-sentinel' for more info on sentinels. */) 996See `set-process-sentinel' for more info on sentinels. */)
1074 (process) 997 (register Lisp_Object process)
1075 register Lisp_Object process;
1076{ 998{
1077 CHECK_PROCESS (process); 999 CHECK_PROCESS (process);
1078 return XPROCESS (process)->sentinel; 1000 return XPROCESS (process)->sentinel;
@@ -1081,8 +1003,7 @@ See `set-process-sentinel' for more info on sentinels. */)
1081DEFUN ("set-process-window-size", Fset_process_window_size, 1003DEFUN ("set-process-window-size", Fset_process_window_size,
1082 Sset_process_window_size, 3, 3, 0, 1004 Sset_process_window_size, 3, 3, 0,
1083 doc: /* Tell PROCESS that it has logical window size HEIGHT and WIDTH. */) 1005 doc: /* Tell PROCESS that it has logical window size HEIGHT and WIDTH. */)
1084 (process, height, width) 1006 (register Lisp_Object process, Lisp_Object height, Lisp_Object width)
1085 register Lisp_Object process, height, width;
1086{ 1007{
1087 CHECK_PROCESS (process); 1008 CHECK_PROCESS (process);
1088 CHECK_NATNUM (height); 1009 CHECK_NATNUM (height);
@@ -1113,36 +1034,20 @@ is more appropriate for saving the process buffer.
1113Binding the variable `inherit-process-coding-system' to non-nil before 1034Binding the variable `inherit-process-coding-system' to non-nil before
1114starting the process is an alternative way of setting the inherit flag 1035starting the process is an alternative way of setting the inherit flag
1115for the process which will run. */) 1036for the process which will run. */)
1116 (process, flag) 1037 (register Lisp_Object process, Lisp_Object flag)
1117 register Lisp_Object process, flag;
1118{ 1038{
1119 CHECK_PROCESS (process); 1039 CHECK_PROCESS (process);
1120 XPROCESS (process)->inherit_coding_system_flag = !NILP (flag); 1040 XPROCESS (process)->inherit_coding_system_flag = !NILP (flag);
1121 return flag; 1041 return flag;
1122} 1042}
1123 1043
1124DEFUN ("process-inherit-coding-system-flag",
1125 Fprocess_inherit_coding_system_flag, Sprocess_inherit_coding_system_flag,
1126 1, 1, 0,
1127 doc: /* Return the value of inherit-coding-system flag for PROCESS.
1128If this flag is t, `buffer-file-coding-system' of the buffer
1129associated with PROCESS will inherit the coding system used to decode
1130the process output. */)
1131 (process)
1132 register Lisp_Object process;
1133{
1134 CHECK_PROCESS (process);
1135 return XPROCESS (process)->inherit_coding_system_flag ? Qt : Qnil;
1136}
1137
1138DEFUN ("set-process-query-on-exit-flag", 1044DEFUN ("set-process-query-on-exit-flag",
1139 Fset_process_query_on_exit_flag, Sset_process_query_on_exit_flag, 1045 Fset_process_query_on_exit_flag, Sset_process_query_on_exit_flag,
1140 2, 2, 0, 1046 2, 2, 0,
1141 doc: /* Specify if query is needed for PROCESS when Emacs is exited. 1047 doc: /* Specify if query is needed for PROCESS when Emacs is exited.
1142If the second argument FLAG is non-nil, Emacs will query the user before 1048If the second argument FLAG is non-nil, Emacs will query the user before
1143exiting or killing a buffer if PROCESS is running. */) 1049exiting or killing a buffer if PROCESS is running. */)
1144 (process, flag) 1050 (register Lisp_Object process, Lisp_Object flag)
1145 register Lisp_Object process, flag;
1146{ 1051{
1147 CHECK_PROCESS (process); 1052 CHECK_PROCESS (process);
1148 XPROCESS (process)->kill_without_query = NILP (flag); 1053 XPROCESS (process)->kill_without_query = NILP (flag);
@@ -1153,15 +1058,14 @@ DEFUN ("process-query-on-exit-flag",
1153 Fprocess_query_on_exit_flag, Sprocess_query_on_exit_flag, 1058 Fprocess_query_on_exit_flag, Sprocess_query_on_exit_flag,
1154 1, 1, 0, 1059 1, 1, 0,
1155 doc: /* Return the current value of query-on-exit flag for PROCESS. */) 1060 doc: /* Return the current value of query-on-exit flag for PROCESS. */)
1156 (process) 1061 (register Lisp_Object process)
1157 register Lisp_Object process;
1158{ 1062{
1159 CHECK_PROCESS (process); 1063 CHECK_PROCESS (process);
1160 return (XPROCESS (process)->kill_without_query ? Qnil : Qt); 1064 return (XPROCESS (process)->kill_without_query ? Qnil : Qt);
1161} 1065}
1162 1066
1163#ifdef DATAGRAM_SOCKETS 1067#ifdef DATAGRAM_SOCKETS
1164Lisp_Object Fprocess_datagram_address (); 1068Lisp_Object Fprocess_datagram_address (Lisp_Object process);
1165#endif 1069#endif
1166 1070
1167DEFUN ("process-contact", Fprocess_contact, Sprocess_contact, 1071DEFUN ("process-contact", Fprocess_contact, Sprocess_contact,
@@ -1174,8 +1078,7 @@ connection. If KEY is t, the complete contact information for the
1174connection is returned, else the specific value for the keyword KEY is 1078connection is returned, else the specific value for the keyword KEY is
1175returned. See `make-network-process' or `make-serial-process' for a 1079returned. See `make-network-process' or `make-serial-process' for a
1176list of keywords. */) 1080list of keywords. */)
1177 (process, key) 1081 (register Lisp_Object process, Lisp_Object key)
1178 register Lisp_Object process, key;
1179{ 1082{
1180 Lisp_Object contact; 1083 Lisp_Object contact;
1181 1084
@@ -1203,8 +1106,7 @@ list of keywords. */)
1203DEFUN ("process-plist", Fprocess_plist, Sprocess_plist, 1106DEFUN ("process-plist", Fprocess_plist, Sprocess_plist,
1204 1, 1, 0, 1107 1, 1, 0,
1205 doc: /* Return the plist of PROCESS. */) 1108 doc: /* Return the plist of PROCESS. */)
1206 (process) 1109 (register Lisp_Object process)
1207 register Lisp_Object process;
1208{ 1110{
1209 CHECK_PROCESS (process); 1111 CHECK_PROCESS (process);
1210 return XPROCESS (process)->plist; 1112 return XPROCESS (process)->plist;
@@ -1213,8 +1115,7 @@ DEFUN ("process-plist", Fprocess_plist, Sprocess_plist,
1213DEFUN ("set-process-plist", Fset_process_plist, Sset_process_plist, 1115DEFUN ("set-process-plist", Fset_process_plist, Sset_process_plist,
1214 2, 2, 0, 1116 2, 2, 0,
1215 doc: /* Replace the plist of PROCESS with PLIST. Returns PLIST. */) 1117 doc: /* Replace the plist of PROCESS with PLIST. Returns PLIST. */)
1216 (process, plist) 1118 (register Lisp_Object process, Lisp_Object plist)
1217 register Lisp_Object process, plist;
1218{ 1119{
1219 CHECK_PROCESS (process); 1120 CHECK_PROCESS (process);
1220 CHECK_LIST (plist); 1121 CHECK_LIST (plist);
@@ -1229,8 +1130,7 @@ DEFUN ("process-connection", Fprocess_connection, Sprocess_connection, 1, 1, 0,
1229 doc: /* Return the connection type of PROCESS. 1130 doc: /* Return the connection type of PROCESS.
1230The value is nil for a pipe, t or `pty' for a pty, or `stream' for 1131The value is nil for a pipe, t or `pty' for a pty, or `stream' for
1231a socket connection. */) 1132a socket connection. */)
1232 (process) 1133 (Lisp_Object process)
1233 Lisp_Object process;
1234{ 1134{
1235 return XPROCESS (process)->type; 1135 return XPROCESS (process)->type;
1236} 1136}
@@ -1241,8 +1141,7 @@ DEFUN ("process-type", Fprocess_type, Sprocess_type, 1, 1, 0,
1241The value is either the symbol `real', `network', or `serial'. 1141The value is either the symbol `real', `network', or `serial'.
1242PROCESS may be a process, a buffer, the name of a process or buffer, or 1142PROCESS may be a process, a buffer, the name of a process or buffer, or
1243nil, indicating the current buffer's process. */) 1143nil, indicating the current buffer's process. */)
1244 (process) 1144 (Lisp_Object process)
1245 Lisp_Object process;
1246{ 1145{
1247 Lisp_Object proc; 1146 Lisp_Object proc;
1248 proc = get_process (process); 1147 proc = get_process (process);
@@ -1258,8 +1157,7 @@ An 8 or 9 element vector represents an IPv6 address (with port number).
1258If optional second argument OMIT-PORT is non-nil, don't include a port 1157If optional second argument OMIT-PORT is non-nil, don't include a port
1259number in the string, even when present in ADDRESS. 1158number in the string, even when present in ADDRESS.
1260Returns nil if format of ADDRESS is invalid. */) 1159Returns nil if format of ADDRESS is invalid. */)
1261 (address, omit_port) 1160 (Lisp_Object address, Lisp_Object omit_port)
1262 Lisp_Object address, omit_port;
1263{ 1161{
1264 if (NILP (address)) 1162 if (NILP (address))
1265 return Qnil; 1163 return Qnil;
@@ -1327,8 +1225,7 @@ Returns nil if format of ADDRESS is invalid. */)
1327#endif 1225#endif
1328 1226
1329static Lisp_Object 1227static Lisp_Object
1330list_processes_1 (query_only) 1228list_processes_1 (Lisp_Object query_only)
1331 Lisp_Object query_only;
1332{ 1229{
1333 register Lisp_Object tail, tem; 1230 register Lisp_Object tail, tem;
1334 Lisp_Object proc, minspace, tem1; 1231 Lisp_Object proc, minspace, tem1;
@@ -1562,8 +1459,7 @@ If optional argument QUERY-ONLY is non-nil, only processes with
1562the query-on-exit flag set will be listed. 1459the query-on-exit flag set will be listed.
1563Any process listed as exited or signaled is actually eliminated 1460Any process listed as exited or signaled is actually eliminated
1564after the listing is made. */) 1461after the listing is made. */)
1565 (query_only) 1462 (Lisp_Object query_only)
1566 Lisp_Object query_only;
1567{ 1463{
1568 internal_with_output_to_temp_buffer ("*Process List*", 1464 internal_with_output_to_temp_buffer ("*Process List*",
1569 list_processes_1, query_only); 1465 list_processes_1, query_only);
@@ -1572,14 +1468,14 @@ after the listing is made. */)
1572 1468
1573DEFUN ("process-list", Fprocess_list, Sprocess_list, 0, 0, 0, 1469DEFUN ("process-list", Fprocess_list, Sprocess_list, 0, 0, 0,
1574 doc: /* Return a list of all processes. */) 1470 doc: /* Return a list of all processes. */)
1575 () 1471 (void)
1576{ 1472{
1577 return Fmapcar (Qcdr, Vprocess_alist); 1473 return Fmapcar (Qcdr, Vprocess_alist);
1578} 1474}
1579 1475
1580/* Starting asynchronous inferior processes. */ 1476/* Starting asynchronous inferior processes. */
1581 1477
1582static Lisp_Object start_process_unwind (); 1478static Lisp_Object start_process_unwind (Lisp_Object proc);
1583 1479
1584DEFUN ("start-process", Fstart_process, Sstart_process, 3, MANY, 0, 1480DEFUN ("start-process", Fstart_process, Sstart_process, 3, MANY, 0,
1585 doc: /* Start a program in a subprocess. Return the process object for it. 1481 doc: /* Start a program in a subprocess. Return the process object for it.
@@ -1600,9 +1496,7 @@ the command through a shell and redirect one of them using the shell
1600syntax. 1496syntax.
1601 1497
1602usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */) 1498usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1603 (nargs, args) 1499 (int nargs, register Lisp_Object *args)
1604 int nargs;
1605 register Lisp_Object *args;
1606{ 1500{
1607 Lisp_Object buffer, name, program, proc, current_dir, tem; 1501 Lisp_Object buffer, name, program, proc, current_dir, tem;
1608 register unsigned char **new_argv; 1502 register unsigned char **new_argv;
@@ -1814,8 +1708,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1814 an error and the process wasn't started successfully, so we should 1708 an error and the process wasn't started successfully, so we should
1815 remove it from the process list. */ 1709 remove it from the process list. */
1816static Lisp_Object 1710static Lisp_Object
1817start_process_unwind (proc) 1711start_process_unwind (Lisp_Object proc)
1818 Lisp_Object proc;
1819{ 1712{
1820 if (!PROCESSP (proc)) 1713 if (!PROCESSP (proc))
1821 abort (); 1714 abort ();
@@ -1828,8 +1721,7 @@ start_process_unwind (proc)
1828} 1721}
1829 1722
1830static void 1723static void
1831create_process_1 (timer) 1724create_process_1 (struct atimer *timer)
1832 struct atimer *timer;
1833{ 1725{
1834 /* Nothing to do. */ 1726 /* Nothing to do. */
1835} 1727}
@@ -1855,10 +1747,7 @@ create_process_sigchld ()
1855#endif 1747#endif
1856 1748
1857void 1749void
1858create_process (process, new_argv, current_dir) 1750create_process (Lisp_Object process, char **new_argv, Lisp_Object current_dir)
1859 Lisp_Object process;
1860 char **new_argv;
1861 Lisp_Object current_dir;
1862{ 1751{
1863 int inchannel, outchannel; 1752 int inchannel, outchannel;
1864 pid_t pid; 1753 pid_t pid;
@@ -2038,7 +1927,7 @@ create_process (process, new_argv, current_dir)
2038 process_set_signal to fail on SGI when using a pipe. */ 1927 process_set_signal to fail on SGI when using a pipe. */
2039 setsid (); 1928 setsid ();
2040 /* Make the pty's terminal the controlling terminal. */ 1929 /* Make the pty's terminal the controlling terminal. */
2041 if (pty_flag) 1930 if (pty_flag && xforkin >= 0)
2042 { 1931 {
2043#ifdef TIOCSCTTY 1932#ifdef TIOCSCTTY
2044 /* We ignore the return value 1933 /* We ignore the return value
@@ -2081,8 +1970,11 @@ create_process (process, new_argv, current_dir)
2081 /* I wonder: would just ioctl (0, TIOCNOTTY, 0) work here? 1970 /* I wonder: would just ioctl (0, TIOCNOTTY, 0) work here?
2082 I can't test it since I don't have 4.3. */ 1971 I can't test it since I don't have 4.3. */
2083 int j = emacs_open ("/dev/tty", O_RDWR, 0); 1972 int j = emacs_open ("/dev/tty", O_RDWR, 0);
2084 ioctl (j, TIOCNOTTY, 0); 1973 if (j >= 0)
2085 emacs_close (j); 1974 {
1975 ioctl (j, TIOCNOTTY, 0);
1976 emacs_close (j);
1977 }
2086#ifndef USG 1978#ifndef USG
2087 /* In order to get a controlling terminal on some versions 1979 /* In order to get a controlling terminal on some versions
2088 of BSD, it is necessary to put the process in pgrp 0 1980 of BSD, it is necessary to put the process in pgrp 0
@@ -2242,8 +2134,7 @@ create_process (process, new_argv, current_dir)
2242} 2134}
2243 2135
2244void 2136void
2245create_pty (process) 2137create_pty (Lisp_Object process)
2246 Lisp_Object process;
2247{ 2138{
2248 int inchannel, outchannel; 2139 int inchannel, outchannel;
2249 2140
@@ -2330,9 +2221,7 @@ create_pty (process)
2330 The address family of sa is not included in the result. */ 2221 The address family of sa is not included in the result. */
2331 2222
2332static Lisp_Object 2223static Lisp_Object
2333conv_sockaddr_to_lisp (sa, len) 2224conv_sockaddr_to_lisp (struct sockaddr *sa, int len)
2334 struct sockaddr *sa;
2335 int len;
2336{ 2225{
2337 Lisp_Object address; 2226 Lisp_Object address;
2338 int i; 2227 int i;
@@ -2342,7 +2231,7 @@ conv_sockaddr_to_lisp (sa, len)
2342 /* Workaround for a bug in getsockname on BSD: Names bound to 2231 /* Workaround for a bug in getsockname on BSD: Names bound to
2343 sockets in the UNIX domain are inaccessible; getsockname returns 2232 sockets in the UNIX domain are inaccessible; getsockname returns
2344 a zero length name. */ 2233 a zero length name. */
2345 if (len < OFFSETOF (struct sockaddr, sa_family) + sizeof (sa->sa_family)) 2234 if (len < offsetof (struct sockaddr, sa_family) + sizeof (sa->sa_family))
2346 return empty_unibyte_string; 2235 return empty_unibyte_string;
2347 2236
2348 switch (sa->sa_family) 2237 switch (sa->sa_family)
@@ -2382,7 +2271,7 @@ conv_sockaddr_to_lisp (sa, len)
2382 } 2271 }
2383#endif 2272#endif
2384 default: 2273 default:
2385 len -= OFFSETOF (struct sockaddr, sa_family) + sizeof (sa->sa_family); 2274 len -= offsetof (struct sockaddr, sa_family) + sizeof (sa->sa_family);
2386 address = Fcons (make_number (sa->sa_family), 2275 address = Fcons (make_number (sa->sa_family),
2387 Fmake_vector (make_number (len), Qnil)); 2276 Fmake_vector (make_number (len), Qnil));
2388 p = XVECTOR (XCDR (address)); 2277 p = XVECTOR (XCDR (address));
@@ -2401,9 +2290,7 @@ conv_sockaddr_to_lisp (sa, len)
2401/* Get family and required size for sockaddr structure to hold ADDRESS. */ 2290/* Get family and required size for sockaddr structure to hold ADDRESS. */
2402 2291
2403static int 2292static int
2404get_lisp_to_sockaddr_size (address, familyp) 2293get_lisp_to_sockaddr_size (Lisp_Object address, int *familyp)
2405 Lisp_Object address;
2406 int *familyp;
2407{ 2294{
2408 register struct Lisp_Vector *p; 2295 register struct Lisp_Vector *p;
2409 2296
@@ -2448,17 +2335,13 @@ get_lisp_to_sockaddr_size (address, familyp)
2448 we return after zeroing *SA. */ 2335 we return after zeroing *SA. */
2449 2336
2450static void 2337static void
2451conv_lisp_to_sockaddr (family, address, sa, len) 2338conv_lisp_to_sockaddr (int family, Lisp_Object address, struct sockaddr *sa, int len)
2452 int family;
2453 Lisp_Object address;
2454 struct sockaddr *sa;
2455 int len;
2456{ 2339{
2457 register struct Lisp_Vector *p; 2340 register struct Lisp_Vector *p;
2458 register unsigned char *cp = NULL; 2341 register unsigned char *cp = NULL;
2459 register int i; 2342 register int i;
2460 2343
2461 bzero (sa, len); 2344 memset (sa, 0, len);
2462 2345
2463 if (VECTORP (address)) 2346 if (VECTORP (address))
2464 { 2347 {
@@ -2522,8 +2405,7 @@ conv_lisp_to_sockaddr (family, address, sa, len)
2522DEFUN ("process-datagram-address", Fprocess_datagram_address, Sprocess_datagram_address, 2405DEFUN ("process-datagram-address", Fprocess_datagram_address, Sprocess_datagram_address,
2523 1, 1, 0, 2406 1, 1, 0,
2524 doc: /* Get the current datagram address associated with PROCESS. */) 2407 doc: /* Get the current datagram address associated with PROCESS. */)
2525 (process) 2408 (Lisp_Object process)
2526 Lisp_Object process;
2527{ 2409{
2528 int channel; 2410 int channel;
2529 2411
@@ -2541,8 +2423,7 @@ DEFUN ("set-process-datagram-address", Fset_process_datagram_address, Sset_proce
2541 2, 2, 0, 2423 2, 2, 0,
2542 doc: /* Set the datagram address for PROCESS to ADDRESS. 2424 doc: /* Set the datagram address for PROCESS to ADDRESS.
2543Returns nil upon error setting address, ADDRESS otherwise. */) 2425Returns nil upon error setting address, ADDRESS otherwise. */)
2544 (process, address) 2426 (Lisp_Object process, Lisp_Object address)
2545 Lisp_Object process, address;
2546{ 2427{
2547 int channel; 2428 int channel;
2548 int family, len; 2429 int family, len;
@@ -2609,9 +2490,7 @@ static const struct socket_options {
2609*/ 2490*/
2610 2491
2611static int 2492static int
2612set_socket_option (s, opt, val) 2493set_socket_option (int s, Lisp_Object opt, Lisp_Object val)
2613 int s;
2614 Lisp_Object opt, val;
2615{ 2494{
2616 char *name; 2495 char *name;
2617 const struct socket_options *sopt; 2496 const struct socket_options *sopt;
@@ -2655,12 +2534,12 @@ set_socket_option (s, opt, val)
2655 /* This is broken, at least in the Linux 2.4 kernel. 2534 /* This is broken, at least in the Linux 2.4 kernel.
2656 To unbind, the arg must be a zero integer, not the empty string. 2535 To unbind, the arg must be a zero integer, not the empty string.
2657 This should work on all systems. KFS. 2003-09-23. */ 2536 This should work on all systems. KFS. 2003-09-23. */
2658 bzero (devname, sizeof devname); 2537 memset (devname, 0, sizeof devname);
2659 if (STRINGP (val)) 2538 if (STRINGP (val))
2660 { 2539 {
2661 char *arg = (char *) SDATA (val); 2540 char *arg = (char *) SDATA (val);
2662 int len = min (strlen (arg), IFNAMSIZ); 2541 int len = min (strlen (arg), IFNAMSIZ);
2663 bcopy (arg, devname, len); 2542 memcpy (devname, arg, len);
2664 } 2543 }
2665 else if (!NILP (val)) 2544 else if (!NILP (val))
2666 error ("Bad option value for %s", name); 2545 error ("Bad option value for %s", name);
@@ -2705,9 +2584,7 @@ DEFUN ("set-network-process-option",
2705See `make-network-process' for a list of options and values. 2584See `make-network-process' for a list of options and values.
2706If optional fourth arg NO-ERROR is non-nil, don't signal an error if 2585If optional fourth arg NO-ERROR is non-nil, don't signal an error if
2707OPTION is not a supported option, return nil instead; otherwise return t. */) 2586OPTION is not a supported option, return nil instead; otherwise return t. */)
2708 (process, option, value, no_error) 2587 (Lisp_Object process, Lisp_Object option, Lisp_Object value, Lisp_Object no_error)
2709 Lisp_Object process, option, value;
2710 Lisp_Object no_error;
2711{ 2588{
2712 int s; 2589 int s;
2713 struct Lisp_Process *p; 2590 struct Lisp_Process *p;
@@ -2794,9 +2671,7 @@ Examples:
2794\(serial-process-configure :port "\\\\.\\COM13" :bytesize 7) 2671\(serial-process-configure :port "\\\\.\\COM13" :bytesize 7)
2795 2672
2796usage: (serial-process-configure &rest ARGS) */) 2673usage: (serial-process-configure &rest ARGS) */)
2797 (nargs, args) 2674 (int nargs, Lisp_Object *args)
2798 int nargs;
2799 Lisp_Object *args;
2800{ 2675{
2801 struct Lisp_Process *p; 2676 struct Lisp_Process *p;
2802 Lisp_Object contact = Qnil; 2677 Lisp_Object contact = Qnil;
@@ -2913,9 +2788,7 @@ Examples:
2913\(make-serial-process :port "/dev/tty.BlueConsole-SPP-1" :speed nil) 2788\(make-serial-process :port "/dev/tty.BlueConsole-SPP-1" :speed nil)
2914 2789
2915usage: (make-serial-process &rest ARGS) */) 2790usage: (make-serial-process &rest ARGS) */)
2916 (nargs, args) 2791 (int nargs, Lisp_Object *args)
2917 int nargs;
2918 Lisp_Object *args;
2919{ 2792{
2920 int fd = -1; 2793 int fd = -1;
2921 Lisp_Object proc, contact, port; 2794 Lisp_Object proc, contact, port;
@@ -3027,7 +2900,7 @@ usage: (make-serial-process &rest ARGS) */)
3027 p->inherit_coding_system_flag 2900 p->inherit_coding_system_flag
3028 = !(!NILP (tem) || NILP (buffer) || !inherit_process_coding_system); 2901 = !(!NILP (tem) || NILP (buffer) || !inherit_process_coding_system);
3029 2902
3030 Fserial_process_configure(nargs, args); 2903 Fserial_process_configure (nargs, args);
3031 2904
3032 specpdl_ptr = specpdl + specpdl_count; 2905 specpdl_ptr = specpdl + specpdl_count;
3033 2906
@@ -3194,9 +3067,7 @@ The original argument list, modified with the actual connection
3194information, is available via the `process-contact' function. 3067information, is available via the `process-contact' function.
3195 3068
3196usage: (make-network-process &rest ARGS) */) 3069usage: (make-network-process &rest ARGS) */)
3197 (nargs, args) 3070 (int nargs, Lisp_Object *args)
3198 int nargs;
3199 Lisp_Object *args;
3200{ 3071{
3201 Lisp_Object proc; 3072 Lisp_Object proc;
3202 Lisp_Object contact; 3073 Lisp_Object contact;
@@ -3369,7 +3240,7 @@ usage: (make-network-process &rest ARGS) */)
3369 host = Qnil; 3240 host = Qnil;
3370 } 3241 }
3371 CHECK_STRING (service); 3242 CHECK_STRING (service);
3372 bzero (&address_un, sizeof address_un); 3243 memset (&address_un, 0, sizeof address_un);
3373 address_un.sun_family = AF_LOCAL; 3244 address_un.sun_family = AF_LOCAL;
3374 strncpy (address_un.sun_path, SDATA (service), sizeof address_un.sun_path); 3245 strncpy (address_un.sun_path, SDATA (service), sizeof address_un.sun_path);
3375 ai.ai_addr = (struct sockaddr *) &address_un; 3246 ai.ai_addr = (struct sockaddr *) &address_un;
@@ -3425,7 +3296,7 @@ usage: (make-network-process &rest ARGS) */)
3425 ret = getaddrinfo (SDATA (host), portstring, &hints, &res); 3296 ret = getaddrinfo (SDATA (host), portstring, &hints, &res);
3426 if (ret) 3297 if (ret)
3427#ifdef HAVE_GAI_STRERROR 3298#ifdef HAVE_GAI_STRERROR
3428 error ("%s/%s %s", SDATA (host), portstring, gai_strerror(ret)); 3299 error ("%s/%s %s", SDATA (host), portstring, gai_strerror (ret));
3429#else 3300#else
3430 error ("%s/%s getaddrinfo error %d", SDATA (host), portstring, ret); 3301 error ("%s/%s getaddrinfo error %d", SDATA (host), portstring, ret);
3431#endif 3302#endif
@@ -3453,7 +3324,7 @@ usage: (make-network-process &rest ARGS) */)
3453 port = svc_info->s_port; 3324 port = svc_info->s_port;
3454 } 3325 }
3455 3326
3456 bzero (&address_in, sizeof address_in); 3327 memset (&address_in, 0, sizeof address_in);
3457 address_in.sin_family = family; 3328 address_in.sin_family = family;
3458 address_in.sin_addr.s_addr = INADDR_ANY; 3329 address_in.sin_addr.s_addr = INADDR_ANY;
3459 address_in.sin_port = port; 3330 address_in.sin_port = port;
@@ -3477,8 +3348,8 @@ usage: (make-network-process &rest ARGS) */)
3477 3348
3478 if (host_info_ptr) 3349 if (host_info_ptr)
3479 { 3350 {
3480 bcopy (host_info_ptr->h_addr, (char *) &address_in.sin_addr, 3351 memcpy (&address_in.sin_addr, host_info_ptr->h_addr,
3481 host_info_ptr->h_length); 3352 host_info_ptr->h_length);
3482 family = host_info_ptr->h_addrtype; 3353 family = host_info_ptr->h_addrtype;
3483 address_in.sin_family = family; 3354 address_in.sin_family = family;
3484 } 3355 }
@@ -3490,8 +3361,8 @@ usage: (make-network-process &rest ARGS) */)
3490 if (numeric_addr == -1) 3361 if (numeric_addr == -1)
3491 error ("Unknown host \"%s\"", SDATA (host)); 3362 error ("Unknown host \"%s\"", SDATA (host));
3492 3363
3493 bcopy ((char *)&numeric_addr, (char *) &address_in.sin_addr, 3364 memcpy (&address_in.sin_addr, &numeric_addr,
3494 sizeof (address_in.sin_addr)); 3365 sizeof (address_in.sin_addr));
3495 } 3366 }
3496 3367
3497 } 3368 }
@@ -3675,7 +3546,7 @@ usage: (make-network-process &rest ARGS) */)
3675 if (is_server) 3546 if (is_server)
3676 { 3547 {
3677 Lisp_Object remote; 3548 Lisp_Object remote;
3678 bzero (datagram_address[s].sa, lres->ai_addrlen); 3549 memset (datagram_address[s].sa, 0, lres->ai_addrlen);
3679 if (remote = Fplist_get (contact, QCremote), !NILP (remote)) 3550 if (remote = Fplist_get (contact, QCremote), !NILP (remote))
3680 { 3551 {
3681 int rfamily, rlen; 3552 int rfamily, rlen;
@@ -3686,7 +3557,7 @@ usage: (make-network-process &rest ARGS) */)
3686 } 3557 }
3687 } 3558 }
3688 else 3559 else
3689 bcopy (lres->ai_addr, datagram_address[s].sa, lres->ai_addrlen); 3560 memcpy (datagram_address[s].sa, lres->ai_addr, lres->ai_addrlen);
3690 } 3561 }
3691#endif 3562#endif
3692 contact = Fplist_put (contact, QCaddress, 3563 contact = Fplist_put (contact, QCaddress,
@@ -3698,7 +3569,7 @@ usage: (make-network-process &rest ARGS) */)
3698 int len1 = sizeof (sa1); 3569 int len1 = sizeof (sa1);
3699 if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0) 3570 if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0)
3700 contact = Fplist_put (contact, QClocal, 3571 contact = Fplist_put (contact, QClocal,
3701 conv_sockaddr_to_lisp (&sa1, len1)); 3572 conv_sockaddr_to_lisp ((struct sockaddr *)&sa1, len1));
3702 } 3573 }
3703#endif 3574#endif
3704 } 3575 }
@@ -3910,7 +3781,7 @@ DEFUN ("network-interface-list", Fnetwork_interface_list, Snetwork_interface_lis
3910Each element is a cons, the car of which is a string containing the 3781Each element is a cons, the car of which is a string containing the
3911interface name, and the cdr is the network address in internal 3782interface name, and the cdr is the network address in internal
3912format; see the description of ADDRESS in `make-network-process'. */) 3783format; see the description of ADDRESS in `make-network-process'. */)
3913 () 3784 (void)
3914{ 3785{
3915 struct ifconf ifconf; 3786 struct ifconf ifconf;
3916 struct ifreq *ifreqs = NULL; 3787 struct ifreq *ifreqs = NULL;
@@ -3924,7 +3795,7 @@ format; see the description of ADDRESS in `make-network-process'. */)
3924 3795
3925 again: 3796 again:
3926 ifaces += 25; 3797 ifaces += 25;
3927 buf_size = ifaces * sizeof(ifreqs[0]); 3798 buf_size = ifaces * sizeof (ifreqs[0]);
3928 ifreqs = (struct ifreq *)xrealloc(ifreqs, buf_size); 3799 ifreqs = (struct ifreq *)xrealloc(ifreqs, buf_size);
3929 if (!ifreqs) 3800 if (!ifreqs)
3930 { 3801 {
@@ -3953,7 +3824,7 @@ format; see the description of ADDRESS in `make-network-process'. */)
3953 char namebuf[sizeof (ifq->ifr_name) + 1]; 3824 char namebuf[sizeof (ifq->ifr_name) + 1];
3954 if (ifq->ifr_addr.sa_family != AF_INET) 3825 if (ifq->ifr_addr.sa_family != AF_INET)
3955 continue; 3826 continue;
3956 bcopy (ifq->ifr_name, namebuf, sizeof (ifq->ifr_name)); 3827 memcpy (namebuf, ifq->ifr_name, sizeof (ifq->ifr_name));
3957 namebuf[sizeof (ifq->ifr_name)] = 0; 3828 namebuf[sizeof (ifq->ifr_name)] = 0;
3958 res = Fcons (Fcons (build_string (namebuf), 3829 res = Fcons (Fcons (build_string (namebuf),
3959 conv_sockaddr_to_lisp (&ifq->ifr_addr, 3830 conv_sockaddr_to_lisp (&ifq->ifr_addr,
@@ -4045,8 +3916,7 @@ The return value is a list (ADDR BCAST NETMASK HWADDR FLAGS),
4045where ADDR is the layer 3 address, BCAST is the layer 3 broadcast address, 3916where ADDR is the layer 3 address, BCAST is the layer 3 broadcast address,
4046NETMASK is the layer 3 network mask, HWADDR is the layer 2 addres, and 3917NETMASK is the layer 3 network mask, HWADDR is the layer 2 addres, and
4047FLAGS is the current flags of the interface. */) 3918FLAGS is the current flags of the interface. */)
4048 (ifname) 3919 (Lisp_Object ifname)
4049 Lisp_Object ifname;
4050{ 3920{
4051 struct ifreq rq; 3921 struct ifreq rq;
4052 Lisp_Object res = Qnil; 3922 Lisp_Object res = Qnil;
@@ -4056,7 +3926,7 @@ FLAGS is the current flags of the interface. */)
4056 3926
4057 CHECK_STRING (ifname); 3927 CHECK_STRING (ifname);
4058 3928
4059 bzero (rq.ifr_name, sizeof rq.ifr_name); 3929 memset (rq.ifr_name, 0, sizeof rq.ifr_name);
4060 strncpy (rq.ifr_name, SDATA (ifname), sizeof (rq.ifr_name)); 3930 strncpy (rq.ifr_name, SDATA (ifname), sizeof (rq.ifr_name));
4061 3931
4062 s = socket (AF_INET, SOCK_STREAM, 0); 3932 s = socket (AF_INET, SOCK_STREAM, 0);
@@ -4151,8 +4021,7 @@ FLAGS is the current flags of the interface. */)
4151/* Turn off input and output for process PROC. */ 4021/* Turn off input and output for process PROC. */
4152 4022
4153void 4023void
4154deactivate_process (proc) 4024deactivate_process (Lisp_Object proc)
4155 Lisp_Object proc;
4156{ 4025{
4157 register int inchannel, outchannel; 4026 register int inchannel, outchannel;
4158 register struct Lisp_Process *p = XPROCESS (proc); 4027 register struct Lisp_Process *p = XPROCESS (proc);
@@ -4212,31 +4081,6 @@ deactivate_process (proc)
4212 } 4081 }
4213} 4082}
4214 4083
4215/* Close all descriptors currently in use for communication
4216 with subprocess. This is used in a newly-forked subprocess
4217 to get rid of irrelevant descriptors. */
4218
4219void
4220close_process_descs ()
4221{
4222#ifndef WINDOWSNT
4223 int i;
4224 for (i = 0; i < MAXDESC; i++)
4225 {
4226 Lisp_Object process;
4227 process = chan_process[i];
4228 if (!NILP (process))
4229 {
4230 int in = XPROCESS (process)->infd;
4231 int out = XPROCESS (process)->outfd;
4232 if (in >= 0)
4233 emacs_close (in);
4234 if (out >= 0 && in != out)
4235 emacs_close (out);
4236 }
4237 }
4238#endif
4239}
4240 4084
4241DEFUN ("accept-process-output", Faccept_process_output, Saccept_process_output, 4085DEFUN ("accept-process-output", Faccept_process_output, Saccept_process_output,
4242 0, 4, 0, 4086 0, 4, 0,
@@ -4255,8 +4099,7 @@ If optional fourth arg JUST-THIS-ONE is non-nil, only accept output
4255from PROCESS, suspending reading output from other processes. 4099from PROCESS, suspending reading output from other processes.
4256If JUST-THIS-ONE is an integer, don't run any timers either. 4100If JUST-THIS-ONE is an integer, don't run any timers either.
4257Return non-nil if we received any output before the timeout expired. */) 4101Return non-nil if we received any output before the timeout expired. */)
4258 (process, seconds, millisec, just_this_one) 4102 (register Lisp_Object process, Lisp_Object seconds, Lisp_Object millisec, Lisp_Object just_this_one)
4259 register Lisp_Object process, seconds, millisec, just_this_one;
4260{ 4103{
4261 int secs, usecs = 0; 4104 int secs, usecs = 0;
4262 4105
@@ -4310,9 +4153,7 @@ Return non-nil if we received any output before the timeout expired. */)
4310static int connect_counter = 0; 4153static int connect_counter = 0;
4311 4154
4312static void 4155static void
4313server_accept_connection (server, channel) 4156server_accept_connection (Lisp_Object server, int channel)
4314 Lisp_Object server;
4315 int channel;
4316{ 4157{
4317 Lisp_Object proc, caller, name, buffer; 4158 Lisp_Object proc, caller, name, buffer;
4318 Lisp_Object contact, host, service; 4159 Lisp_Object contact, host, service;
@@ -4389,7 +4230,7 @@ server_accept_connection (server, channel)
4389 int i; 4230 int i;
4390 args[0] = build_string ("%x:%x:%x:%x:%x:%x:%x:%x"); 4231 args[0] = build_string ("%x:%x:%x:%x:%x:%x:%x:%x");
4391 for (i = 0; i < 8; i++) 4232 for (i = 0; i < 8; i++)
4392 args[i+1] = make_number (ntohs(ip6[i])); 4233 args[i+1] = make_number (ntohs (ip6[i]));
4393 host = Fformat (9, args); 4234 host = Fformat (9, args);
4394 service = make_number (ntohs (saddr.in.sin_port)); 4235 service = make_number (ntohs (saddr.in.sin_port));
4395 4236
@@ -4528,8 +4369,7 @@ server_accept_connection (server, channel)
4528static int waiting_for_user_input_p; 4369static int waiting_for_user_input_p;
4529 4370
4530static Lisp_Object 4371static Lisp_Object
4531wait_reading_process_output_unwind (data) 4372wait_reading_process_output_unwind (Lisp_Object data)
4532 Lisp_Object data;
4533{ 4373{
4534 waiting_for_user_input_p = XINT (data); 4374 waiting_for_user_input_p = XINT (data);
4535 return Qnil; 4375 return Qnil;
@@ -4537,7 +4377,7 @@ wait_reading_process_output_unwind (data)
4537 4377
4538/* This is here so breakpoints can be put on it. */ 4378/* This is here so breakpoints can be put on it. */
4539static void 4379static void
4540wait_reading_process_output_1 () 4380wait_reading_process_output_1 (void)
4541{ 4381{
4542} 4382}
4543 4383
@@ -4550,10 +4390,7 @@ wait_reading_process_output_1 ()
4550 4390
4551#ifndef select 4391#ifndef select
4552static INLINE int 4392static INLINE int
4553select_wrapper (n, rfd, wfd, xfd, tmo) 4393select_wrapper (int n, fd_set *rfd, fd_set *wfd, fd_set *xfd, struct timeval *tmo)
4554 int n;
4555 SELECT_TYPE *rfd, *wfd, *xfd;
4556 EMACS_TIME *tmo;
4557{ 4394{
4558 return select (n, rfd, wfd, xfd, tmo); 4395 return select (n, rfd, wfd, xfd, tmo);
4559} 4396}
@@ -4598,12 +4435,10 @@ select_wrapper (n, rfd, wfd, xfd, tmo)
4598 Otherwise, return true if we received input from any process. */ 4435 Otherwise, return true if we received input from any process. */
4599 4436
4600int 4437int
4601wait_reading_process_output (time_limit, microsecs, read_kbd, do_display, 4438wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
4602 wait_for_cell, wait_proc, just_wait_proc) 4439 int do_display,
4603 int time_limit, microsecs, read_kbd, do_display; 4440 Lisp_Object wait_for_cell,
4604 Lisp_Object wait_for_cell; 4441 struct Lisp_Process *wait_proc, int just_wait_proc)
4605 struct Lisp_Process *wait_proc;
4606 int just_wait_proc;
4607{ 4442{
4608 register int channel, nfds; 4443 register int channel, nfds;
4609 SELECT_TYPE Available; 4444 SELECT_TYPE Available;
@@ -4762,7 +4597,10 @@ wait_reading_process_output (time_limit, microsecs, read_kbd, do_display,
4762 SELECT_TYPE Ctemp; 4597 SELECT_TYPE Ctemp;
4763#endif 4598#endif
4764 4599
4765 Atemp = input_wait_mask; 4600 if (kbd_on_hold_p ())
4601 FD_ZERO (&Atemp);
4602 else
4603 Atemp = input_wait_mask;
4766 IF_NON_BLOCKING_CONNECT (Ctemp = connect_wait_mask); 4604 IF_NON_BLOCKING_CONNECT (Ctemp = connect_wait_mask);
4767 4605
4768 EMACS_SET_SECS_USECS (timeout, 0, 0); 4606 EMACS_SET_SECS_USECS (timeout, 0, 0);
@@ -5195,23 +5033,23 @@ wait_reading_process_output (time_limit, microsecs, read_kbd, do_display,
5195 /* getsockopt(,,SO_ERROR,,) is said to hang on some systems. 5033 /* getsockopt(,,SO_ERROR,,) is said to hang on some systems.
5196 So only use it on systems where it is known to work. */ 5034 So only use it on systems where it is known to work. */
5197 { 5035 {
5198 int xlen = sizeof(xerrno); 5036 int xlen = sizeof (xerrno);
5199 if (getsockopt(channel, SOL_SOCKET, SO_ERROR, &xerrno, &xlen)) 5037 if (getsockopt (channel, SOL_SOCKET, SO_ERROR, &xerrno, &xlen))
5200 xerrno = errno; 5038 xerrno = errno;
5201 } 5039 }
5202#else 5040#else
5203 { 5041 {
5204 struct sockaddr pname; 5042 struct sockaddr pname;
5205 int pnamelen = sizeof(pname); 5043 int pnamelen = sizeof (pname);
5206 5044
5207 /* If connection failed, getpeername will fail. */ 5045 /* If connection failed, getpeername will fail. */
5208 xerrno = 0; 5046 xerrno = 0;
5209 if (getpeername(channel, &pname, &pnamelen) < 0) 5047 if (getpeername (channel, &pname, &pnamelen) < 0)
5210 { 5048 {
5211 /* Obtain connect failure code through error slippage. */ 5049 /* Obtain connect failure code through error slippage. */
5212 char dummy; 5050 char dummy;
5213 xerrno = errno; 5051 xerrno = errno;
5214 if (errno == ENOTCONN && read(channel, &dummy, 1) < 0) 5052 if (errno == ENOTCONN && read (channel, &dummy, 1) < 0)
5215 xerrno = errno; 5053 xerrno = errno;
5216 } 5054 }
5217 } 5055 }
@@ -5258,15 +5096,13 @@ wait_reading_process_output (time_limit, microsecs, read_kbd, do_display,
5258/* Given a list (FUNCTION ARGS...), apply FUNCTION to the ARGS. */ 5096/* Given a list (FUNCTION ARGS...), apply FUNCTION to the ARGS. */
5259 5097
5260static Lisp_Object 5098static Lisp_Object
5261read_process_output_call (fun_and_args) 5099read_process_output_call (Lisp_Object fun_and_args)
5262 Lisp_Object fun_and_args;
5263{ 5100{
5264 return apply1 (XCAR (fun_and_args), XCDR (fun_and_args)); 5101 return apply1 (XCAR (fun_and_args), XCDR (fun_and_args));
5265} 5102}
5266 5103
5267static Lisp_Object 5104static Lisp_Object
5268read_process_output_error_handler (error) 5105read_process_output_error_handler (Lisp_Object error)
5269 Lisp_Object error;
5270{ 5106{
5271 cmd_error_internal (error, "error in process filter: "); 5107 cmd_error_internal (error, "error in process filter: ");
5272 Vinhibit_quit = Qt; 5108 Vinhibit_quit = Qt;
@@ -5287,9 +5123,7 @@ read_process_output_error_handler (error)
5287 for decoding. */ 5123 for decoding. */
5288 5124
5289static int 5125static int
5290read_process_output (proc, channel) 5126read_process_output (Lisp_Object proc, register int channel)
5291 Lisp_Object proc;
5292 register int channel;
5293{ 5127{
5294 register int nbytes; 5128 register int nbytes;
5295 char *chars; 5129 char *chars;
@@ -5305,7 +5139,7 @@ read_process_output (proc, channel)
5305 chars = (char *) alloca (carryover + readmax); 5139 chars = (char *) alloca (carryover + readmax);
5306 if (carryover) 5140 if (carryover)
5307 /* See the comment above. */ 5141 /* See the comment above. */
5308 bcopy (SDATA (p->decoding_buf), chars, carryover); 5142 memcpy (chars, SDATA (p->decoding_buf), carryover);
5309 5143
5310#ifdef DATAGRAM_SOCKETS 5144#ifdef DATAGRAM_SOCKETS
5311 /* We have a working select, so proc_buffered_char is always -1. */ 5145 /* We have a working select, so proc_buffered_char is always -1. */
@@ -5449,8 +5283,8 @@ read_process_output (proc, channel)
5449 { 5283 {
5450 if (SCHARS (p->decoding_buf) < coding->carryover_bytes) 5284 if (SCHARS (p->decoding_buf) < coding->carryover_bytes)
5451 p->decoding_buf = make_uninit_string (coding->carryover_bytes); 5285 p->decoding_buf = make_uninit_string (coding->carryover_bytes);
5452 bcopy (coding->carryover, SDATA (p->decoding_buf), 5286 memcpy (SDATA (p->decoding_buf), coding->carryover,
5453 coding->carryover_bytes); 5287 coding->carryover_bytes);
5454 p->decoding_carryover = coding->carryover_bytes; 5288 p->decoding_carryover = coding->carryover_bytes;
5455 } 5289 }
5456 if (SBYTES (text) > 0) 5290 if (SBYTES (text) > 0)
@@ -5541,8 +5375,8 @@ read_process_output (proc, channel)
5541 { 5375 {
5542 if (SCHARS (p->decoding_buf) < coding->carryover_bytes) 5376 if (SCHARS (p->decoding_buf) < coding->carryover_bytes)
5543 p->decoding_buf = make_uninit_string (coding->carryover_bytes); 5377 p->decoding_buf = make_uninit_string (coding->carryover_bytes);
5544 bcopy (coding->carryover, SDATA (p->decoding_buf), 5378 memcpy (SDATA (p->decoding_buf), coding->carryover,
5545 coding->carryover_bytes); 5379 coding->carryover_bytes);
5546 p->decoding_carryover = coding->carryover_bytes; 5380 p->decoding_carryover = coding->carryover_bytes;
5547 } 5381 }
5548 /* Adjust the multibyteness of TEXT to that of the buffer. */ 5382 /* Adjust the multibyteness of TEXT to that of the buffer. */
@@ -5599,15 +5433,6 @@ read_process_output (proc, channel)
5599 unbind_to (count, Qnil); 5433 unbind_to (count, Qnil);
5600 return nbytes; 5434 return nbytes;
5601} 5435}
5602
5603DEFUN ("waiting-for-user-input-p", Fwaiting_for_user_input_p, Swaiting_for_user_input_p,
5604 0, 0, 0,
5605 doc: /* Returns non-nil if Emacs is waiting for input from the user.
5606This is intended for use by asynchronous process output filters and sentinels. */)
5607 ()
5608{
5609 return (waiting_for_user_input_p ? Qt : Qnil);
5610}
5611 5436
5612/* Sending data to subprocess */ 5437/* Sending data to subprocess */
5613 5438
@@ -5615,7 +5440,7 @@ jmp_buf send_process_frame;
5615Lisp_Object process_sent_to; 5440Lisp_Object process_sent_to;
5616 5441
5617SIGTYPE 5442SIGTYPE
5618send_process_trap () 5443send_process_trap (int ignore)
5619{ 5444{
5620 SIGNAL_THREAD_CHECK (SIGPIPE); 5445 SIGNAL_THREAD_CHECK (SIGPIPE);
5621 sigunblock (sigmask (SIGPIPE)); 5446 sigunblock (sigmask (SIGPIPE));
@@ -5633,18 +5458,15 @@ send_process_trap ()
5633 This function can evaluate Lisp code and can garbage collect. */ 5458 This function can evaluate Lisp code and can garbage collect. */
5634 5459
5635static void 5460static void
5636send_process (proc, buf, len, object) 5461send_process (volatile Lisp_Object proc, unsigned char *volatile buf,
5637 volatile Lisp_Object proc; 5462 volatile int len, volatile Lisp_Object object)
5638 unsigned char *volatile buf;
5639 volatile int len;
5640 volatile Lisp_Object object;
5641{ 5463{
5642 /* Use volatile to protect variables from being clobbered by longjmp. */ 5464 /* Use volatile to protect variables from being clobbered by longjmp. */
5643 struct Lisp_Process *p = XPROCESS (proc); 5465 struct Lisp_Process *p = XPROCESS (proc);
5644 int rv; 5466 int rv;
5645 struct coding_system *coding; 5467 struct coding_system *coding;
5646 struct gcpro gcpro1; 5468 struct gcpro gcpro1;
5647 SIGTYPE (*volatile old_sigpipe) (); 5469 SIGTYPE (*volatile old_sigpipe) (int);
5648 5470
5649 GCPRO1 (object); 5471 GCPRO1 (object);
5650 5472
@@ -5757,7 +5579,7 @@ send_process (proc, buf, len, object)
5757 while (this > 0) 5579 while (this > 0)
5758 { 5580 {
5759 int outfd = p->outfd; 5581 int outfd = p->outfd;
5760 old_sigpipe = (SIGTYPE (*) ()) signal (SIGPIPE, send_process_trap); 5582 old_sigpipe = (SIGTYPE (*) (int)) signal (SIGPIPE, send_process_trap);
5761#ifdef DATAGRAM_SOCKETS 5583#ifdef DATAGRAM_SOCKETS
5762 if (DATAGRAM_CHAN_P (outfd)) 5584 if (DATAGRAM_CHAN_P (outfd))
5763 { 5585 {
@@ -5882,8 +5704,7 @@ Called from program, takes three arguments, PROCESS, START and END.
5882If the region is more than 500 characters long, 5704If the region is more than 500 characters long,
5883it is sent in several bunches. This may happen even for shorter regions. 5705it is sent in several bunches. This may happen even for shorter regions.
5884Output from processes can arrive in between bunches. */) 5706Output from processes can arrive in between bunches. */)
5885 (process, start, end) 5707 (Lisp_Object process, Lisp_Object start, Lisp_Object end)
5886 Lisp_Object process, start, end;
5887{ 5708{
5888 Lisp_Object proc; 5709 Lisp_Object proc;
5889 int start1, end1; 5710 int start1, end1;
@@ -5910,8 +5731,7 @@ nil, indicating the current buffer's process.
5910If STRING is more than 500 characters long, 5731If STRING is more than 500 characters long,
5911it is sent in several bunches. This may happen even for shorter strings. 5732it is sent in several bunches. This may happen even for shorter strings.
5912Output from processes can arrive in between bunches. */) 5733Output from processes can arrive in between bunches. */)
5913 (process, string) 5734 (Lisp_Object process, Lisp_Object string)
5914 Lisp_Object process, string;
5915{ 5735{
5916 Lisp_Object proc; 5736 Lisp_Object proc;
5917 CHECK_STRING (string); 5737 CHECK_STRING (string);
@@ -5924,8 +5744,7 @@ Output from processes can arrive in between bunches. */)
5924/* Return the foreground process group for the tty/pty that 5744/* Return the foreground process group for the tty/pty that
5925 the process P uses. */ 5745 the process P uses. */
5926static int 5746static int
5927emacs_get_tty_pgrp (p) 5747emacs_get_tty_pgrp (struct Lisp_Process *p)
5928 struct Lisp_Process *p;
5929{ 5748{
5930 int gid = -1; 5749 int gid = -1;
5931 5750
@@ -5953,8 +5772,7 @@ DEFUN ("process-running-child-p", Fprocess_running_child_p,
5953 doc: /* Return t if PROCESS has given the terminal to a child. 5772 doc: /* Return t if PROCESS has given the terminal to a child.
5954If the operating system does not make it possible to find out, 5773If the operating system does not make it possible to find out,
5955return t unconditionally. */) 5774return t unconditionally. */)
5956 (process) 5775 (Lisp_Object process)
5957 Lisp_Object process;
5958{ 5776{
5959 /* Initialize in case ioctl doesn't exist or gives an error, 5777 /* Initialize in case ioctl doesn't exist or gives an error,
5960 in a way that will cause returning t. */ 5778 in a way that will cause returning t. */
@@ -5994,11 +5812,8 @@ return t unconditionally. */)
5994 their uid, for which killpg would return an EPERM error. */ 5812 their uid, for which killpg would return an EPERM error. */
5995 5813
5996static void 5814static void
5997process_send_signal (process, signo, current_group, nomsg) 5815process_send_signal (Lisp_Object process, int signo, Lisp_Object current_group,
5998 Lisp_Object process; 5816 int nomsg)
5999 int signo;
6000 Lisp_Object current_group;
6001 int nomsg;
6002{ 5817{
6003 Lisp_Object proc; 5818 Lisp_Object proc;
6004 register struct Lisp_Process *p; 5819 register struct Lisp_Process *p;
@@ -6218,8 +6033,7 @@ rather than the shell.
6218 6033
6219If CURRENT-GROUP is `lambda', and if the shell owns the terminal, 6034If CURRENT-GROUP is `lambda', and if the shell owns the terminal,
6220don't send the signal. */) 6035don't send the signal. */)
6221 (process, current_group) 6036 (Lisp_Object process, Lisp_Object current_group)
6222 Lisp_Object process, current_group;
6223{ 6037{
6224 process_send_signal (process, SIGINT, current_group, 0); 6038 process_send_signal (process, SIGINT, current_group, 0);
6225 return process; 6039 return process;
@@ -6228,8 +6042,7 @@ don't send the signal. */)
6228DEFUN ("kill-process", Fkill_process, Skill_process, 0, 2, 0, 6042DEFUN ("kill-process", Fkill_process, Skill_process, 0, 2, 0,
6229 doc: /* Kill process PROCESS. May be process or name of one. 6043 doc: /* Kill process PROCESS. May be process or name of one.
6230See function `interrupt-process' for more details on usage. */) 6044See function `interrupt-process' for more details on usage. */)
6231 (process, current_group) 6045 (Lisp_Object process, Lisp_Object current_group)
6232 Lisp_Object process, current_group;
6233{ 6046{
6234 process_send_signal (process, SIGKILL, current_group, 0); 6047 process_send_signal (process, SIGKILL, current_group, 0);
6235 return process; 6048 return process;
@@ -6238,8 +6051,7 @@ See function `interrupt-process' for more details on usage. */)
6238DEFUN ("quit-process", Fquit_process, Squit_process, 0, 2, 0, 6051DEFUN ("quit-process", Fquit_process, Squit_process, 0, 2, 0,
6239 doc: /* Send QUIT signal to process PROCESS. May be process or name of one. 6052 doc: /* Send QUIT signal to process PROCESS. May be process or name of one.
6240See function `interrupt-process' for more details on usage. */) 6053See function `interrupt-process' for more details on usage. */)
6241 (process, current_group) 6054 (Lisp_Object process, Lisp_Object current_group)
6242 Lisp_Object process, current_group;
6243{ 6055{
6244 process_send_signal (process, SIGQUIT, current_group, 0); 6056 process_send_signal (process, SIGQUIT, current_group, 0);
6245 return process; 6057 return process;
@@ -6250,8 +6062,7 @@ DEFUN ("stop-process", Fstop_process, Sstop_process, 0, 2, 0,
6250See function `interrupt-process' for more details on usage. 6062See function `interrupt-process' for more details on usage.
6251If PROCESS is a network or serial process, inhibit handling of incoming 6063If PROCESS is a network or serial process, inhibit handling of incoming
6252traffic. */) 6064traffic. */)
6253 (process, current_group) 6065 (Lisp_Object process, Lisp_Object current_group)
6254 Lisp_Object process, current_group;
6255{ 6066{
6256#ifdef HAVE_SOCKETS 6067#ifdef HAVE_SOCKETS
6257 if (PROCESSP (process) && (NETCONN_P (process) || SERIALCONN_P (process))) 6068 if (PROCESSP (process) && (NETCONN_P (process) || SERIALCONN_P (process)))
@@ -6282,8 +6093,7 @@ DEFUN ("continue-process", Fcontinue_process, Scontinue_process, 0, 2, 0,
6282See function `interrupt-process' for more details on usage. 6093See function `interrupt-process' for more details on usage.
6283If PROCESS is a network or serial process, resume handling of incoming 6094If PROCESS is a network or serial process, resume handling of incoming
6284traffic. */) 6095traffic. */)
6285 (process, current_group) 6096 (Lisp_Object process, Lisp_Object current_group)
6286 Lisp_Object process, current_group;
6287{ 6097{
6288#ifdef HAVE_SOCKETS 6098#ifdef HAVE_SOCKETS
6289 if (PROCESSP (process) && (NETCONN_P (process) || SERIALCONN_P (process))) 6099 if (PROCESSP (process) && (NETCONN_P (process) || SERIALCONN_P (process)))
@@ -6324,8 +6134,7 @@ PROCESS may also be a number specifying the process id of the
6324process to signal; in this case, the process need not be a child of 6134process to signal; in this case, the process need not be a child of
6325this Emacs. 6135this Emacs.
6326SIGCODE may be an integer, or a symbol whose name is a signal name. */) 6136SIGCODE may be an integer, or a symbol whose name is a signal name. */)
6327 (process, sigcode) 6137 (Lisp_Object process, Lisp_Object sigcode)
6328 Lisp_Object process, sigcode;
6329{ 6138{
6330 pid_t pid; 6139 pid_t pid;
6331 6140
@@ -6378,7 +6187,7 @@ SIGCODE may be an integer, or a symbol whose name is a signal name. */)
6378 CHECK_SYMBOL (sigcode); 6187 CHECK_SYMBOL (sigcode);
6379 name = SDATA (SYMBOL_NAME (sigcode)); 6188 name = SDATA (SYMBOL_NAME (sigcode));
6380 6189
6381 if (!strncmp(name, "SIG", 3) || !strncmp(name, "sig", 3)) 6190 if (!strncmp (name, "SIG", 3) || !strncmp (name, "sig", 3))
6382 name += 3; 6191 name += 3;
6383 6192
6384 if (0) 6193 if (0)
@@ -6492,8 +6301,7 @@ through a pipe (as opposed to a pty), then you cannot send any more
6492text to PROCESS after you call this function. 6301text to PROCESS after you call this function.
6493If PROCESS is a serial process, wait until all output written to the 6302If PROCESS is a serial process, wait until all output written to the
6494process has been transmitted to the serial port. */) 6303process has been transmitted to the serial port. */)
6495 (process) 6304 (Lisp_Object process)
6496 Lisp_Object process;
6497{ 6305{
6498 Lisp_Object proc; 6306 Lisp_Object proc;
6499 struct coding_system *coding; 6307 struct coding_system *coding;
@@ -6552,39 +6360,16 @@ process has been transmitted to the serial port. */)
6552 if (!proc_encode_coding_system[new_outfd]) 6360 if (!proc_encode_coding_system[new_outfd])
6553 proc_encode_coding_system[new_outfd] 6361 proc_encode_coding_system[new_outfd]
6554 = (struct coding_system *) xmalloc (sizeof (struct coding_system)); 6362 = (struct coding_system *) xmalloc (sizeof (struct coding_system));
6555 bcopy (proc_encode_coding_system[old_outfd], 6363 memcpy (proc_encode_coding_system[new_outfd],
6556 proc_encode_coding_system[new_outfd], 6364 proc_encode_coding_system[old_outfd],
6557 sizeof (struct coding_system)); 6365 sizeof (struct coding_system));
6558 bzero (proc_encode_coding_system[old_outfd], 6366 memset (proc_encode_coding_system[old_outfd], 0,
6559 sizeof (struct coding_system)); 6367 sizeof (struct coding_system));
6560 6368
6561 XPROCESS (proc)->outfd = new_outfd; 6369 XPROCESS (proc)->outfd = new_outfd;
6562 } 6370 }
6563 return process; 6371 return process;
6564} 6372}
6565
6566/* Kill all processes associated with `buffer'.
6567 If `buffer' is nil, kill all processes */
6568
6569void
6570kill_buffer_processes (buffer)
6571 Lisp_Object buffer;
6572{
6573 Lisp_Object tail, proc;
6574
6575 for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail))
6576 {
6577 proc = XCDR (XCAR (tail));
6578 if (PROCESSP (proc)
6579 && (NILP (buffer) || EQ (XPROCESS (proc)->buffer, buffer)))
6580 {
6581 if (NETCONN_P (proc) || SERIALCONN_P (proc))
6582 Fdelete_process (proc);
6583 else if (XPROCESS (proc)->infd >= 0)
6584 process_send_signal (proc, SIGHUP, Qnil, 1);
6585 }
6586 }
6587}
6588 6373
6589/* On receipt of a signal that a child status has changed, loop asking 6374/* On receipt of a signal that a child status has changed, loop asking
6590 about children with changed statuses until the system says there 6375 about children with changed statuses until the system says there
@@ -6613,8 +6398,7 @@ kill_buffer_processes (buffer)
6613 6398
6614#ifdef SIGCHLD 6399#ifdef SIGCHLD
6615SIGTYPE 6400SIGTYPE
6616sigchld_handler (signo) 6401sigchld_handler (int signo)
6617 int signo;
6618{ 6402{
6619 int old_errno = errno; 6403 int old_errno = errno;
6620 Lisp_Object proc; 6404 Lisp_Object proc;
@@ -6755,16 +6539,14 @@ sigchld_handler (signo)
6755 6539
6756 6540
6757static Lisp_Object 6541static Lisp_Object
6758exec_sentinel_unwind (data) 6542exec_sentinel_unwind (Lisp_Object data)
6759 Lisp_Object data;
6760{ 6543{
6761 XPROCESS (XCAR (data))->sentinel = XCDR (data); 6544 XPROCESS (XCAR (data))->sentinel = XCDR (data);
6762 return Qnil; 6545 return Qnil;
6763} 6546}
6764 6547
6765static Lisp_Object 6548static Lisp_Object
6766exec_sentinel_error_handler (error) 6549exec_sentinel_error_handler (Lisp_Object error)
6767 Lisp_Object error;
6768{ 6550{
6769 cmd_error_internal (error, "error in process sentinel: "); 6551 cmd_error_internal (error, "error in process sentinel: ");
6770 Vinhibit_quit = Qt; 6552 Vinhibit_quit = Qt;
@@ -6774,8 +6556,7 @@ exec_sentinel_error_handler (error)
6774} 6556}
6775 6557
6776static void 6558static void
6777exec_sentinel (proc, reason) 6559exec_sentinel (Lisp_Object proc, Lisp_Object reason)
6778 Lisp_Object proc, reason;
6779{ 6560{
6780 Lisp_Object sentinel, obuffer, odeactivate, okeymap; 6561 Lisp_Object sentinel, obuffer, odeactivate, okeymap;
6781 register struct Lisp_Process *p = XPROCESS (proc); 6562 register struct Lisp_Process *p = XPROCESS (proc);
@@ -6860,8 +6641,7 @@ exec_sentinel (proc, reason)
6860 but can be done at other times. */ 6641 but can be done at other times. */
6861 6642
6862static void 6643static void
6863status_notify (deleting_process) 6644status_notify (struct Lisp_Process *deleting_process)
6864 struct Lisp_Process *deleting_process;
6865{ 6645{
6866 register Lisp_Object proc, buffer; 6646 register Lisp_Object proc, buffer;
6867 Lisp_Object tail, msg; 6647 Lisp_Object tail, msg;
@@ -6988,8 +6768,7 @@ DEFUN ("set-process-coding-system", Fset_process_coding_system,
6988 doc: /* Set coding systems of PROCESS to DECODING and ENCODING. 6768 doc: /* Set coding systems of PROCESS to DECODING and ENCODING.
6989DECODING will be used to decode subprocess output and ENCODING to 6769DECODING will be used to decode subprocess output and ENCODING to
6990encode subprocess input. */) 6770encode subprocess input. */)
6991 (process, decoding, encoding) 6771 (register Lisp_Object process, Lisp_Object decoding, Lisp_Object encoding)
6992 register Lisp_Object process, decoding, encoding;
6993{ 6772{
6994 register struct Lisp_Process *p; 6773 register struct Lisp_Process *p;
6995 6774
@@ -7012,8 +6791,7 @@ encode subprocess input. */)
7012DEFUN ("process-coding-system", 6791DEFUN ("process-coding-system",
7013 Fprocess_coding_system, Sprocess_coding_system, 1, 1, 0, 6792 Fprocess_coding_system, Sprocess_coding_system, 1, 1, 0,
7014 doc: /* Return a cons of coding systems for decoding and encoding of PROCESS. */) 6793 doc: /* Return a cons of coding systems for decoding and encoding of PROCESS. */)
7015 (process) 6794 (register Lisp_Object process)
7016 register Lisp_Object process;
7017{ 6795{
7018 CHECK_PROCESS (process); 6796 CHECK_PROCESS (process);
7019 return Fcons (XPROCESS (process)->decode_coding_system, 6797 return Fcons (XPROCESS (process)->decode_coding_system,
@@ -7027,8 +6805,7 @@ If FLAG is non-nil, the filter is given multibyte strings.
7027If FLAG is nil, the filter is given unibyte strings. In this case, 6805If FLAG is nil, the filter is given unibyte strings. In this case,
7028all character code conversion except for end-of-line conversion is 6806all character code conversion except for end-of-line conversion is
7029suppressed. */) 6807suppressed. */)
7030 (process, flag) 6808 (Lisp_Object process, Lisp_Object flag)
7031 Lisp_Object process, flag;
7032{ 6809{
7033 register struct Lisp_Process *p; 6810 register struct Lisp_Process *p;
7034 6811
@@ -7044,8 +6821,7 @@ suppressed. */)
7044DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p, 6821DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p,
7045 Sprocess_filter_multibyte_p, 1, 1, 0, 6822 Sprocess_filter_multibyte_p, 1, 1, 0,
7046 doc: /* Return t if a multibyte string is given to PROCESS's filter.*/) 6823 doc: /* Return t if a multibyte string is given to PROCESS's filter.*/)
7047 (process) 6824 (Lisp_Object process)
7048 Lisp_Object process;
7049{ 6825{
7050 register struct Lisp_Process *p; 6826 register struct Lisp_Process *p;
7051 struct coding_system *coding; 6827 struct coding_system *coding;
@@ -7058,23 +6834,11 @@ DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p,
7058 6834
7059 6835
7060 6836
7061/* Add DESC to the set of keyboard input descriptors. */
7062
7063void
7064add_keyboard_wait_descriptor (desc)
7065 int desc;
7066{
7067 FD_SET (desc, &input_wait_mask);
7068 FD_SET (desc, &non_process_wait_mask);
7069 if (desc > max_keyboard_desc)
7070 max_keyboard_desc = desc;
7071}
7072 6837
7073static int add_gpm_wait_descriptor_called_flag; 6838static int add_gpm_wait_descriptor_called_flag;
7074 6839
7075void 6840void
7076add_gpm_wait_descriptor (desc) 6841add_gpm_wait_descriptor (int desc)
7077 int desc;
7078{ 6842{
7079 if (! add_gpm_wait_descriptor_called_flag) 6843 if (! add_gpm_wait_descriptor_called_flag)
7080 FD_CLR (0, &input_wait_mask); 6844 FD_CLR (0, &input_wait_mask);
@@ -7085,29 +6849,8 @@ add_gpm_wait_descriptor (desc)
7085 max_gpm_desc = desc; 6849 max_gpm_desc = desc;
7086} 6850}
7087 6851
7088/* From now on, do not expect DESC to give keyboard input. */
7089
7090void 6852void
7091delete_keyboard_wait_descriptor (desc) 6853delete_gpm_wait_descriptor (int desc)
7092 int desc;
7093{
7094 int fd;
7095 int lim = max_keyboard_desc;
7096
7097 FD_CLR (desc, &input_wait_mask);
7098 FD_CLR (desc, &non_process_wait_mask);
7099
7100 if (desc == max_keyboard_desc)
7101 for (fd = 0; fd < lim; fd++)
7102 if (FD_ISSET (fd, &input_wait_mask)
7103 && !FD_ISSET (fd, &non_keyboard_wait_mask)
7104 && !FD_ISSET (fd, &gpm_wait_mask))
7105 max_keyboard_desc = fd;
7106}
7107
7108void
7109delete_gpm_wait_descriptor (desc)
7110 int desc;
7111{ 6854{
7112 int fd; 6855 int fd;
7113 int lim = max_gpm_desc; 6856 int lim = max_gpm_desc;
@@ -7127,8 +6870,7 @@ delete_gpm_wait_descriptor (desc)
7127 that corresponds to one of the keyboard input descriptors. */ 6870 that corresponds to one of the keyboard input descriptors. */
7128 6871
7129static int 6872static int
7130keyboard_bit_set (mask) 6873keyboard_bit_set (fd_set *mask)
7131 SELECT_TYPE *mask;
7132{ 6874{
7133 int fd; 6875 int fd;
7134 6876
@@ -7139,6 +6881,432 @@ keyboard_bit_set (mask)
7139 6881
7140 return 0; 6882 return 0;
7141} 6883}
6884
6885#else /* not subprocesses */
6886
6887/* Defined on msdos.c. */
6888extern int sys_select (int, SELECT_TYPE *, SELECT_TYPE *, SELECT_TYPE *,
6889 EMACS_TIME *);
6890
6891/* Implementation of wait_reading_process_output, assuming that there
6892 are no subprocesses. Used only by the MS-DOS build.
6893
6894 Wait for timeout to elapse and/or keyboard input to be available.
6895
6896 time_limit is:
6897 timeout in seconds, or
6898 zero for no limit, or
6899 -1 means gobble data immediately available but don't wait for any.
6900
6901 read_kbd is a Lisp_Object:
6902 0 to ignore keyboard input, or
6903 1 to return when input is available, or
6904 -1 means caller will actually read the input, so don't throw to
6905 the quit handler.
6906
6907 see full version for other parameters. We know that wait_proc will
6908 always be NULL, since `subprocesses' isn't defined.
6909
6910 do_display != 0 means redisplay should be done to show subprocess
6911 output that arrives.
6912
6913 Return true if we received input from any process. */
6914
6915int
6916wait_reading_process_output (int time_limit, int microsecs, int read_kbd,
6917 int do_display,
6918 Lisp_Object wait_for_cell,
6919 struct Lisp_Process *wait_proc, int just_wait_proc)
6920{
6921 register int nfds;
6922 EMACS_TIME end_time, timeout;
6923 SELECT_TYPE waitchannels;
6924 int xerrno;
6925
6926 /* What does time_limit really mean? */
6927 if (time_limit || microsecs)
6928 {
6929 EMACS_GET_TIME (end_time);
6930 EMACS_SET_SECS_USECS (timeout, time_limit, microsecs);
6931 EMACS_ADD_TIME (end_time, end_time, timeout);
6932 }
6933
6934 /* Turn off periodic alarms (in case they are in use)
6935 and then turn off any other atimers,
6936 because the select emulator uses alarms. */
6937 stop_polling ();
6938 turn_on_atimers (0);
6939
6940 while (1)
6941 {
6942 int timeout_reduced_for_timers = 0;
6943
6944 /* If calling from keyboard input, do not quit
6945 since we want to return C-g as an input character.
6946 Otherwise, do pending quit if requested. */
6947 if (read_kbd >= 0)
6948 QUIT;
6949
6950 /* Exit now if the cell we're waiting for became non-nil. */
6951 if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell)))
6952 break;
6953
6954 /* Compute time from now till when time limit is up */
6955 /* Exit if already run out */
6956 if (time_limit == -1)
6957 {
6958 /* -1 specified for timeout means
6959 gobble output available now
6960 but don't wait at all. */
6961
6962 EMACS_SET_SECS_USECS (timeout, 0, 0);
6963 }
6964 else if (time_limit || microsecs)
6965 {
6966 EMACS_GET_TIME (timeout);
6967 EMACS_SUB_TIME (timeout, end_time, timeout);
6968 if (EMACS_TIME_NEG_P (timeout))
6969 break;
6970 }
6971 else
6972 {
6973 EMACS_SET_SECS_USECS (timeout, 100000, 0);
6974 }
6975
6976 /* If our caller will not immediately handle keyboard events,
6977 run timer events directly.
6978 (Callers that will immediately read keyboard events
6979 call timer_delay on their own.) */
6980 if (NILP (wait_for_cell))
6981 {
6982 EMACS_TIME timer_delay;
6983
6984 do
6985 {
6986 int old_timers_run = timers_run;
6987 timer_delay = timer_check (1);
6988 if (timers_run != old_timers_run && do_display)
6989 /* We must retry, since a timer may have requeued itself
6990 and that could alter the time delay. */
6991 redisplay_preserve_echo_area (14);
6992 else
6993 break;
6994 }
6995 while (!detect_input_pending ());
6996
6997 /* If there is unread keyboard input, also return. */
6998 if (read_kbd != 0
6999 && requeued_events_pending_p ())
7000 break;
7001
7002 if (! EMACS_TIME_NEG_P (timer_delay) && time_limit != -1)
7003 {
7004 EMACS_TIME difference;
7005 EMACS_SUB_TIME (difference, timer_delay, timeout);
7006 if (EMACS_TIME_NEG_P (difference))
7007 {
7008 timeout = timer_delay;
7009 timeout_reduced_for_timers = 1;
7010 }
7011 }
7012 }
7013
7014 /* Cause C-g and alarm signals to take immediate action,
7015 and cause input available signals to zero out timeout. */
7016 if (read_kbd < 0)
7017 set_waiting_for_input (&timeout);
7018
7019 /* Wait till there is something to do. */
7020
7021 if (! read_kbd && NILP (wait_for_cell))
7022 FD_ZERO (&waitchannels);
7023 else
7024 FD_SET (0, &waitchannels);
7025
7026 /* If a frame has been newly mapped and needs updating,
7027 reprocess its display stuff. */
7028 if (frame_garbaged && do_display)
7029 {
7030 clear_waiting_for_input ();
7031 redisplay_preserve_echo_area (15);
7032 if (read_kbd < 0)
7033 set_waiting_for_input (&timeout);
7034 }
7035
7036 if (read_kbd && detect_input_pending ())
7037 {
7038 nfds = 0;
7039 FD_ZERO (&waitchannels);
7040 }
7041 else
7042 nfds = select (1, &waitchannels, (SELECT_TYPE *)0, (SELECT_TYPE *)0,
7043 &timeout);
7044
7045 xerrno = errno;
7046
7047 /* Make C-g and alarm signals set flags again */
7048 clear_waiting_for_input ();
7049
7050 /* If we woke up due to SIGWINCH, actually change size now. */
7051 do_pending_window_change (0);
7052
7053 if (time_limit && nfds == 0 && ! timeout_reduced_for_timers)
7054 /* We waited the full specified time, so return now. */
7055 break;
7056
7057 if (nfds == -1)
7058 {
7059 /* If the system call was interrupted, then go around the
7060 loop again. */
7061 if (xerrno == EINTR)
7062 FD_ZERO (&waitchannels);
7063 else
7064 error ("select error: %s", emacs_strerror (xerrno));
7065 }
7066
7067 /* Check for keyboard input */
7068
7069 if (read_kbd
7070 && detect_input_pending_run_timers (do_display))
7071 {
7072 swallow_events (do_display);
7073 if (detect_input_pending_run_timers (do_display))
7074 break;
7075 }
7076
7077 /* If there is unread keyboard input, also return. */
7078 if (read_kbd
7079 && requeued_events_pending_p ())
7080 break;
7081
7082 /* If wait_for_cell. check for keyboard input
7083 but don't run any timers.
7084 ??? (It seems wrong to me to check for keyboard
7085 input at all when wait_for_cell, but the code
7086 has been this way since July 1994.
7087 Try changing this after version 19.31.) */
7088 if (! NILP (wait_for_cell)
7089 && detect_input_pending ())
7090 {
7091 swallow_events (do_display);
7092 if (detect_input_pending ())
7093 break;
7094 }
7095
7096 /* Exit now if the cell we're waiting for became non-nil. */
7097 if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell)))
7098 break;
7099 }
7100
7101 start_polling ();
7102
7103 return 0;
7104}
7105
7106#endif /* not subprocesses */
7107
7108/* The following functions are needed even if async subprocesses are
7109 not supported. Some of them are no-op stubs in that case. */
7110
7111/* Add DESC to the set of keyboard input descriptors. */
7112
7113void
7114add_keyboard_wait_descriptor (int desc)
7115{
7116#ifdef subprocesses
7117 FD_SET (desc, &input_wait_mask);
7118 FD_SET (desc, &non_process_wait_mask);
7119 if (desc > max_keyboard_desc)
7120 max_keyboard_desc = desc;
7121#endif
7122}
7123
7124/* From now on, do not expect DESC to give keyboard input. */
7125
7126void
7127delete_keyboard_wait_descriptor (int desc)
7128{
7129#ifdef subprocesses
7130 int fd;
7131 int lim = max_keyboard_desc;
7132
7133 FD_CLR (desc, &input_wait_mask);
7134 FD_CLR (desc, &non_process_wait_mask);
7135
7136 if (desc == max_keyboard_desc)
7137 for (fd = 0; fd < lim; fd++)
7138 if (FD_ISSET (fd, &input_wait_mask)
7139 && !FD_ISSET (fd, &non_keyboard_wait_mask)
7140 && !FD_ISSET (fd, &gpm_wait_mask))
7141 max_keyboard_desc = fd;
7142#endif /* subprocesses */
7143}
7144
7145/* Setup coding systems of PROCESS. */
7146
7147void
7148setup_process_coding_systems (Lisp_Object process)
7149{
7150#ifdef subprocesses
7151 struct Lisp_Process *p = XPROCESS (process);
7152 int inch = p->infd;
7153 int outch = p->outfd;
7154 Lisp_Object coding_system;
7155
7156 if (inch < 0 || outch < 0)
7157 return;
7158
7159 if (!proc_decode_coding_system[inch])
7160 proc_decode_coding_system[inch]
7161 = (struct coding_system *) xmalloc (sizeof (struct coding_system));
7162 coding_system = p->decode_coding_system;
7163 if (! NILP (p->filter))
7164 ;
7165 else if (BUFFERP (p->buffer))
7166 {
7167 if (NILP (XBUFFER (p->buffer)->enable_multibyte_characters))
7168 coding_system = raw_text_coding_system (coding_system);
7169 }
7170 setup_coding_system (coding_system, proc_decode_coding_system[inch]);
7171
7172 if (!proc_encode_coding_system[outch])
7173 proc_encode_coding_system[outch]
7174 = (struct coding_system *) xmalloc (sizeof (struct coding_system));
7175 setup_coding_system (p->encode_coding_system,
7176 proc_encode_coding_system[outch]);
7177#endif
7178}
7179
7180/* Close all descriptors currently in use for communication
7181 with subprocess. This is used in a newly-forked subprocess
7182 to get rid of irrelevant descriptors. */
7183
7184void
7185close_process_descs (void)
7186{
7187#ifndef DOS_NT
7188 int i;
7189 for (i = 0; i < MAXDESC; i++)
7190 {
7191 Lisp_Object process;
7192 process = chan_process[i];
7193 if (!NILP (process))
7194 {
7195 int in = XPROCESS (process)->infd;
7196 int out = XPROCESS (process)->outfd;
7197 if (in >= 0)
7198 emacs_close (in);
7199 if (out >= 0 && in != out)
7200 emacs_close (out);
7201 }
7202 }
7203#endif
7204}
7205
7206DEFUN ("get-buffer-process", Fget_buffer_process, Sget_buffer_process, 1, 1, 0,
7207 doc: /* Return the (or a) process associated with BUFFER.
7208BUFFER may be a buffer or the name of one. */)
7209 (register Lisp_Object buffer)
7210{
7211#ifdef subprocesses
7212 register Lisp_Object buf, tail, proc;
7213
7214 if (NILP (buffer)) return Qnil;
7215 buf = Fget_buffer (buffer);
7216 if (NILP (buf)) return Qnil;
7217
7218 for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail))
7219 {
7220 proc = Fcdr (XCAR (tail));
7221 if (PROCESSP (proc) && EQ (XPROCESS (proc)->buffer, buf))
7222 return proc;
7223 }
7224#endif /* subprocesses */
7225 return Qnil;
7226}
7227
7228DEFUN ("process-inherit-coding-system-flag",
7229 Fprocess_inherit_coding_system_flag, Sprocess_inherit_coding_system_flag,
7230 1, 1, 0,
7231 doc: /* Return the value of inherit-coding-system flag for PROCESS.
7232If this flag is t, `buffer-file-coding-system' of the buffer
7233associated with PROCESS will inherit the coding system used to decode
7234the process output. */)
7235 (register Lisp_Object process)
7236{
7237#ifdef subprocesses
7238 CHECK_PROCESS (process);
7239 return XPROCESS (process)->inherit_coding_system_flag ? Qt : Qnil;
7240#else
7241 /* Ignore the argument and return the value of
7242 inherit-process-coding-system. */
7243 return inherit_process_coding_system ? Qt : Qnil;
7244#endif
7245}
7246
7247/* Kill all processes associated with `buffer'.
7248 If `buffer' is nil, kill all processes */
7249
7250void
7251kill_buffer_processes (Lisp_Object buffer)
7252{
7253#ifdef subprocesses
7254 Lisp_Object tail, proc;
7255
7256 for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail))
7257 {
7258 proc = XCDR (XCAR (tail));
7259 if (PROCESSP (proc)
7260 && (NILP (buffer) || EQ (XPROCESS (proc)->buffer, buffer)))
7261 {
7262 if (NETCONN_P (proc) || SERIALCONN_P (proc))
7263 Fdelete_process (proc);
7264 else if (XPROCESS (proc)->infd >= 0)
7265 process_send_signal (proc, SIGHUP, Qnil, 1);
7266 }
7267 }
7268#else /* subprocesses */
7269 /* Since we have no subprocesses, this does nothing. */
7270#endif /* subprocesses */
7271}
7272
7273DEFUN ("waiting-for-user-input-p", Fwaiting_for_user_input_p, Swaiting_for_user_input_p,
7274 0, 0, 0,
7275 doc: /* Returns non-nil if Emacs is waiting for input from the user.
7276This is intended for use by asynchronous process output filters and sentinels. */)
7277 (void)
7278{
7279#ifdef subprocesses
7280 return (waiting_for_user_input_p ? Qt : Qnil);
7281#else
7282 return Qnil;
7283#endif
7284}
7285
7286/* Stop reading input from keyboard sources. */
7287
7288void
7289hold_keyboard_input (void)
7290{
7291 kbd_is_on_hold = 1;
7292}
7293
7294/* Resume reading input from keyboard sources. */
7295
7296void
7297unhold_keyboard_input (void)
7298{
7299 kbd_is_on_hold = 0;
7300}
7301
7302/* Return non-zero if keyboard input is on hold, zero otherwise. */
7303
7304int
7305kbd_on_hold_p (void)
7306{
7307 return kbd_is_on_hold;
7308}
7309
7142 7310
7143/* Enumeration of and access to system processes a-la ps(1). */ 7311/* Enumeration of and access to system processes a-la ps(1). */
7144 7312
@@ -7148,7 +7316,7 @@ DEFUN ("list-system-processes", Flist_system_processes, Slist_system_processes,
7148If this functionality is unsupported, return nil. 7316If this functionality is unsupported, return nil.
7149 7317
7150See `process-attributes' for getting attributes of a process given its ID. */) 7318See `process-attributes' for getting attributes of a process given its ID. */)
7151 () 7319 (void)
7152{ 7320{
7153 return list_system_processes (); 7321 return list_system_processes ();
7154} 7322}
@@ -7204,16 +7372,16 @@ integer or floating point values.
7204 pmem -- percents of total physical memory used by process's resident set 7372 pmem -- percents of total physical memory used by process's resident set
7205 (floating-point number) 7373 (floating-point number)
7206 args -- command line which invoked the process (string). */) 7374 args -- command line which invoked the process (string). */)
7207 (pid) 7375 ( Lisp_Object pid)
7208
7209 Lisp_Object pid;
7210{ 7376{
7211 return system_process_attributes (pid); 7377 return system_process_attributes (pid);
7212} 7378}
7379
7213 7380
7214void 7381void
7215init_process () 7382init_process (void)
7216{ 7383{
7384#ifdef subprocesses
7217 register int i; 7385 register int i;
7218 7386
7219 inhibit_sentinels = 0; 7387 inhibit_sentinels = 0;
@@ -7256,10 +7424,10 @@ init_process ()
7256 chan_process[i] = Qnil; 7424 chan_process[i] = Qnil;
7257 proc_buffered_char[i] = -1; 7425 proc_buffered_char[i] = -1;
7258 } 7426 }
7259 bzero (proc_decode_coding_system, sizeof proc_decode_coding_system); 7427 memset (proc_decode_coding_system, 0, sizeof proc_decode_coding_system);
7260 bzero (proc_encode_coding_system, sizeof proc_encode_coding_system); 7428 memset (proc_encode_coding_system, 0, sizeof proc_encode_coding_system);
7261#ifdef DATAGRAM_SOCKETS 7429#ifdef DATAGRAM_SOCKETS
7262 bzero (datagram_address, sizeof datagram_address); 7430 memset (datagram_address, 0, sizeof datagram_address);
7263#endif 7431#endif
7264 7432
7265#ifdef HAVE_SOCKETS 7433#ifdef HAVE_SOCKETS
@@ -7305,18 +7473,22 @@ init_process ()
7305 processes. As such, we only change the default value. */ 7473 processes. As such, we only change the default value. */
7306 if (initialized) 7474 if (initialized)
7307 { 7475 {
7308 char *release = get_operating_system_release(); 7476 char *release = get_operating_system_release ();
7309 if (!release || !release[0] || (release[0] < MIN_PTY_KERNEL_VERSION 7477 if (!release || !release[0] || (release[0] < MIN_PTY_KERNEL_VERSION
7310 && release[1] == '.')) { 7478 && release[1] == '.')) {
7311 Vprocess_connection_type = Qnil; 7479 Vprocess_connection_type = Qnil;
7312 } 7480 }
7313 } 7481 }
7314#endif 7482#endif
7483#endif /* subprocesses */
7484 kbd_is_on_hold = 0;
7315} 7485}
7316 7486
7317void 7487void
7318syms_of_process () 7488syms_of_process (void)
7319{ 7489{
7490#ifdef subprocesses
7491
7320 Qprocessp = intern_c_string ("processp"); 7492 Qprocessp = intern_c_string ("processp");
7321 staticpro (&Qprocessp); 7493 staticpro (&Qprocessp);
7322 Qrun = intern_c_string ("run"); 7494 Qrun = intern_c_string ("run");
@@ -7387,17 +7559,12 @@ syms_of_process ()
7387 staticpro (&Qnetwork); 7559 staticpro (&Qnetwork);
7388 Qserial = intern_c_string ("serial"); 7560 Qserial = intern_c_string ("serial");
7389 staticpro (&Qserial); 7561 staticpro (&Qserial);
7390
7391 QCname = intern_c_string (":name");
7392 staticpro (&QCname);
7393 QCbuffer = intern_c_string (":buffer"); 7562 QCbuffer = intern_c_string (":buffer");
7394 staticpro (&QCbuffer); 7563 staticpro (&QCbuffer);
7395 QChost = intern_c_string (":host"); 7564 QChost = intern_c_string (":host");
7396 staticpro (&QChost); 7565 staticpro (&QChost);
7397 QCservice = intern_c_string (":service"); 7566 QCservice = intern_c_string (":service");
7398 staticpro (&QCservice); 7567 staticpro (&QCservice);
7399 QCtype = intern_c_string (":type");
7400 staticpro (&QCtype);
7401 QClocal = intern_c_string (":local"); 7568 QClocal = intern_c_string (":local");
7402 staticpro (&QClocal); 7569 staticpro (&QClocal);
7403 QCremote = intern_c_string (":remote"); 7570 QCremote = intern_c_string (":remote");
@@ -7429,6 +7596,13 @@ syms_of_process ()
7429 staticpro (&deleted_pid_list); 7596 staticpro (&deleted_pid_list);
7430#endif 7597#endif
7431 7598
7599#endif /* subprocesses */
7600
7601 QCname = intern_c_string (":name");
7602 staticpro (&QCname);
7603 QCtype = intern_c_string (":type");
7604 staticpro (&QCtype);
7605
7432 Qeuid = intern_c_string ("euid"); 7606 Qeuid = intern_c_string ("euid");
7433 staticpro (&Qeuid); 7607 staticpro (&Qeuid);
7434 Qegid = intern_c_string ("egid"); 7608 Qegid = intern_c_string ("egid");
@@ -7498,6 +7672,7 @@ A value of nil means don't delete them until `list-processes' is run. */);
7498 7672
7499 delete_exited_processes = 1; 7673 delete_exited_processes = 1;
7500 7674
7675#ifdef subprocesses
7501 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type, 7676 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type,
7502 doc: /* Control type of device used to communicate with subprocesses. 7677 doc: /* Control type of device used to communicate with subprocesses.
7503Values are nil to use a pipe, or t or `pty' to use a pty. 7678Values are nil to use a pipe, or t or `pty' to use a pty.
@@ -7522,7 +7697,6 @@ The variable takes effect when `start-process' is called. */);
7522 7697
7523 defsubr (&Sprocessp); 7698 defsubr (&Sprocessp);
7524 defsubr (&Sget_process); 7699 defsubr (&Sget_process);
7525 defsubr (&Sget_buffer_process);
7526 defsubr (&Sdelete_process); 7700 defsubr (&Sdelete_process);
7527 defsubr (&Sprocess_status); 7701 defsubr (&Sprocess_status);
7528 defsubr (&Sprocess_exit_status); 7702 defsubr (&Sprocess_exit_status);
@@ -7539,7 +7713,6 @@ The variable takes effect when `start-process' is called. */);
7539 defsubr (&Sprocess_sentinel); 7713 defsubr (&Sprocess_sentinel);
7540 defsubr (&Sset_process_window_size); 7714 defsubr (&Sset_process_window_size);
7541 defsubr (&Sset_process_inherit_coding_system_flag); 7715 defsubr (&Sset_process_inherit_coding_system_flag);
7542 defsubr (&Sprocess_inherit_coding_system_flag);
7543 defsubr (&Sset_process_query_on_exit_flag); 7716 defsubr (&Sset_process_query_on_exit_flag);
7544 defsubr (&Sprocess_query_on_exit_flag); 7717 defsubr (&Sprocess_query_on_exit_flag);
7545 defsubr (&Sprocess_contact); 7718 defsubr (&Sprocess_contact);
@@ -7586,449 +7759,8 @@ The variable takes effect when `start-process' is called. */);
7586 defsubr (&Sprocess_coding_system); 7759 defsubr (&Sprocess_coding_system);
7587 defsubr (&Sset_process_filter_multibyte); 7760 defsubr (&Sset_process_filter_multibyte);
7588 defsubr (&Sprocess_filter_multibyte_p); 7761 defsubr (&Sprocess_filter_multibyte_p);
7589 defsubr (&Slist_system_processes);
7590 defsubr (&Sprocess_attributes);
7591}
7592
7593
7594#else /* not subprocesses */
7595
7596#include <sys/types.h>
7597#include <errno.h>
7598#include <sys/stat.h>
7599#include <stdlib.h>
7600#include <fcntl.h>
7601#include <setjmp.h>
7602#ifdef HAVE_UNISTD_H
7603#include <unistd.h>
7604#endif
7605
7606#include "lisp.h"
7607#include "systime.h"
7608#include "character.h"
7609#include "coding.h"
7610#include "termopts.h"
7611#include "sysselect.h"
7612
7613extern int frame_garbaged;
7614
7615extern EMACS_TIME timer_check ();
7616extern int timers_run;
7617
7618Lisp_Object QCtype, QCname;
7619
7620Lisp_Object Qeuid, Qegid, Qcomm, Qstate, Qppid, Qpgrp, Qsess, Qttname, Qtpgid;
7621Lisp_Object Qminflt, Qmajflt, Qcminflt, Qcmajflt, Qutime, Qstime, Qcstime;
7622Lisp_Object Qcutime, Qpri, Qnice, Qthcount, Qstart, Qvsize, Qrss, Qargs;
7623Lisp_Object Quser, Qgroup, Qetime, Qpcpu, Qpmem, Qtime, Qctime;
7624
7625/* As described above, except assuming that there are no subprocesses:
7626
7627 Wait for timeout to elapse and/or keyboard input to be available.
7628
7629 time_limit is:
7630 timeout in seconds, or
7631 zero for no limit, or
7632 -1 means gobble data immediately available but don't wait for any.
7633
7634 read_kbd is a Lisp_Object:
7635 0 to ignore keyboard input, or
7636 1 to return when input is available, or
7637 -1 means caller will actually read the input, so don't throw to
7638 the quit handler.
7639
7640 see full version for other parameters. We know that wait_proc will
7641 always be NULL, since `subprocesses' isn't defined.
7642
7643 do_display != 0 means redisplay should be done to show subprocess
7644 output that arrives.
7645
7646 Return true if we received input from any process. */
7647
7648int
7649wait_reading_process_output (time_limit, microsecs, read_kbd, do_display,
7650 wait_for_cell, wait_proc, just_wait_proc)
7651 int time_limit, microsecs, read_kbd, do_display;
7652 Lisp_Object wait_for_cell;
7653 struct Lisp_Process *wait_proc;
7654 int just_wait_proc;
7655{
7656 register int nfds;
7657 EMACS_TIME end_time, timeout;
7658 SELECT_TYPE waitchannels;
7659 int xerrno;
7660
7661 /* What does time_limit really mean? */
7662 if (time_limit || microsecs)
7663 {
7664 EMACS_GET_TIME (end_time);
7665 EMACS_SET_SECS_USECS (timeout, time_limit, microsecs);
7666 EMACS_ADD_TIME (end_time, end_time, timeout);
7667 }
7668
7669 /* Turn off periodic alarms (in case they are in use)
7670 and then turn off any other atimers,
7671 because the select emulator uses alarms. */
7672 stop_polling ();
7673 turn_on_atimers (0);
7674
7675 while (1)
7676 {
7677 int timeout_reduced_for_timers = 0;
7678
7679 /* If calling from keyboard input, do not quit
7680 since we want to return C-g as an input character.
7681 Otherwise, do pending quit if requested. */
7682 if (read_kbd >= 0)
7683 QUIT;
7684 7762
7685 /* Exit now if the cell we're waiting for became non-nil. */ 7763#endif /* subprocesses */
7686 if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell)))
7687 break;
7688
7689 /* Compute time from now till when time limit is up */
7690 /* Exit if already run out */
7691 if (time_limit == -1)
7692 {
7693 /* -1 specified for timeout means
7694 gobble output available now
7695 but don't wait at all. */
7696
7697 EMACS_SET_SECS_USECS (timeout, 0, 0);
7698 }
7699 else if (time_limit || microsecs)
7700 {
7701 EMACS_GET_TIME (timeout);
7702 EMACS_SUB_TIME (timeout, end_time, timeout);
7703 if (EMACS_TIME_NEG_P (timeout))
7704 break;
7705 }
7706 else
7707 {
7708 EMACS_SET_SECS_USECS (timeout, 100000, 0);
7709 }
7710
7711 /* If our caller will not immediately handle keyboard events,
7712 run timer events directly.
7713 (Callers that will immediately read keyboard events
7714 call timer_delay on their own.) */
7715 if (NILP (wait_for_cell))
7716 {
7717 EMACS_TIME timer_delay;
7718
7719 do
7720 {
7721 int old_timers_run = timers_run;
7722 timer_delay = timer_check (1);
7723 if (timers_run != old_timers_run && do_display)
7724 /* We must retry, since a timer may have requeued itself
7725 and that could alter the time delay. */
7726 redisplay_preserve_echo_area (14);
7727 else
7728 break;
7729 }
7730 while (!detect_input_pending ());
7731
7732 /* If there is unread keyboard input, also return. */
7733 if (read_kbd != 0
7734 && requeued_events_pending_p ())
7735 break;
7736
7737 if (! EMACS_TIME_NEG_P (timer_delay) && time_limit != -1)
7738 {
7739 EMACS_TIME difference;
7740 EMACS_SUB_TIME (difference, timer_delay, timeout);
7741 if (EMACS_TIME_NEG_P (difference))
7742 {
7743 timeout = timer_delay;
7744 timeout_reduced_for_timers = 1;
7745 }
7746 }
7747 }
7748
7749 /* Cause C-g and alarm signals to take immediate action,
7750 and cause input available signals to zero out timeout. */
7751 if (read_kbd < 0)
7752 set_waiting_for_input (&timeout);
7753
7754 /* Wait till there is something to do. */
7755
7756 if (! read_kbd && NILP (wait_for_cell))
7757 FD_ZERO (&waitchannels);
7758 else
7759 FD_SET (0, &waitchannels);
7760
7761 /* If a frame has been newly mapped and needs updating,
7762 reprocess its display stuff. */
7763 if (frame_garbaged && do_display)
7764 {
7765 clear_waiting_for_input ();
7766 redisplay_preserve_echo_area (15);
7767 if (read_kbd < 0)
7768 set_waiting_for_input (&timeout);
7769 }
7770
7771 if (read_kbd && detect_input_pending ())
7772 {
7773 nfds = 0;
7774 FD_ZERO (&waitchannels);
7775 }
7776 else
7777 nfds = select (1, &waitchannels, (SELECT_TYPE *)0, (SELECT_TYPE *)0,
7778 &timeout);
7779
7780 xerrno = errno;
7781
7782 /* Make C-g and alarm signals set flags again */
7783 clear_waiting_for_input ();
7784
7785 /* If we woke up due to SIGWINCH, actually change size now. */
7786 do_pending_window_change (0);
7787
7788 if (time_limit && nfds == 0 && ! timeout_reduced_for_timers)
7789 /* We waited the full specified time, so return now. */
7790 break;
7791
7792 if (nfds == -1)
7793 {
7794 /* If the system call was interrupted, then go around the
7795 loop again. */
7796 if (xerrno == EINTR)
7797 FD_ZERO (&waitchannels);
7798 else
7799 error ("select error: %s", emacs_strerror (xerrno));
7800 }
7801#ifdef SOLARIS2
7802 else if (nfds > 0 && (waitchannels & 1) && interrupt_input)
7803 /* System sometimes fails to deliver SIGIO. */
7804 kill (getpid (), SIGIO);
7805#endif
7806#ifdef SIGIO
7807 if (read_kbd && interrupt_input && (waitchannels & 1))
7808 kill (getpid (), SIGIO);
7809#endif
7810
7811 /* Check for keyboard input */
7812
7813 if (read_kbd
7814 && detect_input_pending_run_timers (do_display))
7815 {
7816 swallow_events (do_display);
7817 if (detect_input_pending_run_timers (do_display))
7818 break;
7819 }
7820
7821 /* If there is unread keyboard input, also return. */
7822 if (read_kbd
7823 && requeued_events_pending_p ())
7824 break;
7825
7826 /* If wait_for_cell. check for keyboard input
7827 but don't run any timers.
7828 ??? (It seems wrong to me to check for keyboard
7829 input at all when wait_for_cell, but the code
7830 has been this way since July 1994.
7831 Try changing this after version 19.31.) */
7832 if (! NILP (wait_for_cell)
7833 && detect_input_pending ())
7834 {
7835 swallow_events (do_display);
7836 if (detect_input_pending ())
7837 break;
7838 }
7839
7840 /* Exit now if the cell we're waiting for became non-nil. */
7841 if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell)))
7842 break;
7843 }
7844
7845 start_polling ();
7846
7847 return 0;
7848}
7849
7850
7851/* Don't confuse make-docfile by having two doc strings for this function.
7852 make-docfile does not pay attention to #if, for good reason! */
7853DEFUN ("get-buffer-process", Fget_buffer_process, Sget_buffer_process, 1, 1, 0,
7854 0)
7855 (name)
7856 register Lisp_Object name;
7857{
7858 return Qnil;
7859}
7860
7861 /* Don't confuse make-docfile by having two doc strings for this function.
7862 make-docfile does not pay attention to #if, for good reason! */
7863DEFUN ("process-inherit-coding-system-flag",
7864 Fprocess_inherit_coding_system_flag, Sprocess_inherit_coding_system_flag,
7865 1, 1, 0,
7866 0)
7867 (process)
7868 register Lisp_Object process;
7869{
7870 /* Ignore the argument and return the value of
7871 inherit-process-coding-system. */
7872 return inherit_process_coding_system ? Qt : Qnil;
7873}
7874
7875/* Kill all processes associated with `buffer'.
7876 If `buffer' is nil, kill all processes.
7877 Since we have no subprocesses, this does nothing. */
7878
7879void
7880kill_buffer_processes (buffer)
7881 Lisp_Object buffer;
7882{
7883}
7884
7885DEFUN ("list-system-processes", Flist_system_processes, Slist_system_processes,
7886 0, 0, 0,
7887 doc: /* Return a list of numerical process IDs of all running processes.
7888If this functionality is unsupported, return nil.
7889
7890See `process-attributes' for getting attributes of a process given its ID. */)
7891 ()
7892{
7893 return list_system_processes ();
7894}
7895
7896DEFUN ("process-attributes", Fprocess_attributes,
7897 Sprocess_attributes, 1, 1, 0,
7898 doc: /* Return attributes of the process given by its PID, a number.
7899
7900Value is an alist where each element is a cons cell of the form
7901
7902 \(KEY . VALUE)
7903
7904If this functionality is unsupported, the value is nil.
7905
7906See `list-system-processes' for getting a list of all process IDs.
7907
7908The KEYs of the attributes that this function may return are listed
7909below, together with the type of the associated VALUE (in parentheses).
7910Not all platforms support all of these attributes; unsupported
7911attributes will not appear in the returned alist.
7912Unless explicitly indicated otherwise, numbers can have either
7913integer or floating point values.
7914
7915 euid -- Effective user User ID of the process (number)
7916 user -- User name corresponding to euid (string)
7917 egid -- Effective user Group ID of the process (number)
7918 group -- Group name corresponding to egid (string)
7919 comm -- Command name (executable name only) (string)
7920 state -- Process state code, such as "S", "R", or "T" (string)
7921 ppid -- Parent process ID (number)
7922 pgrp -- Process group ID (number)
7923 sess -- Session ID, i.e. process ID of session leader (number)
7924 ttname -- Controlling tty name (string)
7925 tpgid -- ID of foreground process group on the process's tty (number)
7926 minflt -- number of minor page faults (number)
7927 majflt -- number of major page faults (number)
7928 cminflt -- cumulative number of minor page faults (number)
7929 cmajflt -- cumulative number of major page faults (number)
7930 utime -- user time used by the process, in the (HIGH LOW USEC) format
7931 stime -- system time used by the process, in the (HIGH LOW USEC) format
7932 time -- sum of utime and stime, in the (HIGH LOW USEC) format
7933 cutime -- user time used by the process and its children, (HIGH LOW USEC)
7934 cstime -- system time used by the process and its children, (HIGH LOW USEC)
7935 ctime -- sum of cutime and cstime, in the (HIGH LOW USEC) format
7936 pri -- priority of the process (number)
7937 nice -- nice value of the process (number)
7938 thcount -- process thread count (number)
7939 start -- time the process started, in the (HIGH LOW USEC) format
7940 vsize -- virtual memory size of the process in KB's (number)
7941 rss -- resident set size of the process in KB's (number)
7942 etime -- elapsed time the process is running, in (HIGH LOW USEC) format
7943 pcpu -- percents of CPU time used by the process (floating-point number)
7944 pmem -- percents of total physical memory used by process's resident set
7945 (floating-point number)
7946 args -- command line which invoked the process (string). */)
7947 (pid)
7948
7949 Lisp_Object pid;
7950{
7951 return system_process_attributes (pid);
7952}
7953
7954void
7955init_process ()
7956{
7957}
7958
7959void
7960syms_of_process ()
7961{
7962 QCtype = intern_c_string (":type");
7963 staticpro (&QCtype);
7964 QCname = intern_c_string (":name");
7965 staticpro (&QCname);
7966 QCtype = intern_c_string (":type");
7967 staticpro (&QCtype);
7968 QCname = intern_c_string (":name");
7969 staticpro (&QCname);
7970 Qeuid = intern_c_string ("euid");
7971 staticpro (&Qeuid);
7972 Qegid = intern_c_string ("egid");
7973 staticpro (&Qegid);
7974 Quser = intern_c_string ("user");
7975 staticpro (&Quser);
7976 Qgroup = intern_c_string ("group");
7977 staticpro (&Qgroup);
7978 Qcomm = intern_c_string ("comm");
7979 staticpro (&Qcomm);
7980 Qstate = intern_c_string ("state");
7981 staticpro (&Qstate);
7982 Qppid = intern_c_string ("ppid");
7983 staticpro (&Qppid);
7984 Qpgrp = intern_c_string ("pgrp");
7985 staticpro (&Qpgrp);
7986 Qsess = intern_c_string ("sess");
7987 staticpro (&Qsess);
7988 Qttname = intern_c_string ("ttname");
7989 staticpro (&Qttname);
7990 Qtpgid = intern_c_string ("tpgid");
7991 staticpro (&Qtpgid);
7992 Qminflt = intern_c_string ("minflt");
7993 staticpro (&Qminflt);
7994 Qmajflt = intern_c_string ("majflt");
7995 staticpro (&Qmajflt);
7996 Qcminflt = intern_c_string ("cminflt");
7997 staticpro (&Qcminflt);
7998 Qcmajflt = intern_c_string ("cmajflt");
7999 staticpro (&Qcmajflt);
8000 Qutime = intern_c_string ("utime");
8001 staticpro (&Qutime);
8002 Qstime = intern_c_string ("stime");
8003 staticpro (&Qstime);
8004 Qtime = intern_c_string ("time");
8005 staticpro (&Qtime);
8006 Qcutime = intern_c_string ("cutime");
8007 staticpro (&Qcutime);
8008 Qcstime = intern_c_string ("cstime");
8009 staticpro (&Qcstime);
8010 Qctime = intern_c_string ("ctime");
8011 staticpro (&Qctime);
8012 Qpri = intern_c_string ("pri");
8013 staticpro (&Qpri);
8014 Qnice = intern_c_string ("nice");
8015 staticpro (&Qnice);
8016 Qthcount = intern_c_string ("thcount");
8017 staticpro (&Qthcount);
8018 Qstart = intern_c_string ("start");
8019 staticpro (&Qstart);
8020 Qvsize = intern_c_string ("vsize");
8021 staticpro (&Qvsize);
8022 Qrss = intern_c_string ("rss");
8023 staticpro (&Qrss);
8024 Qetime = intern_c_string ("etime");
8025 staticpro (&Qetime);
8026 Qpcpu = intern_c_string ("pcpu");
8027 staticpro (&Qpcpu);
8028 Qpmem = intern_c_string ("pmem");
8029 staticpro (&Qpmem);
8030 Qargs = intern_c_string ("args");
8031 staticpro (&Qargs);
8032 7764
8033 defsubr (&Sget_buffer_process); 7765 defsubr (&Sget_buffer_process);
8034 defsubr (&Sprocess_inherit_coding_system_flag); 7766 defsubr (&Sprocess_inherit_coding_system_flag);
@@ -8036,8 +7768,5 @@ syms_of_process ()
8036 defsubr (&Sprocess_attributes); 7768 defsubr (&Sprocess_attributes);
8037} 7769}
8038 7770
8039
8040#endif /* not subprocesses */
8041
8042/* arch-tag: 3706c011-7b9a-4117-bd4f-59e7f701a4c4 7771/* arch-tag: 3706c011-7b9a-4117-bd4f-59e7f701a4c4
8043 (do not change this comment) */ 7772 (do not change this comment) */