diff options
| author | Eli Zaretskii | 2010-07-10 16:26:44 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2010-07-10 16:26:44 +0300 |
| commit | f388c88aece7b0362ff496fb8fe6eb7cdfbac655 (patch) | |
| tree | d96659f19aaec87334e530fc330bb06fb9fc3947 /src/process.c | |
| parent | ca1bb391deffc77c33811f15ad55856baa94f605 (diff) | |
| download | emacs-f388c88aece7b0362ff496fb8fe6eb7cdfbac655.tar.gz emacs-f388c88aece7b0362ff496fb8fe6eb7cdfbac655.zip | |
Unify the two branches, with and without subprocesses.
process.c: Reshuffle #include's. Condition some of the global
and static variables on `subprocesses'.
(hold_keyboard_input, unhold_keyboard_input, kbd_on_hold_p):
Leave only one implementation.
(Fget_buffer_process, Fprocess_inherit_coding_system_flag)
(kill_buffer_processes, Flist_system_processes)
(Fprocess_attributes, init_process, syms_of_process): Unify the
implementations for with subprocesses and without them.
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 938 |
1 files changed, 362 insertions, 576 deletions
diff --git a/src/process.c b/src/process.c index 1eefae1adc9..55f46e2422d 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -30,8 +30,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 30 | sections that call them. */ | 30 | sections that call them. */ |
| 31 | 31 | ||
| 32 | 32 | ||
| 33 | #ifdef subprocesses | ||
| 34 | |||
| 35 | #include <stdio.h> | 33 | #include <stdio.h> |
| 36 | #include <errno.h> | 34 | #include <errno.h> |
| 37 | #include <setjmp.h> | 35 | #include <setjmp.h> |
| @@ -51,6 +49,9 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 51 | #endif | 49 | #endif |
| 52 | #include <fcntl.h> | 50 | #include <fcntl.h> |
| 53 | 51 | ||
| 52 | /* Only MS-DOS does not define `subprocesses'. */ | ||
| 53 | #ifdef subprocesses | ||
| 54 | |||
| 54 | #ifdef HAVE_SOCKETS /* TCP connection support, if kernel can do it */ | 55 | #ifdef HAVE_SOCKETS /* TCP connection support, if kernel can do it */ |
| 55 | #include <sys/socket.h> | 56 | #include <sys/socket.h> |
| 56 | #include <netdb.h> | 57 | #include <netdb.h> |
| @@ -101,6 +102,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 101 | #include <resolv.h> | 102 | #include <resolv.h> |
| 102 | #endif | 103 | #endif |
| 103 | 104 | ||
| 105 | #endif /* subprocesses */ | ||
| 106 | |||
| 104 | #include "lisp.h" | 107 | #include "lisp.h" |
| 105 | #include "systime.h" | 108 | #include "systime.h" |
| 106 | #include "systty.h" | 109 | #include "systty.h" |
| @@ -119,11 +122,16 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 119 | #include "dispextern.h" | 122 | #include "dispextern.h" |
| 120 | #include "composite.h" | 123 | #include "composite.h" |
| 121 | #include "atimer.h" | 124 | #include "atimer.h" |
| 125 | #include "sysselect.h" | ||
| 126 | #include "syssignal.h" | ||
| 127 | #include "syswait.h" | ||
| 122 | 128 | ||
| 123 | #if defined (USE_GTK) || defined (HAVE_GCONF) | 129 | #if defined (USE_GTK) || defined (HAVE_GCONF) |
| 124 | #include "xgselect.h" | 130 | #include "xgselect.h" |
| 125 | #endif /* defined (USE_GTK) || defined (HAVE_GCONF) */ | 131 | #endif /* defined (USE_GTK) || defined (HAVE_GCONF) */ |
| 126 | 132 | ||
| 133 | #ifdef subprocesses | ||
| 134 | |||
| 127 | Lisp_Object Qprocessp; | 135 | Lisp_Object Qprocessp; |
| 128 | Lisp_Object Qrun, Qstop, Qsignal; | 136 | Lisp_Object Qrun, Qstop, Qsignal; |
| 129 | Lisp_Object Qopen, Qclosed, Qconnect, Qfailed, Qlisten; | 137 | Lisp_Object Qopen, Qclosed, Qconnect, Qfailed, Qlisten; |
| @@ -135,7 +143,7 @@ Lisp_Object Qipv6; | |||
| 135 | Lisp_Object QCport, QCspeed, QCprocess; | 143 | Lisp_Object QCport, QCspeed, QCprocess; |
| 136 | Lisp_Object QCbytesize, QCstopbits, QCparity, Qodd, Qeven; | 144 | Lisp_Object QCbytesize, QCstopbits, QCparity, Qodd, Qeven; |
| 137 | Lisp_Object QCflowcontrol, Qhw, Qsw, QCsummary; | 145 | Lisp_Object QCflowcontrol, Qhw, Qsw, QCsummary; |
| 138 | Lisp_Object QCname, QCbuffer, QChost, QCservice, QCtype; | 146 | Lisp_Object QCbuffer, QChost, QCservice; |
| 139 | Lisp_Object QClocal, QCremote, QCcoding; | 147 | Lisp_Object QClocal, QCremote, QCcoding; |
| 140 | Lisp_Object QCserver, QCnowait, QCnoquery, QCstop; | 148 | Lisp_Object QCserver, QCnowait, QCnoquery, QCstop; |
| 141 | Lisp_Object QCsentinel, QClog, QCoptions, QCplist; | 149 | Lisp_Object QCsentinel, QClog, QCoptions, QCplist; |
| @@ -151,11 +159,6 @@ extern Lisp_Object QCfamily; | |||
| 151 | /* QCfilter is defined in keyboard.c. */ | 159 | /* QCfilter is defined in keyboard.c. */ |
| 152 | extern Lisp_Object QCfilter; | 160 | extern Lisp_Object QCfilter; |
| 153 | 161 | ||
| 154 | Lisp_Object Qeuid, Qegid, Qcomm, Qstate, Qppid, Qpgrp, Qsess, Qttname, Qtpgid; | ||
| 155 | Lisp_Object Qminflt, Qmajflt, Qcminflt, Qcmajflt, Qutime, Qstime, Qcstime; | ||
| 156 | Lisp_Object Qcutime, Qpri, Qnice, Qthcount, Qstart, Qvsize, Qrss, Qargs; | ||
| 157 | Lisp_Object Quser, Qgroup, Qetime, Qpcpu, Qpmem, Qtime, Qctime; | ||
| 158 | |||
| 159 | #ifdef HAVE_SOCKETS | 162 | #ifdef HAVE_SOCKETS |
| 160 | #define NETCONN_P(p) (EQ (XPROCESS (p)->type, Qnetwork)) | 163 | #define NETCONN_P(p) (EQ (XPROCESS (p)->type, Qnetwork)) |
| 161 | #define NETCONN1_P(p) (EQ ((p)->type, Qnetwork)) | 164 | #define NETCONN1_P(p) (EQ ((p)->type, Qnetwork)) |
| @@ -178,10 +181,6 @@ Lisp_Object Quser, Qgroup, Qetime, Qpcpu, Qpmem, Qtime, Qctime; | |||
| 178 | #define SIGCHLD SIGCLD | 181 | #define SIGCHLD SIGCLD |
| 179 | #endif /* SIGCLD */ | 182 | #endif /* SIGCLD */ |
| 180 | 183 | ||
| 181 | #include "syssignal.h" | ||
| 182 | |||
| 183 | #include "syswait.h" | ||
| 184 | |||
| 185 | extern char *get_operating_system_release (void); | 184 | extern char *get_operating_system_release (void); |
| 186 | 185 | ||
| 187 | /* Serial processes require termios or Windows. */ | 186 | /* Serial processes require termios or Windows. */ |
| @@ -282,9 +281,6 @@ static Lisp_Object Vprocess_adaptive_read_buffering; | |||
| 282 | #define process_output_delay_count 0 | 281 | #define process_output_delay_count 0 |
| 283 | #endif | 282 | #endif |
| 284 | 283 | ||
| 285 | |||
| 286 | #include "sysselect.h" | ||
| 287 | |||
| 288 | static int keyboard_bit_set (SELECT_TYPE *); | 284 | static int keyboard_bit_set (SELECT_TYPE *); |
| 289 | static void deactivate_process (Lisp_Object); | 285 | static void deactivate_process (Lisp_Object); |
| 290 | static void status_notify (struct Lisp_Process *); | 286 | static void status_notify (struct Lisp_Process *); |
| @@ -300,16 +296,26 @@ static void create_pty (Lisp_Object); | |||
| 300 | static Lisp_Object get_process (register Lisp_Object name); | 296 | static Lisp_Object get_process (register Lisp_Object name); |
| 301 | static void exec_sentinel (Lisp_Object proc, Lisp_Object reason); | 297 | static void exec_sentinel (Lisp_Object proc, Lisp_Object reason); |
| 302 | 298 | ||
| 303 | extern int timers_run; | 299 | #endif /* subprocesses */ |
| 304 | |||
| 305 | /* Mask of bits indicating the descriptors that we wait for input on. */ | ||
| 306 | 300 | ||
| 307 | static SELECT_TYPE input_wait_mask; | 301 | extern int timers_run; |
| 308 | 302 | ||
| 303 | Lisp_Object Qeuid, Qegid, Qcomm, Qstate, Qppid, Qpgrp, Qsess, Qttname, Qtpgid; | ||
| 304 | Lisp_Object Qminflt, Qmajflt, Qcminflt, Qcmajflt, Qutime, Qstime, Qcstime; | ||
| 305 | Lisp_Object Qcutime, Qpri, Qnice, Qthcount, Qstart, Qvsize, Qrss, Qargs; | ||
| 306 | Lisp_Object Quser, Qgroup, Qetime, Qpcpu, Qpmem, Qtime, Qctime; | ||
| 307 | Lisp_Object QCname, QCtype; | ||
| 308 | |||
| 309 | /* Non-zero if keyboard input is on hold, zero otherwise. */ | 309 | /* Non-zero if keyboard input is on hold, zero otherwise. */ |
| 310 | 310 | ||
| 311 | static int kbd_is_on_hold; | 311 | static int kbd_is_on_hold; |
| 312 | 312 | ||
| 313 | #ifdef subprocesses | ||
| 314 | |||
| 315 | /* Mask of bits indicating the descriptors that we wait for input on. */ | ||
| 316 | |||
| 317 | static SELECT_TYPE input_wait_mask; | ||
| 318 | |||
| 313 | /* Mask that excludes keyboard input descriptor(s). */ | 319 | /* Mask that excludes keyboard input descriptor(s). */ |
| 314 | 320 | ||
| 315 | static SELECT_TYPE non_keyboard_wait_mask; | 321 | static SELECT_TYPE non_keyboard_wait_mask; |
| @@ -333,9 +339,9 @@ static SELECT_TYPE connect_wait_mask; | |||
| 333 | static int num_pending_connects; | 339 | static int num_pending_connects; |
| 334 | 340 | ||
| 335 | #define IF_NON_BLOCKING_CONNECT(s) s | 341 | #define IF_NON_BLOCKING_CONNECT(s) s |
| 336 | #else | 342 | #else /* NON_BLOCKING_CONNECT */ |
| 337 | #define IF_NON_BLOCKING_CONNECT(s) | 343 | #define IF_NON_BLOCKING_CONNECT(s) |
| 338 | #endif | 344 | #endif /* NON_BLOCKING_CONNECT */ |
| 339 | 345 | ||
| 340 | /* The largest descriptor currently in use for a process object. */ | 346 | /* The largest descriptor currently in use for a process object. */ |
| 341 | static int max_process_desc; | 347 | static int max_process_desc; |
| @@ -695,26 +701,6 @@ DEFUN ("get-process", Fget_process, Sget_process, 1, 1, 0, | |||
| 695 | return Fcdr (Fassoc (name, Vprocess_alist)); | 701 | return Fcdr (Fassoc (name, Vprocess_alist)); |
| 696 | } | 702 | } |
| 697 | 703 | ||
| 698 | DEFUN ("get-buffer-process", Fget_buffer_process, Sget_buffer_process, 1, 1, 0, | ||
| 699 | doc: /* Return the (or a) process associated with BUFFER. | ||
| 700 | BUFFER may be a buffer or the name of one. */) | ||
| 701 | (register Lisp_Object buffer) | ||
| 702 | { | ||
| 703 | register Lisp_Object buf, tail, proc; | ||
| 704 | |||
| 705 | if (NILP (buffer)) return Qnil; | ||
| 706 | buf = Fget_buffer (buffer); | ||
| 707 | if (NILP (buf)) return Qnil; | ||
| 708 | |||
| 709 | for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) | ||
| 710 | { | ||
| 711 | proc = Fcdr (XCAR (tail)); | ||
| 712 | if (PROCESSP (proc) && EQ (XPROCESS (proc)->buffer, buf)) | ||
| 713 | return proc; | ||
| 714 | } | ||
| 715 | return Qnil; | ||
| 716 | } | ||
| 717 | |||
| 718 | /* This is how commands for the user decode process arguments. It | 704 | /* This is how commands for the user decode process arguments. It |
| 719 | accepts a process, a process name, a buffer, a buffer name, or nil. | 705 | accepts a process, a process name, a buffer, a buffer name, or nil. |
| 720 | Buffers denote the first process in the buffer, and nil denotes the | 706 | Buffers denote the first process in the buffer, and nil denotes the |
| @@ -1096,19 +1082,6 @@ for the process which will run. */) | |||
| 1096 | return flag; | 1082 | return flag; |
| 1097 | } | 1083 | } |
| 1098 | 1084 | ||
| 1099 | DEFUN ("process-inherit-coding-system-flag", | ||
| 1100 | Fprocess_inherit_coding_system_flag, Sprocess_inherit_coding_system_flag, | ||
| 1101 | 1, 1, 0, | ||
| 1102 | doc: /* Return the value of inherit-coding-system flag for PROCESS. | ||
| 1103 | If this flag is t, `buffer-file-coding-system' of the buffer | ||
| 1104 | associated with PROCESS will inherit the coding system used to decode | ||
| 1105 | the process output. */) | ||
| 1106 | (register Lisp_Object process) | ||
| 1107 | { | ||
| 1108 | CHECK_PROCESS (process); | ||
| 1109 | return XPROCESS (process)->inherit_coding_system_flag ? Qt : Qnil; | ||
| 1110 | } | ||
| 1111 | |||
| 1112 | DEFUN ("set-process-query-on-exit-flag", | 1085 | DEFUN ("set-process-query-on-exit-flag", |
| 1113 | Fset_process_query_on_exit_flag, Sset_process_query_on_exit_flag, | 1086 | Fset_process_query_on_exit_flag, Sset_process_query_on_exit_flag, |
| 1114 | 2, 2, 0, | 1087 | 2, 2, 0, |
| @@ -6474,28 +6447,6 @@ process has been transmitted to the serial port. */) | |||
| 6474 | } | 6447 | } |
| 6475 | return process; | 6448 | return process; |
| 6476 | } | 6449 | } |
| 6477 | |||
| 6478 | /* Kill all processes associated with `buffer'. | ||
| 6479 | If `buffer' is nil, kill all processes */ | ||
| 6480 | |||
| 6481 | void | ||
| 6482 | kill_buffer_processes (Lisp_Object buffer) | ||
| 6483 | { | ||
| 6484 | Lisp_Object tail, proc; | ||
| 6485 | |||
| 6486 | for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) | ||
| 6487 | { | ||
| 6488 | proc = XCDR (XCAR (tail)); | ||
| 6489 | if (PROCESSP (proc) | ||
| 6490 | && (NILP (buffer) || EQ (XPROCESS (proc)->buffer, buffer))) | ||
| 6491 | { | ||
| 6492 | if (NETCONN_P (proc) || SERIALCONN_P (proc)) | ||
| 6493 | Fdelete_process (proc); | ||
| 6494 | else if (XPROCESS (proc)->infd >= 0) | ||
| 6495 | process_send_signal (proc, SIGHUP, Qnil, 1); | ||
| 6496 | } | ||
| 6497 | } | ||
| 6498 | } | ||
| 6499 | 6450 | ||
| 6500 | /* On receipt of a signal that a child status has changed, loop asking | 6451 | /* On receipt of a signal that a child status has changed, loop asking |
| 6501 | about children with changed statuses until the system says there | 6452 | about children with changed statuses until the system says there |
| @@ -6960,29 +6911,6 @@ DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p, | |||
| 6960 | 6911 | ||
| 6961 | 6912 | ||
| 6962 | 6913 | ||
| 6963 | /* Stop reading input from keyboard sources. */ | ||
| 6964 | |||
| 6965 | void | ||
| 6966 | hold_keyboard_input (void) | ||
| 6967 | { | ||
| 6968 | kbd_is_on_hold = 1; | ||
| 6969 | } | ||
| 6970 | |||
| 6971 | /* Resume reading input from keyboard sources. */ | ||
| 6972 | |||
| 6973 | void | ||
| 6974 | unhold_keyboard_input (void) | ||
| 6975 | { | ||
| 6976 | kbd_is_on_hold = 0; | ||
| 6977 | } | ||
| 6978 | |||
| 6979 | /* Return non-zero if keyboard input is on hold, zero otherwise. */ | ||
| 6980 | |||
| 6981 | int | ||
| 6982 | kbd_on_hold_p (void) | ||
| 6983 | { | ||
| 6984 | return kbd_is_on_hold; | ||
| 6985 | } | ||
| 6986 | 6914 | ||
| 6987 | /* Add DESC to the set of keyboard input descriptors. */ | 6915 | /* Add DESC to the set of keyboard input descriptors. */ |
| 6988 | 6916 | ||
| @@ -7060,6 +6988,326 @@ keyboard_bit_set (fd_set *mask) | |||
| 7060 | 6988 | ||
| 7061 | return 0; | 6989 | return 0; |
| 7062 | } | 6990 | } |
| 6991 | |||
| 6992 | #else /* not subprocesses */ | ||
| 6993 | |||
| 6994 | /* Defined on msdos.c. */ | ||
| 6995 | extern int sys_select (int, SELECT_TYPE *, SELECT_TYPE *, SELECT_TYPE *, | ||
| 6996 | EMACS_TIME *); | ||
| 6997 | |||
| 6998 | /* Implementation of wait_reading_process_output, assuming that there | ||
| 6999 | are no subprocesses. Used only by the MS-DOS build. | ||
| 7000 | |||
| 7001 | Wait for timeout to elapse and/or keyboard input to be available. | ||
| 7002 | |||
| 7003 | time_limit is: | ||
| 7004 | timeout in seconds, or | ||
| 7005 | zero for no limit, or | ||
| 7006 | -1 means gobble data immediately available but don't wait for any. | ||
| 7007 | |||
| 7008 | read_kbd is a Lisp_Object: | ||
| 7009 | 0 to ignore keyboard input, or | ||
| 7010 | 1 to return when input is available, or | ||
| 7011 | -1 means caller will actually read the input, so don't throw to | ||
| 7012 | the quit handler. | ||
| 7013 | |||
| 7014 | see full version for other parameters. We know that wait_proc will | ||
| 7015 | always be NULL, since `subprocesses' isn't defined. | ||
| 7016 | |||
| 7017 | do_display != 0 means redisplay should be done to show subprocess | ||
| 7018 | output that arrives. | ||
| 7019 | |||
| 7020 | Return true if we received input from any process. */ | ||
| 7021 | |||
| 7022 | int | ||
| 7023 | wait_reading_process_output (time_limit, microsecs, read_kbd, do_display, | ||
| 7024 | wait_for_cell, wait_proc, just_wait_proc) | ||
| 7025 | int time_limit, microsecs, read_kbd, do_display; | ||
| 7026 | Lisp_Object wait_for_cell; | ||
| 7027 | struct Lisp_Process *wait_proc; | ||
| 7028 | int just_wait_proc; | ||
| 7029 | { | ||
| 7030 | register int nfds; | ||
| 7031 | EMACS_TIME end_time, timeout; | ||
| 7032 | SELECT_TYPE waitchannels; | ||
| 7033 | int xerrno; | ||
| 7034 | |||
| 7035 | /* What does time_limit really mean? */ | ||
| 7036 | if (time_limit || microsecs) | ||
| 7037 | { | ||
| 7038 | EMACS_GET_TIME (end_time); | ||
| 7039 | EMACS_SET_SECS_USECS (timeout, time_limit, microsecs); | ||
| 7040 | EMACS_ADD_TIME (end_time, end_time, timeout); | ||
| 7041 | } | ||
| 7042 | |||
| 7043 | /* Turn off periodic alarms (in case they are in use) | ||
| 7044 | and then turn off any other atimers, | ||
| 7045 | because the select emulator uses alarms. */ | ||
| 7046 | stop_polling (); | ||
| 7047 | turn_on_atimers (0); | ||
| 7048 | |||
| 7049 | while (1) | ||
| 7050 | { | ||
| 7051 | int timeout_reduced_for_timers = 0; | ||
| 7052 | |||
| 7053 | /* If calling from keyboard input, do not quit | ||
| 7054 | since we want to return C-g as an input character. | ||
| 7055 | Otherwise, do pending quit if requested. */ | ||
| 7056 | if (read_kbd >= 0) | ||
| 7057 | QUIT; | ||
| 7058 | |||
| 7059 | /* Exit now if the cell we're waiting for became non-nil. */ | ||
| 7060 | if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell))) | ||
| 7061 | break; | ||
| 7062 | |||
| 7063 | /* Compute time from now till when time limit is up */ | ||
| 7064 | /* Exit if already run out */ | ||
| 7065 | if (time_limit == -1) | ||
| 7066 | { | ||
| 7067 | /* -1 specified for timeout means | ||
| 7068 | gobble output available now | ||
| 7069 | but don't wait at all. */ | ||
| 7070 | |||
| 7071 | EMACS_SET_SECS_USECS (timeout, 0, 0); | ||
| 7072 | } | ||
| 7073 | else if (time_limit || microsecs) | ||
| 7074 | { | ||
| 7075 | EMACS_GET_TIME (timeout); | ||
| 7076 | EMACS_SUB_TIME (timeout, end_time, timeout); | ||
| 7077 | if (EMACS_TIME_NEG_P (timeout)) | ||
| 7078 | break; | ||
| 7079 | } | ||
| 7080 | else | ||
| 7081 | { | ||
| 7082 | EMACS_SET_SECS_USECS (timeout, 100000, 0); | ||
| 7083 | } | ||
| 7084 | |||
| 7085 | /* If our caller will not immediately handle keyboard events, | ||
| 7086 | run timer events directly. | ||
| 7087 | (Callers that will immediately read keyboard events | ||
| 7088 | call timer_delay on their own.) */ | ||
| 7089 | if (NILP (wait_for_cell)) | ||
| 7090 | { | ||
| 7091 | EMACS_TIME timer_delay; | ||
| 7092 | |||
| 7093 | do | ||
| 7094 | { | ||
| 7095 | int old_timers_run = timers_run; | ||
| 7096 | timer_delay = timer_check (1); | ||
| 7097 | if (timers_run != old_timers_run && do_display) | ||
| 7098 | /* We must retry, since a timer may have requeued itself | ||
| 7099 | and that could alter the time delay. */ | ||
| 7100 | redisplay_preserve_echo_area (14); | ||
| 7101 | else | ||
| 7102 | break; | ||
| 7103 | } | ||
| 7104 | while (!detect_input_pending ()); | ||
| 7105 | |||
| 7106 | /* If there is unread keyboard input, also return. */ | ||
| 7107 | if (read_kbd != 0 | ||
| 7108 | && requeued_events_pending_p ()) | ||
| 7109 | break; | ||
| 7110 | |||
| 7111 | if (! EMACS_TIME_NEG_P (timer_delay) && time_limit != -1) | ||
| 7112 | { | ||
| 7113 | EMACS_TIME difference; | ||
| 7114 | EMACS_SUB_TIME (difference, timer_delay, timeout); | ||
| 7115 | if (EMACS_TIME_NEG_P (difference)) | ||
| 7116 | { | ||
| 7117 | timeout = timer_delay; | ||
| 7118 | timeout_reduced_for_timers = 1; | ||
| 7119 | } | ||
| 7120 | } | ||
| 7121 | } | ||
| 7122 | |||
| 7123 | /* Cause C-g and alarm signals to take immediate action, | ||
| 7124 | and cause input available signals to zero out timeout. */ | ||
| 7125 | if (read_kbd < 0) | ||
| 7126 | set_waiting_for_input (&timeout); | ||
| 7127 | |||
| 7128 | /* Wait till there is something to do. */ | ||
| 7129 | |||
| 7130 | if (! read_kbd && NILP (wait_for_cell)) | ||
| 7131 | FD_ZERO (&waitchannels); | ||
| 7132 | else | ||
| 7133 | FD_SET (0, &waitchannels); | ||
| 7134 | |||
| 7135 | /* If a frame has been newly mapped and needs updating, | ||
| 7136 | reprocess its display stuff. */ | ||
| 7137 | if (frame_garbaged && do_display) | ||
| 7138 | { | ||
| 7139 | clear_waiting_for_input (); | ||
| 7140 | redisplay_preserve_echo_area (15); | ||
| 7141 | if (read_kbd < 0) | ||
| 7142 | set_waiting_for_input (&timeout); | ||
| 7143 | } | ||
| 7144 | |||
| 7145 | if (read_kbd && detect_input_pending ()) | ||
| 7146 | { | ||
| 7147 | nfds = 0; | ||
| 7148 | FD_ZERO (&waitchannels); | ||
| 7149 | } | ||
| 7150 | else | ||
| 7151 | nfds = select (1, &waitchannels, (SELECT_TYPE *)0, (SELECT_TYPE *)0, | ||
| 7152 | &timeout); | ||
| 7153 | |||
| 7154 | xerrno = errno; | ||
| 7155 | |||
| 7156 | /* Make C-g and alarm signals set flags again */ | ||
| 7157 | clear_waiting_for_input (); | ||
| 7158 | |||
| 7159 | /* If we woke up due to SIGWINCH, actually change size now. */ | ||
| 7160 | do_pending_window_change (0); | ||
| 7161 | |||
| 7162 | if (time_limit && nfds == 0 && ! timeout_reduced_for_timers) | ||
| 7163 | /* We waited the full specified time, so return now. */ | ||
| 7164 | break; | ||
| 7165 | |||
| 7166 | if (nfds == -1) | ||
| 7167 | { | ||
| 7168 | /* If the system call was interrupted, then go around the | ||
| 7169 | loop again. */ | ||
| 7170 | if (xerrno == EINTR) | ||
| 7171 | FD_ZERO (&waitchannels); | ||
| 7172 | else | ||
| 7173 | error ("select error: %s", emacs_strerror (xerrno)); | ||
| 7174 | } | ||
| 7175 | |||
| 7176 | /* Check for keyboard input */ | ||
| 7177 | |||
| 7178 | if (read_kbd | ||
| 7179 | && detect_input_pending_run_timers (do_display)) | ||
| 7180 | { | ||
| 7181 | swallow_events (do_display); | ||
| 7182 | if (detect_input_pending_run_timers (do_display)) | ||
| 7183 | break; | ||
| 7184 | } | ||
| 7185 | |||
| 7186 | /* If there is unread keyboard input, also return. */ | ||
| 7187 | if (read_kbd | ||
| 7188 | && requeued_events_pending_p ()) | ||
| 7189 | break; | ||
| 7190 | |||
| 7191 | /* If wait_for_cell. check for keyboard input | ||
| 7192 | but don't run any timers. | ||
| 7193 | ??? (It seems wrong to me to check for keyboard | ||
| 7194 | input at all when wait_for_cell, but the code | ||
| 7195 | has been this way since July 1994. | ||
| 7196 | Try changing this after version 19.31.) */ | ||
| 7197 | if (! NILP (wait_for_cell) | ||
| 7198 | && detect_input_pending ()) | ||
| 7199 | { | ||
| 7200 | swallow_events (do_display); | ||
| 7201 | if (detect_input_pending ()) | ||
| 7202 | break; | ||
| 7203 | } | ||
| 7204 | |||
| 7205 | /* Exit now if the cell we're waiting for became non-nil. */ | ||
| 7206 | if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell))) | ||
| 7207 | break; | ||
| 7208 | } | ||
| 7209 | |||
| 7210 | start_polling (); | ||
| 7211 | |||
| 7212 | return 0; | ||
| 7213 | } | ||
| 7214 | |||
| 7215 | #endif /* not subprocesses */ | ||
| 7216 | |||
| 7217 | /* The following functions are needed even if async subprocesses are | ||
| 7218 | not supported. Some of them are no-op stubs in that case. */ | ||
| 7219 | |||
| 7220 | DEFUN ("get-buffer-process", Fget_buffer_process, Sget_buffer_process, 1, 1, 0, | ||
| 7221 | doc: /* Return the (or a) process associated with BUFFER. | ||
| 7222 | BUFFER may be a buffer or the name of one. */) | ||
| 7223 | (register Lisp_Object buffer) | ||
| 7224 | { | ||
| 7225 | #ifdef subprocesses | ||
| 7226 | register Lisp_Object buf, tail, proc; | ||
| 7227 | |||
| 7228 | if (NILP (buffer)) return Qnil; | ||
| 7229 | buf = Fget_buffer (buffer); | ||
| 7230 | if (NILP (buf)) return Qnil; | ||
| 7231 | |||
| 7232 | for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) | ||
| 7233 | { | ||
| 7234 | proc = Fcdr (XCAR (tail)); | ||
| 7235 | if (PROCESSP (proc) && EQ (XPROCESS (proc)->buffer, buf)) | ||
| 7236 | return proc; | ||
| 7237 | } | ||
| 7238 | #endif /* subprocesses */ | ||
| 7239 | return Qnil; | ||
| 7240 | } | ||
| 7241 | |||
| 7242 | DEFUN ("process-inherit-coding-system-flag", | ||
| 7243 | Fprocess_inherit_coding_system_flag, Sprocess_inherit_coding_system_flag, | ||
| 7244 | 1, 1, 0, | ||
| 7245 | doc: /* Return the value of inherit-coding-system flag for PROCESS. | ||
| 7246 | If this flag is t, `buffer-file-coding-system' of the buffer | ||
| 7247 | associated with PROCESS will inherit the coding system used to decode | ||
| 7248 | the process output. */) | ||
| 7249 | (register Lisp_Object process) | ||
| 7250 | { | ||
| 7251 | #ifdef subprocesses | ||
| 7252 | CHECK_PROCESS (process); | ||
| 7253 | return XPROCESS (process)->inherit_coding_system_flag ? Qt : Qnil; | ||
| 7254 | #else | ||
| 7255 | /* Ignore the argument and return the value of | ||
| 7256 | inherit-process-coding-system. */ | ||
| 7257 | return inherit_process_coding_system ? Qt : Qnil; | ||
| 7258 | #endif | ||
| 7259 | } | ||
| 7260 | |||
| 7261 | /* Kill all processes associated with `buffer'. | ||
| 7262 | If `buffer' is nil, kill all processes */ | ||
| 7263 | |||
| 7264 | void | ||
| 7265 | kill_buffer_processes (Lisp_Object buffer) | ||
| 7266 | { | ||
| 7267 | #ifdef subprocesses | ||
| 7268 | Lisp_Object tail, proc; | ||
| 7269 | |||
| 7270 | for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) | ||
| 7271 | { | ||
| 7272 | proc = XCDR (XCAR (tail)); | ||
| 7273 | if (PROCESSP (proc) | ||
| 7274 | && (NILP (buffer) || EQ (XPROCESS (proc)->buffer, buffer))) | ||
| 7275 | { | ||
| 7276 | if (NETCONN_P (proc) || SERIALCONN_P (proc)) | ||
| 7277 | Fdelete_process (proc); | ||
| 7278 | else if (XPROCESS (proc)->infd >= 0) | ||
| 7279 | process_send_signal (proc, SIGHUP, Qnil, 1); | ||
| 7280 | } | ||
| 7281 | } | ||
| 7282 | #else /* subprocesses */ | ||
| 7283 | /* Since we have no subprocesses, this does nothing. */ | ||
| 7284 | #endif /* subprocesses */ | ||
| 7285 | } | ||
| 7286 | |||
| 7287 | /* Stop reading input from keyboard sources. */ | ||
| 7288 | |||
| 7289 | void | ||
| 7290 | hold_keyboard_input (void) | ||
| 7291 | { | ||
| 7292 | kbd_is_on_hold = 1; | ||
| 7293 | } | ||
| 7294 | |||
| 7295 | /* Resume reading input from keyboard sources. */ | ||
| 7296 | |||
| 7297 | void | ||
| 7298 | unhold_keyboard_input (void) | ||
| 7299 | { | ||
| 7300 | kbd_is_on_hold = 0; | ||
| 7301 | } | ||
| 7302 | |||
| 7303 | /* Return non-zero if keyboard input is on hold, zero otherwise. */ | ||
| 7304 | |||
| 7305 | int | ||
| 7306 | kbd_on_hold_p (void) | ||
| 7307 | { | ||
| 7308 | return kbd_is_on_hold; | ||
| 7309 | } | ||
| 7310 | |||
| 7063 | 7311 | ||
| 7064 | /* Enumeration of and access to system processes a-la ps(1). */ | 7312 | /* Enumeration of and access to system processes a-la ps(1). */ |
| 7065 | 7313 | ||
| @@ -7129,10 +7377,12 @@ integer or floating point values. | |||
| 7129 | { | 7377 | { |
| 7130 | return system_process_attributes (pid); | 7378 | return system_process_attributes (pid); |
| 7131 | } | 7379 | } |
| 7380 | |||
| 7132 | 7381 | ||
| 7133 | void | 7382 | void |
| 7134 | init_process (void) | 7383 | init_process (void) |
| 7135 | { | 7384 | { |
| 7385 | #ifdef subprocesses | ||
| 7136 | register int i; | 7386 | register int i; |
| 7137 | 7387 | ||
| 7138 | inhibit_sentinels = 0; | 7388 | inhibit_sentinels = 0; |
| @@ -7231,11 +7481,15 @@ init_process (void) | |||
| 7231 | } | 7481 | } |
| 7232 | } | 7482 | } |
| 7233 | #endif | 7483 | #endif |
| 7484 | #endif /* subprocesses */ | ||
| 7485 | kbd_is_on_hold = 0; | ||
| 7234 | } | 7486 | } |
| 7235 | 7487 | ||
| 7236 | void | 7488 | void |
| 7237 | syms_of_process (void) | 7489 | syms_of_process (void) |
| 7238 | { | 7490 | { |
| 7491 | #ifdef subprocesses | ||
| 7492 | |||
| 7239 | Qprocessp = intern_c_string ("processp"); | 7493 | Qprocessp = intern_c_string ("processp"); |
| 7240 | staticpro (&Qprocessp); | 7494 | staticpro (&Qprocessp); |
| 7241 | Qrun = intern_c_string ("run"); | 7495 | Qrun = intern_c_string ("run"); |
| @@ -7306,17 +7560,12 @@ syms_of_process (void) | |||
| 7306 | staticpro (&Qnetwork); | 7560 | staticpro (&Qnetwork); |
| 7307 | Qserial = intern_c_string ("serial"); | 7561 | Qserial = intern_c_string ("serial"); |
| 7308 | staticpro (&Qserial); | 7562 | staticpro (&Qserial); |
| 7309 | |||
| 7310 | QCname = intern_c_string (":name"); | ||
| 7311 | staticpro (&QCname); | ||
| 7312 | QCbuffer = intern_c_string (":buffer"); | 7563 | QCbuffer = intern_c_string (":buffer"); |
| 7313 | staticpro (&QCbuffer); | 7564 | staticpro (&QCbuffer); |
| 7314 | QChost = intern_c_string (":host"); | 7565 | QChost = intern_c_string (":host"); |
| 7315 | staticpro (&QChost); | 7566 | staticpro (&QChost); |
| 7316 | QCservice = intern_c_string (":service"); | 7567 | QCservice = intern_c_string (":service"); |
| 7317 | staticpro (&QCservice); | 7568 | staticpro (&QCservice); |
| 7318 | QCtype = intern_c_string (":type"); | ||
| 7319 | staticpro (&QCtype); | ||
| 7320 | QClocal = intern_c_string (":local"); | 7569 | QClocal = intern_c_string (":local"); |
| 7321 | staticpro (&QClocal); | 7570 | staticpro (&QClocal); |
| 7322 | QCremote = intern_c_string (":remote"); | 7571 | QCremote = intern_c_string (":remote"); |
| @@ -7348,6 +7597,13 @@ syms_of_process (void) | |||
| 7348 | staticpro (&deleted_pid_list); | 7597 | staticpro (&deleted_pid_list); |
| 7349 | #endif | 7598 | #endif |
| 7350 | 7599 | ||
| 7600 | #endif /* subprocesses */ | ||
| 7601 | |||
| 7602 | QCname = intern_c_string (":name"); | ||
| 7603 | staticpro (&QCname); | ||
| 7604 | QCtype = intern_c_string (":type"); | ||
| 7605 | staticpro (&QCtype); | ||
| 7606 | |||
| 7351 | Qeuid = intern_c_string ("euid"); | 7607 | Qeuid = intern_c_string ("euid"); |
| 7352 | staticpro (&Qeuid); | 7608 | staticpro (&Qeuid); |
| 7353 | Qegid = intern_c_string ("egid"); | 7609 | Qegid = intern_c_string ("egid"); |
| @@ -7411,6 +7667,7 @@ syms_of_process (void) | |||
| 7411 | Qargs = intern_c_string ("args"); | 7667 | Qargs = intern_c_string ("args"); |
| 7412 | staticpro (&Qargs); | 7668 | staticpro (&Qargs); |
| 7413 | 7669 | ||
| 7670 | #ifdef subprocesses | ||
| 7414 | DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes, | 7671 | DEFVAR_BOOL ("delete-exited-processes", &delete_exited_processes, |
| 7415 | doc: /* *Non-nil means delete processes immediately when they exit. | 7672 | doc: /* *Non-nil means delete processes immediately when they exit. |
| 7416 | A value of nil means don't delete them until `list-processes' is run. */); | 7673 | A value of nil means don't delete them until `list-processes' is run. */); |
| @@ -7441,7 +7698,6 @@ The variable takes effect when `start-process' is called. */); | |||
| 7441 | 7698 | ||
| 7442 | defsubr (&Sprocessp); | 7699 | defsubr (&Sprocessp); |
| 7443 | defsubr (&Sget_process); | 7700 | defsubr (&Sget_process); |
| 7444 | defsubr (&Sget_buffer_process); | ||
| 7445 | defsubr (&Sdelete_process); | 7701 | defsubr (&Sdelete_process); |
| 7446 | defsubr (&Sprocess_status); | 7702 | defsubr (&Sprocess_status); |
| 7447 | defsubr (&Sprocess_exit_status); | 7703 | defsubr (&Sprocess_exit_status); |
| @@ -7458,7 +7714,6 @@ The variable takes effect when `start-process' is called. */); | |||
| 7458 | defsubr (&Sprocess_sentinel); | 7714 | defsubr (&Sprocess_sentinel); |
| 7459 | defsubr (&Sset_process_window_size); | 7715 | defsubr (&Sset_process_window_size); |
| 7460 | defsubr (&Sset_process_inherit_coding_system_flag); | 7716 | defsubr (&Sset_process_inherit_coding_system_flag); |
| 7461 | defsubr (&Sprocess_inherit_coding_system_flag); | ||
| 7462 | defsubr (&Sset_process_query_on_exit_flag); | 7717 | defsubr (&Sset_process_query_on_exit_flag); |
| 7463 | defsubr (&Sprocess_query_on_exit_flag); | 7718 | defsubr (&Sprocess_query_on_exit_flag); |
| 7464 | defsubr (&Sprocess_contact); | 7719 | defsubr (&Sprocess_contact); |
| @@ -7505,474 +7760,8 @@ The variable takes effect when `start-process' is called. */); | |||
| 7505 | defsubr (&Sprocess_coding_system); | 7760 | defsubr (&Sprocess_coding_system); |
| 7506 | defsubr (&Sset_process_filter_multibyte); | 7761 | defsubr (&Sset_process_filter_multibyte); |
| 7507 | defsubr (&Sprocess_filter_multibyte_p); | 7762 | defsubr (&Sprocess_filter_multibyte_p); |
| 7508 | defsubr (&Slist_system_processes); | ||
| 7509 | defsubr (&Sprocess_attributes); | ||
| 7510 | } | ||
| 7511 | |||
| 7512 | |||
| 7513 | #else /* not subprocesses */ | ||
| 7514 | |||
| 7515 | #include <sys/types.h> | ||
| 7516 | #include <errno.h> | ||
| 7517 | #include <sys/stat.h> | ||
| 7518 | #include <stdlib.h> | ||
| 7519 | #include <fcntl.h> | ||
| 7520 | #include <setjmp.h> | ||
| 7521 | #ifdef HAVE_UNISTD_H | ||
| 7522 | #include <unistd.h> | ||
| 7523 | #endif | ||
| 7524 | |||
| 7525 | #include "lisp.h" | ||
| 7526 | #include "systime.h" | ||
| 7527 | #include "character.h" | ||
| 7528 | #include "coding.h" | ||
| 7529 | #include "termopts.h" | ||
| 7530 | #include "sysselect.h" | ||
| 7531 | |||
| 7532 | extern int frame_garbaged; | ||
| 7533 | |||
| 7534 | extern EMACS_TIME timer_check (); | ||
| 7535 | extern int timers_run; | ||
| 7536 | |||
| 7537 | Lisp_Object QCtype, QCname; | ||
| 7538 | |||
| 7539 | Lisp_Object Qeuid, Qegid, Qcomm, Qstate, Qppid, Qpgrp, Qsess, Qttname, Qtpgid; | ||
| 7540 | Lisp_Object Qminflt, Qmajflt, Qcminflt, Qcmajflt, Qutime, Qstime, Qcstime; | ||
| 7541 | Lisp_Object Qcutime, Qpri, Qnice, Qthcount, Qstart, Qvsize, Qrss, Qargs; | ||
| 7542 | Lisp_Object Quser, Qgroup, Qetime, Qpcpu, Qpmem, Qtime, Qctime; | ||
| 7543 | |||
| 7544 | /* Non-zero if keyboard input is on hold, zero otherwise. */ | ||
| 7545 | static int kbd_is_on_hold; | ||
| 7546 | |||
| 7547 | /* As described above, except assuming that there are no subprocesses: | ||
| 7548 | |||
| 7549 | Wait for timeout to elapse and/or keyboard input to be available. | ||
| 7550 | |||
| 7551 | time_limit is: | ||
| 7552 | timeout in seconds, or | ||
| 7553 | zero for no limit, or | ||
| 7554 | -1 means gobble data immediately available but don't wait for any. | ||
| 7555 | |||
| 7556 | read_kbd is a Lisp_Object: | ||
| 7557 | 0 to ignore keyboard input, or | ||
| 7558 | 1 to return when input is available, or | ||
| 7559 | -1 means caller will actually read the input, so don't throw to | ||
| 7560 | the quit handler. | ||
| 7561 | |||
| 7562 | see full version for other parameters. We know that wait_proc will | ||
| 7563 | always be NULL, since `subprocesses' isn't defined. | ||
| 7564 | |||
| 7565 | do_display != 0 means redisplay should be done to show subprocess | ||
| 7566 | output that arrives. | ||
| 7567 | |||
| 7568 | Return true if we received input from any process. */ | ||
| 7569 | |||
| 7570 | int | ||
| 7571 | wait_reading_process_output (time_limit, microsecs, read_kbd, do_display, | ||
| 7572 | wait_for_cell, wait_proc, just_wait_proc) | ||
| 7573 | int time_limit, microsecs, read_kbd, do_display; | ||
| 7574 | Lisp_Object wait_for_cell; | ||
| 7575 | struct Lisp_Process *wait_proc; | ||
| 7576 | int just_wait_proc; | ||
| 7577 | { | ||
| 7578 | register int nfds; | ||
| 7579 | EMACS_TIME end_time, timeout; | ||
| 7580 | SELECT_TYPE waitchannels; | ||
| 7581 | int xerrno; | ||
| 7582 | |||
| 7583 | /* What does time_limit really mean? */ | ||
| 7584 | if (time_limit || microsecs) | ||
| 7585 | { | ||
| 7586 | EMACS_GET_TIME (end_time); | ||
| 7587 | EMACS_SET_SECS_USECS (timeout, time_limit, microsecs); | ||
| 7588 | EMACS_ADD_TIME (end_time, end_time, timeout); | ||
| 7589 | } | ||
| 7590 | |||
| 7591 | /* Turn off periodic alarms (in case they are in use) | ||
| 7592 | and then turn off any other atimers, | ||
| 7593 | because the select emulator uses alarms. */ | ||
| 7594 | stop_polling (); | ||
| 7595 | turn_on_atimers (0); | ||
| 7596 | |||
| 7597 | while (1) | ||
| 7598 | { | ||
| 7599 | int timeout_reduced_for_timers = 0; | ||
| 7600 | |||
| 7601 | /* If calling from keyboard input, do not quit | ||
| 7602 | since we want to return C-g as an input character. | ||
| 7603 | Otherwise, do pending quit if requested. */ | ||
| 7604 | if (read_kbd >= 0) | ||
| 7605 | QUIT; | ||
| 7606 | 7763 | ||
| 7607 | /* Exit now if the cell we're waiting for became non-nil. */ | 7764 | #endif /* subprocesses */ |
| 7608 | if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell))) | ||
| 7609 | break; | ||
| 7610 | |||
| 7611 | /* Compute time from now till when time limit is up */ | ||
| 7612 | /* Exit if already run out */ | ||
| 7613 | if (time_limit == -1) | ||
| 7614 | { | ||
| 7615 | /* -1 specified for timeout means | ||
| 7616 | gobble output available now | ||
| 7617 | but don't wait at all. */ | ||
| 7618 | |||
| 7619 | EMACS_SET_SECS_USECS (timeout, 0, 0); | ||
| 7620 | } | ||
| 7621 | else if (time_limit || microsecs) | ||
| 7622 | { | ||
| 7623 | EMACS_GET_TIME (timeout); | ||
| 7624 | EMACS_SUB_TIME (timeout, end_time, timeout); | ||
| 7625 | if (EMACS_TIME_NEG_P (timeout)) | ||
| 7626 | break; | ||
| 7627 | } | ||
| 7628 | else | ||
| 7629 | { | ||
| 7630 | EMACS_SET_SECS_USECS (timeout, 100000, 0); | ||
| 7631 | } | ||
| 7632 | |||
| 7633 | /* If our caller will not immediately handle keyboard events, | ||
| 7634 | run timer events directly. | ||
| 7635 | (Callers that will immediately read keyboard events | ||
| 7636 | call timer_delay on their own.) */ | ||
| 7637 | if (NILP (wait_for_cell)) | ||
| 7638 | { | ||
| 7639 | EMACS_TIME timer_delay; | ||
| 7640 | |||
| 7641 | do | ||
| 7642 | { | ||
| 7643 | int old_timers_run = timers_run; | ||
| 7644 | timer_delay = timer_check (1); | ||
| 7645 | if (timers_run != old_timers_run && do_display) | ||
| 7646 | /* We must retry, since a timer may have requeued itself | ||
| 7647 | and that could alter the time delay. */ | ||
| 7648 | redisplay_preserve_echo_area (14); | ||
| 7649 | else | ||
| 7650 | break; | ||
| 7651 | } | ||
| 7652 | while (!detect_input_pending ()); | ||
| 7653 | |||
| 7654 | /* If there is unread keyboard input, also return. */ | ||
| 7655 | if (read_kbd != 0 | ||
| 7656 | && requeued_events_pending_p ()) | ||
| 7657 | break; | ||
| 7658 | |||
| 7659 | if (! EMACS_TIME_NEG_P (timer_delay) && time_limit != -1) | ||
| 7660 | { | ||
| 7661 | EMACS_TIME difference; | ||
| 7662 | EMACS_SUB_TIME (difference, timer_delay, timeout); | ||
| 7663 | if (EMACS_TIME_NEG_P (difference)) | ||
| 7664 | { | ||
| 7665 | timeout = timer_delay; | ||
| 7666 | timeout_reduced_for_timers = 1; | ||
| 7667 | } | ||
| 7668 | } | ||
| 7669 | } | ||
| 7670 | |||
| 7671 | /* Cause C-g and alarm signals to take immediate action, | ||
| 7672 | and cause input available signals to zero out timeout. */ | ||
| 7673 | if (read_kbd < 0) | ||
| 7674 | set_waiting_for_input (&timeout); | ||
| 7675 | |||
| 7676 | /* Wait till there is something to do. */ | ||
| 7677 | |||
| 7678 | if (! read_kbd && NILP (wait_for_cell)) | ||
| 7679 | FD_ZERO (&waitchannels); | ||
| 7680 | else | ||
| 7681 | FD_SET (0, &waitchannels); | ||
| 7682 | |||
| 7683 | /* If a frame has been newly mapped and needs updating, | ||
| 7684 | reprocess its display stuff. */ | ||
| 7685 | if (frame_garbaged && do_display) | ||
| 7686 | { | ||
| 7687 | clear_waiting_for_input (); | ||
| 7688 | redisplay_preserve_echo_area (15); | ||
| 7689 | if (read_kbd < 0) | ||
| 7690 | set_waiting_for_input (&timeout); | ||
| 7691 | } | ||
| 7692 | |||
| 7693 | if (read_kbd && detect_input_pending ()) | ||
| 7694 | { | ||
| 7695 | nfds = 0; | ||
| 7696 | FD_ZERO (&waitchannels); | ||
| 7697 | } | ||
| 7698 | else | ||
| 7699 | nfds = select (1, &waitchannels, (SELECT_TYPE *)0, (SELECT_TYPE *)0, | ||
| 7700 | &timeout); | ||
| 7701 | |||
| 7702 | xerrno = errno; | ||
| 7703 | |||
| 7704 | /* Make C-g and alarm signals set flags again */ | ||
| 7705 | clear_waiting_for_input (); | ||
| 7706 | |||
| 7707 | /* If we woke up due to SIGWINCH, actually change size now. */ | ||
| 7708 | do_pending_window_change (0); | ||
| 7709 | |||
| 7710 | if (time_limit && nfds == 0 && ! timeout_reduced_for_timers) | ||
| 7711 | /* We waited the full specified time, so return now. */ | ||
| 7712 | break; | ||
| 7713 | |||
| 7714 | if (nfds == -1) | ||
| 7715 | { | ||
| 7716 | /* If the system call was interrupted, then go around the | ||
| 7717 | loop again. */ | ||
| 7718 | if (xerrno == EINTR) | ||
| 7719 | FD_ZERO (&waitchannels); | ||
| 7720 | else | ||
| 7721 | error ("select error: %s", emacs_strerror (xerrno)); | ||
| 7722 | } | ||
| 7723 | #ifdef SOLARIS2 | ||
| 7724 | else if (nfds > 0 && (waitchannels & 1) && interrupt_input) | ||
| 7725 | /* System sometimes fails to deliver SIGIO. */ | ||
| 7726 | kill (getpid (), SIGIO); | ||
| 7727 | #endif | ||
| 7728 | #ifdef SIGIO | ||
| 7729 | if (read_kbd && interrupt_input && (waitchannels & 1)) | ||
| 7730 | kill (getpid (), SIGIO); | ||
| 7731 | #endif | ||
| 7732 | |||
| 7733 | /* Check for keyboard input */ | ||
| 7734 | |||
| 7735 | if (read_kbd | ||
| 7736 | && detect_input_pending_run_timers (do_display)) | ||
| 7737 | { | ||
| 7738 | swallow_events (do_display); | ||
| 7739 | if (detect_input_pending_run_timers (do_display)) | ||
| 7740 | break; | ||
| 7741 | } | ||
| 7742 | |||
| 7743 | /* If there is unread keyboard input, also return. */ | ||
| 7744 | if (read_kbd | ||
| 7745 | && requeued_events_pending_p ()) | ||
| 7746 | break; | ||
| 7747 | |||
| 7748 | /* If wait_for_cell. check for keyboard input | ||
| 7749 | but don't run any timers. | ||
| 7750 | ??? (It seems wrong to me to check for keyboard | ||
| 7751 | input at all when wait_for_cell, but the code | ||
| 7752 | has been this way since July 1994. | ||
| 7753 | Try changing this after version 19.31.) */ | ||
| 7754 | if (! NILP (wait_for_cell) | ||
| 7755 | && detect_input_pending ()) | ||
| 7756 | { | ||
| 7757 | swallow_events (do_display); | ||
| 7758 | if (detect_input_pending ()) | ||
| 7759 | break; | ||
| 7760 | } | ||
| 7761 | |||
| 7762 | /* Exit now if the cell we're waiting for became non-nil. */ | ||
| 7763 | if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell))) | ||
| 7764 | break; | ||
| 7765 | } | ||
| 7766 | |||
| 7767 | start_polling (); | ||
| 7768 | |||
| 7769 | return 0; | ||
| 7770 | } | ||
| 7771 | |||
| 7772 | |||
| 7773 | /* Don't confuse make-docfile by having two doc strings for this function. | ||
| 7774 | make-docfile does not pay attention to #if, for good reason! */ | ||
| 7775 | DEFUN ("get-buffer-process", Fget_buffer_process, Sget_buffer_process, 1, 1, 0, | ||
| 7776 | 0) | ||
| 7777 | (register Lisp_Object name) | ||
| 7778 | { | ||
| 7779 | return Qnil; | ||
| 7780 | } | ||
| 7781 | |||
| 7782 | /* Don't confuse make-docfile by having two doc strings for this function. | ||
| 7783 | make-docfile does not pay attention to #if, for good reason! */ | ||
| 7784 | DEFUN ("process-inherit-coding-system-flag", | ||
| 7785 | Fprocess_inherit_coding_system_flag, Sprocess_inherit_coding_system_flag, | ||
| 7786 | 1, 1, 0, | ||
| 7787 | 0) | ||
| 7788 | (register Lisp_Object process) | ||
| 7789 | { | ||
| 7790 | /* Ignore the argument and return the value of | ||
| 7791 | inherit-process-coding-system. */ | ||
| 7792 | return inherit_process_coding_system ? Qt : Qnil; | ||
| 7793 | } | ||
| 7794 | |||
| 7795 | /* Kill all processes associated with `buffer'. | ||
| 7796 | If `buffer' is nil, kill all processes. | ||
| 7797 | Since we have no subprocesses, this does nothing. */ | ||
| 7798 | |||
| 7799 | void | ||
| 7800 | kill_buffer_processes (buffer) | ||
| 7801 | Lisp_Object buffer; | ||
| 7802 | { | ||
| 7803 | } | ||
| 7804 | |||
| 7805 | |||
| 7806 | /* Stop reading input from keyboard sources. */ | ||
| 7807 | |||
| 7808 | void | ||
| 7809 | hold_keyboard_input (void) | ||
| 7810 | { | ||
| 7811 | kbd_is_on_hold = 1; | ||
| 7812 | } | ||
| 7813 | |||
| 7814 | /* Resume reading input from keyboard sources. */ | ||
| 7815 | |||
| 7816 | void | ||
| 7817 | unhold_keyboard_input (void) | ||
| 7818 | { | ||
| 7819 | kbd_is_on_hold = 0; | ||
| 7820 | } | ||
| 7821 | |||
| 7822 | /* Return non-zero if keyboard input is on hold, zero otherwise. */ | ||
| 7823 | |||
| 7824 | int | ||
| 7825 | kbd_on_hold_p (void) | ||
| 7826 | { | ||
| 7827 | return kbd_is_on_hold; | ||
| 7828 | } | ||
| 7829 | |||
| 7830 | DEFUN ("list-system-processes", Flist_system_processes, Slist_system_processes, | ||
| 7831 | 0, 0, 0, | ||
| 7832 | doc: /* Return a list of numerical process IDs of all running processes. | ||
| 7833 | If this functionality is unsupported, return nil. | ||
| 7834 | |||
| 7835 | See `process-attributes' for getting attributes of a process given its ID. */) | ||
| 7836 | (void) | ||
| 7837 | { | ||
| 7838 | return list_system_processes (); | ||
| 7839 | } | ||
| 7840 | |||
| 7841 | DEFUN ("process-attributes", Fprocess_attributes, | ||
| 7842 | Sprocess_attributes, 1, 1, 0, | ||
| 7843 | doc: /* Return attributes of the process given by its PID, a number. | ||
| 7844 | |||
| 7845 | Value is an alist where each element is a cons cell of the form | ||
| 7846 | |||
| 7847 | \(KEY . VALUE) | ||
| 7848 | |||
| 7849 | If this functionality is unsupported, the value is nil. | ||
| 7850 | |||
| 7851 | See `list-system-processes' for getting a list of all process IDs. | ||
| 7852 | |||
| 7853 | The KEYs of the attributes that this function may return are listed | ||
| 7854 | below, together with the type of the associated VALUE (in parentheses). | ||
| 7855 | Not all platforms support all of these attributes; unsupported | ||
| 7856 | attributes will not appear in the returned alist. | ||
| 7857 | Unless explicitly indicated otherwise, numbers can have either | ||
| 7858 | integer or floating point values. | ||
| 7859 | |||
| 7860 | euid -- Effective user User ID of the process (number) | ||
| 7861 | user -- User name corresponding to euid (string) | ||
| 7862 | egid -- Effective user Group ID of the process (number) | ||
| 7863 | group -- Group name corresponding to egid (string) | ||
| 7864 | comm -- Command name (executable name only) (string) | ||
| 7865 | state -- Process state code, such as "S", "R", or "T" (string) | ||
| 7866 | ppid -- Parent process ID (number) | ||
| 7867 | pgrp -- Process group ID (number) | ||
| 7868 | sess -- Session ID, i.e. process ID of session leader (number) | ||
| 7869 | ttname -- Controlling tty name (string) | ||
| 7870 | tpgid -- ID of foreground process group on the process's tty (number) | ||
| 7871 | minflt -- number of minor page faults (number) | ||
| 7872 | majflt -- number of major page faults (number) | ||
| 7873 | cminflt -- cumulative number of minor page faults (number) | ||
| 7874 | cmajflt -- cumulative number of major page faults (number) | ||
| 7875 | utime -- user time used by the process, in the (HIGH LOW USEC) format | ||
| 7876 | stime -- system time used by the process, in the (HIGH LOW USEC) format | ||
| 7877 | time -- sum of utime and stime, in the (HIGH LOW USEC) format | ||
| 7878 | cutime -- user time used by the process and its children, (HIGH LOW USEC) | ||
| 7879 | cstime -- system time used by the process and its children, (HIGH LOW USEC) | ||
| 7880 | ctime -- sum of cutime and cstime, in the (HIGH LOW USEC) format | ||
| 7881 | pri -- priority of the process (number) | ||
| 7882 | nice -- nice value of the process (number) | ||
| 7883 | thcount -- process thread count (number) | ||
| 7884 | start -- time the process started, in the (HIGH LOW USEC) format | ||
| 7885 | vsize -- virtual memory size of the process in KB's (number) | ||
| 7886 | rss -- resident set size of the process in KB's (number) | ||
| 7887 | etime -- elapsed time the process is running, in (HIGH LOW USEC) format | ||
| 7888 | pcpu -- percents of CPU time used by the process (floating-point number) | ||
| 7889 | pmem -- percents of total physical memory used by process's resident set | ||
| 7890 | (floating-point number) | ||
| 7891 | args -- command line which invoked the process (string). */) | ||
| 7892 | ( Lisp_Object pid) | ||
| 7893 | { | ||
| 7894 | return system_process_attributes (pid); | ||
| 7895 | } | ||
| 7896 | |||
| 7897 | void | ||
| 7898 | init_process () | ||
| 7899 | { | ||
| 7900 | kbd_is_on_hold = 0; | ||
| 7901 | } | ||
| 7902 | |||
| 7903 | void | ||
| 7904 | syms_of_process () | ||
| 7905 | { | ||
| 7906 | QCtype = intern_c_string (":type"); | ||
| 7907 | staticpro (&QCtype); | ||
| 7908 | QCname = intern_c_string (":name"); | ||
| 7909 | staticpro (&QCname); | ||
| 7910 | QCtype = intern_c_string (":type"); | ||
| 7911 | staticpro (&QCtype); | ||
| 7912 | QCname = intern_c_string (":name"); | ||
| 7913 | staticpro (&QCname); | ||
| 7914 | Qeuid = intern_c_string ("euid"); | ||
| 7915 | staticpro (&Qeuid); | ||
| 7916 | Qegid = intern_c_string ("egid"); | ||
| 7917 | staticpro (&Qegid); | ||
| 7918 | Quser = intern_c_string ("user"); | ||
| 7919 | staticpro (&Quser); | ||
| 7920 | Qgroup = intern_c_string ("group"); | ||
| 7921 | staticpro (&Qgroup); | ||
| 7922 | Qcomm = intern_c_string ("comm"); | ||
| 7923 | staticpro (&Qcomm); | ||
| 7924 | Qstate = intern_c_string ("state"); | ||
| 7925 | staticpro (&Qstate); | ||
| 7926 | Qppid = intern_c_string ("ppid"); | ||
| 7927 | staticpro (&Qppid); | ||
| 7928 | Qpgrp = intern_c_string ("pgrp"); | ||
| 7929 | staticpro (&Qpgrp); | ||
| 7930 | Qsess = intern_c_string ("sess"); | ||
| 7931 | staticpro (&Qsess); | ||
| 7932 | Qttname = intern_c_string ("ttname"); | ||
| 7933 | staticpro (&Qttname); | ||
| 7934 | Qtpgid = intern_c_string ("tpgid"); | ||
| 7935 | staticpro (&Qtpgid); | ||
| 7936 | Qminflt = intern_c_string ("minflt"); | ||
| 7937 | staticpro (&Qminflt); | ||
| 7938 | Qmajflt = intern_c_string ("majflt"); | ||
| 7939 | staticpro (&Qmajflt); | ||
| 7940 | Qcminflt = intern_c_string ("cminflt"); | ||
| 7941 | staticpro (&Qcminflt); | ||
| 7942 | Qcmajflt = intern_c_string ("cmajflt"); | ||
| 7943 | staticpro (&Qcmajflt); | ||
| 7944 | Qutime = intern_c_string ("utime"); | ||
| 7945 | staticpro (&Qutime); | ||
| 7946 | Qstime = intern_c_string ("stime"); | ||
| 7947 | staticpro (&Qstime); | ||
| 7948 | Qtime = intern_c_string ("time"); | ||
| 7949 | staticpro (&Qtime); | ||
| 7950 | Qcutime = intern_c_string ("cutime"); | ||
| 7951 | staticpro (&Qcutime); | ||
| 7952 | Qcstime = intern_c_string ("cstime"); | ||
| 7953 | staticpro (&Qcstime); | ||
| 7954 | Qctime = intern_c_string ("ctime"); | ||
| 7955 | staticpro (&Qctime); | ||
| 7956 | Qpri = intern_c_string ("pri"); | ||
| 7957 | staticpro (&Qpri); | ||
| 7958 | Qnice = intern_c_string ("nice"); | ||
| 7959 | staticpro (&Qnice); | ||
| 7960 | Qthcount = intern_c_string ("thcount"); | ||
| 7961 | staticpro (&Qthcount); | ||
| 7962 | Qstart = intern_c_string ("start"); | ||
| 7963 | staticpro (&Qstart); | ||
| 7964 | Qvsize = intern_c_string ("vsize"); | ||
| 7965 | staticpro (&Qvsize); | ||
| 7966 | Qrss = intern_c_string ("rss"); | ||
| 7967 | staticpro (&Qrss); | ||
| 7968 | Qetime = intern_c_string ("etime"); | ||
| 7969 | staticpro (&Qetime); | ||
| 7970 | Qpcpu = intern_c_string ("pcpu"); | ||
| 7971 | staticpro (&Qpcpu); | ||
| 7972 | Qpmem = intern_c_string ("pmem"); | ||
| 7973 | staticpro (&Qpmem); | ||
| 7974 | Qargs = intern_c_string ("args"); | ||
| 7975 | staticpro (&Qargs); | ||
| 7976 | 7765 | ||
| 7977 | defsubr (&Sget_buffer_process); | 7766 | defsubr (&Sget_buffer_process); |
| 7978 | defsubr (&Sprocess_inherit_coding_system_flag); | 7767 | defsubr (&Sprocess_inherit_coding_system_flag); |
| @@ -7980,8 +7769,5 @@ syms_of_process () | |||
| 7980 | defsubr (&Sprocess_attributes); | 7769 | defsubr (&Sprocess_attributes); |
| 7981 | } | 7770 | } |
| 7982 | 7771 | ||
| 7983 | |||
| 7984 | #endif /* not subprocesses */ | ||
| 7985 | |||
| 7986 | /* arch-tag: 3706c011-7b9a-4117-bd4f-59e7f701a4c4 | 7772 | /* arch-tag: 3706c011-7b9a-4117-bd4f-59e7f701a4c4 |
| 7987 | (do not change this comment) */ | 7773 | (do not change this comment) */ |