Mercurial > emacs
comparison src/process.c @ 109353:d43e7dfda4f1
merge trunk
| author | Kenichi Handa <handa@etlken> |
|---|---|
| date | Mon, 12 Jul 2010 11:28:50 +0900 |
| parents | a0d2db31314d |
| children | 5b332381f0a9 |
comparison
equal
deleted
inserted
replaced
| 109352:2803d726899d | 109353:d43e7dfda4f1 |
|---|---|
| 19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | 19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
| 20 | 20 |
| 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> |
| 38 #include <sys/types.h> /* some typedefs are used in sys/file.h */ | 27 #include <sys/types.h> /* some typedefs are used in sys/file.h */ |
| 39 #include <sys/file.h> | 28 #include <sys/file.h> |
| 49 #ifdef HAVE_UNISTD_H | 38 #ifdef HAVE_UNISTD_H |
| 50 #include <unistd.h> | 39 #include <unistd.h> |
| 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> |
| 57 #include <netinet/in.h> | 49 #include <netinet/in.h> |
| 58 #include <arpa/inet.h> | 50 #include <arpa/inet.h> |
| 98 #ifdef HAVE_RES_INIT | 90 #ifdef HAVE_RES_INIT |
| 99 #include <netinet/in.h> | 91 #include <netinet/in.h> |
| 100 #include <arpa/nameser.h> | 92 #include <arpa/nameser.h> |
| 101 #include <resolv.h> | 93 #include <resolv.h> |
| 102 #endif | 94 #endif |
| 95 | |
| 96 #endif /* subprocesses */ | |
| 103 | 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" |
| 107 | 101 |
| 117 #include "keyboard.h" | 111 #include "keyboard.h" |
| 118 #include "blockinput.h" | 112 #include "blockinput.h" |
| 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) */ |
| 123 | |
| 124 #ifdef subprocesses | |
| 126 | 125 |
| 127 Lisp_Object Qprocessp; | 126 Lisp_Object Qprocessp; |
| 128 Lisp_Object Qrun, Qstop, Qsignal; | 127 Lisp_Object Qrun, Qstop, Qsignal; |
| 129 Lisp_Object Qopen, Qclosed, Qconnect, Qfailed, Qlisten; | 128 Lisp_Object Qopen, Qclosed, Qconnect, Qfailed, Qlisten; |
| 130 Lisp_Object Qlocal, Qipv4, Qdatagram, Qseqpacket; | 129 Lisp_Object Qlocal, Qipv4, Qdatagram, Qseqpacket; |
| 133 Lisp_Object Qipv6; | 132 Lisp_Object Qipv6; |
| 134 #endif | 133 #endif |
| 135 Lisp_Object QCport, QCspeed, QCprocess; | 134 Lisp_Object QCport, QCspeed, QCprocess; |
| 136 Lisp_Object QCbytesize, QCstopbits, QCparity, Qodd, Qeven; | 135 Lisp_Object QCbytesize, QCstopbits, QCparity, Qodd, Qeven; |
| 137 Lisp_Object QCflowcontrol, Qhw, Qsw, QCsummary; | 136 Lisp_Object QCflowcontrol, Qhw, Qsw, QCsummary; |
| 138 Lisp_Object QCname, QCbuffer, QChost, QCservice, QCtype; | 137 Lisp_Object QCbuffer, QChost, QCservice; |
| 139 Lisp_Object QClocal, QCremote, QCcoding; | 138 Lisp_Object QClocal, QCremote, QCcoding; |
| 140 Lisp_Object QCserver, QCnowait, QCnoquery, QCstop; | 139 Lisp_Object QCserver, QCnowait, QCnoquery, QCstop; |
| 141 Lisp_Object QCsentinel, QClog, QCoptions, QCplist; | 140 Lisp_Object QCsentinel, QClog, QCoptions, QCplist; |
| 142 Lisp_Object Qlast_nonmenu_event; | 141 Lisp_Object Qlast_nonmenu_event; |
| 143 /* QCfamily is declared and initialized in xfaces.c, | 142 /* QCfamily is declared and initialized in xfaces.c, |
| 148 | 147 |
| 149 /* QCfamily is defined in xfaces.c. */ | 148 /* QCfamily is defined in xfaces.c. */ |
| 150 extern Lisp_Object QCfamily; | 149 extern Lisp_Object QCfamily; |
| 151 /* QCfilter is defined in keyboard.c. */ | 150 /* QCfilter is defined in keyboard.c. */ |
| 152 extern Lisp_Object QCfilter; | 151 extern Lisp_Object QCfilter; |
| 153 | |
| 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 | 152 |
| 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)) |
| 162 #define SERIALCONN_P(p) (EQ (XPROCESS (p)->type, Qserial)) | 156 #define SERIALCONN_P(p) (EQ (XPROCESS (p)->type, Qserial)) |
| 175 testing SIGCHLD. */ | 169 testing SIGCHLD. */ |
| 176 | 170 |
| 177 #if !defined (SIGCHLD) && defined (SIGCLD) | 171 #if !defined (SIGCHLD) && defined (SIGCLD) |
| 178 #define SIGCHLD SIGCLD | 172 #define SIGCHLD SIGCLD |
| 179 #endif /* SIGCLD */ | 173 #endif /* SIGCLD */ |
| 180 | |
| 181 #include "syssignal.h" | |
| 182 | |
| 183 #include "syswait.h" | |
| 184 | 174 |
| 185 extern char *get_operating_system_release (void); | 175 extern char *get_operating_system_release (void); |
| 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) |
| 280 static Lisp_Object Vprocess_adaptive_read_buffering; | 270 static Lisp_Object Vprocess_adaptive_read_buffering; |
| 281 #else | 271 #else |
| 282 #define process_output_delay_count 0 | 272 #define process_output_delay_count 0 |
| 283 #endif | 273 #endif |
| 284 | 274 |
| 285 | |
| 286 #include "sysselect.h" | |
| 287 | |
| 288 static int keyboard_bit_set (SELECT_TYPE *); | 275 static int keyboard_bit_set (SELECT_TYPE *); |
| 289 static void deactivate_process (Lisp_Object); | 276 static void deactivate_process (Lisp_Object); |
| 290 static void status_notify (struct Lisp_Process *); | 277 static void status_notify (struct Lisp_Process *); |
| 291 static int read_process_output (Lisp_Object, int); | 278 static int read_process_output (Lisp_Object, int); |
| 292 static void create_pty (Lisp_Object); | 279 static void create_pty (Lisp_Object); |
| 298 #endif | 285 #endif |
| 299 | 286 |
| 300 static Lisp_Object get_process (register Lisp_Object name); | 287 static Lisp_Object get_process (register Lisp_Object name); |
| 301 static void exec_sentinel (Lisp_Object proc, Lisp_Object reason); | 288 static void exec_sentinel (Lisp_Object proc, Lisp_Object reason); |
| 302 | 289 |
| 290 #endif /* subprocesses */ | |
| 291 | |
| 303 extern int timers_run; | 292 extern int timers_run; |
| 293 | |
| 294 Lisp_Object Qeuid, Qegid, Qcomm, Qstate, Qppid, Qpgrp, Qsess, Qttname, Qtpgid; | |
| 295 Lisp_Object Qminflt, Qmajflt, Qcminflt, Qcmajflt, Qutime, Qstime, Qcstime; | |
| 296 Lisp_Object Qcutime, Qpri, Qnice, Qthcount, Qstart, Qvsize, Qrss, Qargs; | |
| 297 Lisp_Object Quser, Qgroup, Qetime, Qpcpu, Qpmem, Qtime, Qctime; | |
| 298 Lisp_Object QCname, QCtype; | |
| 304 | 299 |
| 300 /* Non-zero if keyboard input is on hold, zero otherwise. */ | |
| 301 | |
| 302 static int kbd_is_on_hold; | |
| 303 | |
| 304 /* Nonzero means delete a process right away if it exits. */ | |
| 305 static int delete_exited_processes; | |
| 306 | |
| 307 #ifdef subprocesses | |
| 308 | |
| 305 /* Mask of bits indicating the descriptors that we wait for input on. */ | 309 /* Mask of bits indicating the descriptors that we wait for input on. */ |
| 306 | 310 |
| 307 static SELECT_TYPE input_wait_mask; | 311 static SELECT_TYPE input_wait_mask; |
| 308 | |
| 309 /* Non-zero if keyboard input is on hold, zero otherwise. */ | |
| 310 | |
| 311 static int kbd_is_on_hold; | |
| 312 | 312 |
| 313 /* Mask that excludes keyboard input descriptor(s). */ | 313 /* Mask that excludes keyboard input descriptor(s). */ |
| 314 | 314 |
| 315 static SELECT_TYPE non_keyboard_wait_mask; | 315 static SELECT_TYPE non_keyboard_wait_mask; |
| 316 | 316 |
| 331 | 331 |
| 332 /* Number of bits set in connect_wait_mask. */ | 332 /* Number of bits set in connect_wait_mask. */ |
| 333 static int num_pending_connects; | 333 static int num_pending_connects; |
| 334 | 334 |
| 335 #define IF_NON_BLOCKING_CONNECT(s) s | 335 #define IF_NON_BLOCKING_CONNECT(s) s |
| 336 #else | 336 #else /* NON_BLOCKING_CONNECT */ |
| 337 #define IF_NON_BLOCKING_CONNECT(s) | 337 #define IF_NON_BLOCKING_CONNECT(s) |
| 338 #endif | 338 #endif /* NON_BLOCKING_CONNECT */ |
| 339 | 339 |
| 340 /* The largest descriptor currently in use for a process object. */ | 340 /* The largest descriptor currently in use for a process object. */ |
| 341 static int max_process_desc; | 341 static int max_process_desc; |
| 342 | 342 |
| 343 /* The largest descriptor currently in use for keyboard input. */ | 343 /* The largest descriptor currently in use for keyboard input. */ |
| 344 static int max_keyboard_desc; | 344 static int max_keyboard_desc; |
| 345 | 345 |
| 346 /* The largest descriptor currently in use for gpm mouse input. */ | 346 /* The largest descriptor currently in use for gpm mouse input. */ |
| 347 static int max_gpm_desc; | 347 static int max_gpm_desc; |
| 348 | |
| 349 /* Nonzero means delete a process right away if it exits. */ | |
| 350 static int delete_exited_processes; | |
| 351 | 348 |
| 352 /* Indexed by descriptor, gives the process (if any) for that descriptor */ | 349 /* Indexed by descriptor, gives the process (if any) for that descriptor */ |
| 353 Lisp_Object chan_process[MAXDESC]; | 350 Lisp_Object chan_process[MAXDESC]; |
| 354 | 351 |
| 355 /* Alist of elements (NAME . PROCESS) */ | 352 /* Alist of elements (NAME . PROCESS) */ |
| 693 return name; | 690 return name; |
| 694 CHECK_STRING (name); | 691 CHECK_STRING (name); |
| 695 return Fcdr (Fassoc (name, Vprocess_alist)); | 692 return Fcdr (Fassoc (name, Vprocess_alist)); |
| 696 } | 693 } |
| 697 | 694 |
| 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 | 695 /* 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. | 696 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 | 697 Buffers denote the first process in the buffer, and nil denotes the |
| 721 current buffer. */ | 698 current buffer. */ |
| 722 | 699 |
| 1092 (register Lisp_Object process, Lisp_Object flag) | 1069 (register Lisp_Object process, Lisp_Object flag) |
| 1093 { | 1070 { |
| 1094 CHECK_PROCESS (process); | 1071 CHECK_PROCESS (process); |
| 1095 XPROCESS (process)->inherit_coding_system_flag = !NILP (flag); | 1072 XPROCESS (process)->inherit_coding_system_flag = !NILP (flag); |
| 1096 return flag; | 1073 return flag; |
| 1097 } | |
| 1098 | |
| 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 } | 1074 } |
| 1111 | 1075 |
| 1112 DEFUN ("set-process-query-on-exit-flag", | 1076 DEFUN ("set-process-query-on-exit-flag", |
| 1113 Fset_process_query_on_exit_flag, Sset_process_query_on_exit_flag, | 1077 Fset_process_query_on_exit_flag, Sset_process_query_on_exit_flag, |
| 1114 2, 2, 0, | 1078 2, 2, 0, |
| 2297 register struct Lisp_Vector *p; | 2261 register struct Lisp_Vector *p; |
| 2298 | 2262 |
| 2299 /* Workaround for a bug in getsockname on BSD: Names bound to | 2263 /* Workaround for a bug in getsockname on BSD: Names bound to |
| 2300 sockets in the UNIX domain are inaccessible; getsockname returns | 2264 sockets in the UNIX domain are inaccessible; getsockname returns |
| 2301 a zero length name. */ | 2265 a zero length name. */ |
| 2302 if (len < OFFSETOF (struct sockaddr, sa_family) + sizeof (sa->sa_family)) | 2266 if (len < offsetof (struct sockaddr, sa_family) + sizeof (sa->sa_family)) |
| 2303 return empty_unibyte_string; | 2267 return empty_unibyte_string; |
| 2304 | 2268 |
| 2305 switch (sa->sa_family) | 2269 switch (sa->sa_family) |
| 2306 { | 2270 { |
| 2307 case AF_INET: | 2271 case AF_INET: |
| 2337 break; | 2301 break; |
| 2338 return make_unibyte_string (sockun->sun_path, i); | 2302 return make_unibyte_string (sockun->sun_path, i); |
| 2339 } | 2303 } |
| 2340 #endif | 2304 #endif |
| 2341 default: | 2305 default: |
| 2342 len -= OFFSETOF (struct sockaddr, sa_family) + sizeof (sa->sa_family); | 2306 len -= offsetof (struct sockaddr, sa_family) + sizeof (sa->sa_family); |
| 2343 address = Fcons (make_number (sa->sa_family), | 2307 address = Fcons (make_number (sa->sa_family), |
| 2344 Fmake_vector (make_number (len), Qnil)); | 2308 Fmake_vector (make_number (len), Qnil)); |
| 2345 p = XVECTOR (XCDR (address)); | 2309 p = XVECTOR (XCDR (address)); |
| 2346 cp = (unsigned char *) &sa->sa_family + sizeof (sa->sa_family); | 2310 cp = (unsigned char *) &sa->sa_family + sizeof (sa->sa_family); |
| 2347 break; | 2311 break; |
| 6472 | 6436 |
| 6473 XPROCESS (proc)->outfd = new_outfd; | 6437 XPROCESS (proc)->outfd = new_outfd; |
| 6474 } | 6438 } |
| 6475 return process; | 6439 return process; |
| 6476 } | 6440 } |
| 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 | 6441 |
| 6500 /* On receipt of a signal that a child status has changed, loop asking | 6442 /* On receipt of a signal that a child status has changed, loop asking |
| 6501 about children with changed statuses until the system says there | 6443 about children with changed statuses until the system says there |
| 6502 are no more. | 6444 are no more. |
| 6503 | 6445 |
| 6958 return (CODING_FOR_UNIBYTE (coding) ? Qnil : Qt); | 6900 return (CODING_FOR_UNIBYTE (coding) ? Qnil : Qt); |
| 6959 } | 6901 } |
| 6960 | 6902 |
| 6961 | 6903 |
| 6962 | 6904 |
| 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 | 6905 |
| 6987 /* Add DESC to the set of keyboard input descriptors. */ | 6906 /* Add DESC to the set of keyboard input descriptors. */ |
| 6988 | 6907 |
| 6989 void | 6908 void |
| 6990 add_keyboard_wait_descriptor (int desc) | 6909 add_keyboard_wait_descriptor (int desc) |
| 7058 && !FD_ISSET (fd, &non_keyboard_wait_mask)) | 6977 && !FD_ISSET (fd, &non_keyboard_wait_mask)) |
| 7059 return 1; | 6978 return 1; |
| 7060 | 6979 |
| 7061 return 0; | 6980 return 0; |
| 7062 } | 6981 } |
| 6982 | |
| 6983 #else /* not subprocesses */ | |
| 6984 | |
| 6985 /* Defined on msdos.c. */ | |
| 6986 extern int sys_select (int, SELECT_TYPE *, SELECT_TYPE *, SELECT_TYPE *, | |
| 6987 EMACS_TIME *); | |
| 6988 | |
| 6989 /* Implementation of wait_reading_process_output, assuming that there | |
| 6990 are no subprocesses. Used only by the MS-DOS build. | |
| 6991 | |
| 6992 Wait for timeout to elapse and/or keyboard input to be available. | |
| 6993 | |
| 6994 time_limit is: | |
| 6995 timeout in seconds, or | |
| 6996 zero for no limit, or | |
| 6997 -1 means gobble data immediately available but don't wait for any. | |
| 6998 | |
| 6999 read_kbd is a Lisp_Object: | |
| 7000 0 to ignore keyboard input, or | |
| 7001 1 to return when input is available, or | |
| 7002 -1 means caller will actually read the input, so don't throw to | |
| 7003 the quit handler. | |
| 7004 | |
| 7005 see full version for other parameters. We know that wait_proc will | |
| 7006 always be NULL, since `subprocesses' isn't defined. | |
| 7007 | |
| 7008 do_display != 0 means redisplay should be done to show subprocess | |
| 7009 output that arrives. | |
| 7010 | |
| 7011 Return true if we received input from any process. */ | |
| 7012 | |
| 7013 int | |
| 7014 wait_reading_process_output (time_limit, microsecs, read_kbd, do_display, | |
| 7015 wait_for_cell, wait_proc, just_wait_proc) | |
| 7016 int time_limit, microsecs, read_kbd, do_display; | |
| 7017 Lisp_Object wait_for_cell; | |
| 7018 struct Lisp_Process *wait_proc; | |
| 7019 int just_wait_proc; | |
| 7020 { | |
| 7021 register int nfds; | |
| 7022 EMACS_TIME end_time, timeout; | |
| 7023 SELECT_TYPE waitchannels; | |
| 7024 int xerrno; | |
| 7025 | |
| 7026 /* What does time_limit really mean? */ | |
| 7027 if (time_limit || microsecs) | |
| 7028 { | |
| 7029 EMACS_GET_TIME (end_time); | |
| 7030 EMACS_SET_SECS_USECS (timeout, time_limit, microsecs); | |
| 7031 EMACS_ADD_TIME (end_time, end_time, timeout); | |
| 7032 } | |
| 7033 | |
| 7034 /* Turn off periodic alarms (in case they are in use) | |
| 7035 and then turn off any other atimers, | |
| 7036 because the select emulator uses alarms. */ | |
| 7037 stop_polling (); | |
| 7038 turn_on_atimers (0); | |
| 7039 | |
| 7040 while (1) | |
| 7041 { | |
| 7042 int timeout_reduced_for_timers = 0; | |
| 7043 | |
| 7044 /* If calling from keyboard input, do not quit | |
| 7045 since we want to return C-g as an input character. | |
| 7046 Otherwise, do pending quit if requested. */ | |
| 7047 if (read_kbd >= 0) | |
| 7048 QUIT; | |
| 7049 | |
| 7050 /* Exit now if the cell we're waiting for became non-nil. */ | |
| 7051 if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell))) | |
| 7052 break; | |
| 7053 | |
| 7054 /* Compute time from now till when time limit is up */ | |
| 7055 /* Exit if already run out */ | |
| 7056 if (time_limit == -1) | |
| 7057 { | |
| 7058 /* -1 specified for timeout means | |
| 7059 gobble output available now | |
| 7060 but don't wait at all. */ | |
| 7061 | |
| 7062 EMACS_SET_SECS_USECS (timeout, 0, 0); | |
| 7063 } | |
| 7064 else if (time_limit || microsecs) | |
| 7065 { | |
| 7066 EMACS_GET_TIME (timeout); | |
| 7067 EMACS_SUB_TIME (timeout, end_time, timeout); | |
| 7068 if (EMACS_TIME_NEG_P (timeout)) | |
| 7069 break; | |
| 7070 } | |
| 7071 else | |
| 7072 { | |
| 7073 EMACS_SET_SECS_USECS (timeout, 100000, 0); | |
| 7074 } | |
| 7075 | |
| 7076 /* If our caller will not immediately handle keyboard events, | |
| 7077 run timer events directly. | |
| 7078 (Callers that will immediately read keyboard events | |
| 7079 call timer_delay on their own.) */ | |
| 7080 if (NILP (wait_for_cell)) | |
| 7081 { | |
| 7082 EMACS_TIME timer_delay; | |
| 7083 | |
| 7084 do | |
| 7085 { | |
| 7086 int old_timers_run = timers_run; | |
| 7087 timer_delay = timer_check (1); | |
| 7088 if (timers_run != old_timers_run && do_display) | |
| 7089 /* We must retry, since a timer may have requeued itself | |
| 7090 and that could alter the time delay. */ | |
| 7091 redisplay_preserve_echo_area (14); | |
| 7092 else | |
| 7093 break; | |
| 7094 } | |
| 7095 while (!detect_input_pending ()); | |
| 7096 | |
| 7097 /* If there is unread keyboard input, also return. */ | |
| 7098 if (read_kbd != 0 | |
| 7099 && requeued_events_pending_p ()) | |
| 7100 break; | |
| 7101 | |
| 7102 if (! EMACS_TIME_NEG_P (timer_delay) && time_limit != -1) | |
| 7103 { | |
| 7104 EMACS_TIME difference; | |
| 7105 EMACS_SUB_TIME (difference, timer_delay, timeout); | |
| 7106 if (EMACS_TIME_NEG_P (difference)) | |
| 7107 { | |
| 7108 timeout = timer_delay; | |
| 7109 timeout_reduced_for_timers = 1; | |
| 7110 } | |
| 7111 } | |
| 7112 } | |
| 7113 | |
| 7114 /* Cause C-g and alarm signals to take immediate action, | |
| 7115 and cause input available signals to zero out timeout. */ | |
| 7116 if (read_kbd < 0) | |
| 7117 set_waiting_for_input (&timeout); | |
| 7118 | |
| 7119 /* Wait till there is something to do. */ | |
| 7120 | |
| 7121 if (! read_kbd && NILP (wait_for_cell)) | |
| 7122 FD_ZERO (&waitchannels); | |
| 7123 else | |
| 7124 FD_SET (0, &waitchannels); | |
| 7125 | |
| 7126 /* If a frame has been newly mapped and needs updating, | |
| 7127 reprocess its display stuff. */ | |
| 7128 if (frame_garbaged && do_display) | |
| 7129 { | |
| 7130 clear_waiting_for_input (); | |
| 7131 redisplay_preserve_echo_area (15); | |
| 7132 if (read_kbd < 0) | |
| 7133 set_waiting_for_input (&timeout); | |
| 7134 } | |
| 7135 | |
| 7136 if (read_kbd && detect_input_pending ()) | |
| 7137 { | |
| 7138 nfds = 0; | |
| 7139 FD_ZERO (&waitchannels); | |
| 7140 } | |
| 7141 else | |
| 7142 nfds = select (1, &waitchannels, (SELECT_TYPE *)0, (SELECT_TYPE *)0, | |
| 7143 &timeout); | |
| 7144 | |
| 7145 xerrno = errno; | |
| 7146 | |
| 7147 /* Make C-g and alarm signals set flags again */ | |
| 7148 clear_waiting_for_input (); | |
| 7149 | |
| 7150 /* If we woke up due to SIGWINCH, actually change size now. */ | |
| 7151 do_pending_window_change (0); | |
| 7152 | |
| 7153 if (time_limit && nfds == 0 && ! timeout_reduced_for_timers) | |
| 7154 /* We waited the full specified time, so return now. */ | |
| 7155 break; | |
| 7156 | |
| 7157 if (nfds == -1) | |
| 7158 { | |
| 7159 /* If the system call was interrupted, then go around the | |
| 7160 loop again. */ | |
| 7161 if (xerrno == EINTR) | |
| 7162 FD_ZERO (&waitchannels); | |
| 7163 else | |
| 7164 error ("select error: %s", emacs_strerror (xerrno)); | |
| 7165 } | |
| 7166 | |
| 7167 /* Check for keyboard input */ | |
| 7168 | |
| 7169 if (read_kbd | |
| 7170 && detect_input_pending_run_timers (do_display)) | |
| 7171 { | |
| 7172 swallow_events (do_display); | |
| 7173 if (detect_input_pending_run_timers (do_display)) | |
| 7174 break; | |
| 7175 } | |
| 7176 | |
| 7177 /* If there is unread keyboard input, also return. */ | |
| 7178 if (read_kbd | |
| 7179 && requeued_events_pending_p ()) | |
| 7180 break; | |
| 7181 | |
| 7182 /* If wait_for_cell. check for keyboard input | |
| 7183 but don't run any timers. | |
| 7184 ??? (It seems wrong to me to check for keyboard | |
| 7185 input at all when wait_for_cell, but the code | |
| 7186 has been this way since July 1994. | |
| 7187 Try changing this after version 19.31.) */ | |
| 7188 if (! NILP (wait_for_cell) | |
| 7189 && detect_input_pending ()) | |
| 7190 { | |
| 7191 swallow_events (do_display); | |
| 7192 if (detect_input_pending ()) | |
| 7193 break; | |
| 7194 } | |
| 7195 | |
| 7196 /* Exit now if the cell we're waiting for became non-nil. */ | |
| 7197 if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell))) | |
| 7198 break; | |
| 7199 } | |
| 7200 | |
| 7201 start_polling (); | |
| 7202 | |
| 7203 return 0; | |
| 7204 } | |
| 7205 | |
| 7206 #endif /* not subprocesses */ | |
| 7207 | |
| 7208 /* The following functions are needed even if async subprocesses are | |
| 7209 not supported. Some of them are no-op stubs in that case. */ | |
| 7210 | |
| 7211 DEFUN ("get-buffer-process", Fget_buffer_process, Sget_buffer_process, 1, 1, 0, | |
| 7212 doc: /* Return the (or a) process associated with BUFFER. | |
| 7213 BUFFER may be a buffer or the name of one. */) | |
| 7214 (register Lisp_Object buffer) | |
| 7215 { | |
| 7216 #ifdef subprocesses | |
| 7217 register Lisp_Object buf, tail, proc; | |
| 7218 | |
| 7219 if (NILP (buffer)) return Qnil; | |
| 7220 buf = Fget_buffer (buffer); | |
| 7221 if (NILP (buf)) return Qnil; | |
| 7222 | |
| 7223 for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) | |
| 7224 { | |
| 7225 proc = Fcdr (XCAR (tail)); | |
| 7226 if (PROCESSP (proc) && EQ (XPROCESS (proc)->buffer, buf)) | |
| 7227 return proc; | |
| 7228 } | |
| 7229 #endif /* subprocesses */ | |
| 7230 return Qnil; | |
| 7231 } | |
| 7232 | |
| 7233 DEFUN ("process-inherit-coding-system-flag", | |
| 7234 Fprocess_inherit_coding_system_flag, Sprocess_inherit_coding_system_flag, | |
| 7235 1, 1, 0, | |
| 7236 doc: /* Return the value of inherit-coding-system flag for PROCESS. | |
| 7237 If this flag is t, `buffer-file-coding-system' of the buffer | |
| 7238 associated with PROCESS will inherit the coding system used to decode | |
| 7239 the process output. */) | |
| 7240 (register Lisp_Object process) | |
| 7241 { | |
| 7242 #ifdef subprocesses | |
| 7243 CHECK_PROCESS (process); | |
| 7244 return XPROCESS (process)->inherit_coding_system_flag ? Qt : Qnil; | |
| 7245 #else | |
| 7246 /* Ignore the argument and return the value of | |
| 7247 inherit-process-coding-system. */ | |
| 7248 return inherit_process_coding_system ? Qt : Qnil; | |
| 7249 #endif | |
| 7250 } | |
| 7251 | |
| 7252 /* Kill all processes associated with `buffer'. | |
| 7253 If `buffer' is nil, kill all processes */ | |
| 7254 | |
| 7255 void | |
| 7256 kill_buffer_processes (Lisp_Object buffer) | |
| 7257 { | |
| 7258 #ifdef subprocesses | |
| 7259 Lisp_Object tail, proc; | |
| 7260 | |
| 7261 for (tail = Vprocess_alist; CONSP (tail); tail = XCDR (tail)) | |
| 7262 { | |
| 7263 proc = XCDR (XCAR (tail)); | |
| 7264 if (PROCESSP (proc) | |
| 7265 && (NILP (buffer) || EQ (XPROCESS (proc)->buffer, buffer))) | |
| 7266 { | |
| 7267 if (NETCONN_P (proc) || SERIALCONN_P (proc)) | |
| 7268 Fdelete_process (proc); | |
| 7269 else if (XPROCESS (proc)->infd >= 0) | |
| 7270 process_send_signal (proc, SIGHUP, Qnil, 1); | |
| 7271 } | |
| 7272 } | |
| 7273 #else /* subprocesses */ | |
| 7274 /* Since we have no subprocesses, this does nothing. */ | |
| 7275 #endif /* subprocesses */ | |
| 7276 } | |
| 7277 | |
| 7278 /* Stop reading input from keyboard sources. */ | |
| 7279 | |
| 7280 void | |
| 7281 hold_keyboard_input (void) | |
| 7282 { | |
| 7283 kbd_is_on_hold = 1; | |
| 7284 } | |
| 7285 | |
| 7286 /* Resume reading input from keyboard sources. */ | |
| 7287 | |
| 7288 void | |
| 7289 unhold_keyboard_input (void) | |
| 7290 { | |
| 7291 kbd_is_on_hold = 0; | |
| 7292 } | |
| 7293 | |
| 7294 /* Return non-zero if keyboard input is on hold, zero otherwise. */ | |
| 7295 | |
| 7296 int | |
| 7297 kbd_on_hold_p (void) | |
| 7298 { | |
| 7299 return kbd_is_on_hold; | |
| 7300 } | |
| 7301 | |
| 7063 | 7302 |
| 7064 /* Enumeration of and access to system processes a-la ps(1). */ | 7303 /* Enumeration of and access to system processes a-la ps(1). */ |
| 7065 | 7304 |
| 7066 DEFUN ("list-system-processes", Flist_system_processes, Slist_system_processes, | 7305 DEFUN ("list-system-processes", Flist_system_processes, Slist_system_processes, |
| 7067 0, 0, 0, | 7306 0, 0, 0, |
| 7127 args -- command line which invoked the process (string). */) | 7366 args -- command line which invoked the process (string). */) |
| 7128 ( Lisp_Object pid) | 7367 ( Lisp_Object pid) |
| 7129 { | 7368 { |
| 7130 return system_process_attributes (pid); | 7369 return system_process_attributes (pid); |
| 7131 } | 7370 } |
| 7371 | |
| 7132 | 7372 |
| 7133 void | 7373 void |
| 7134 init_process (void) | 7374 init_process (void) |
| 7135 { | 7375 { |
| 7376 #ifdef subprocesses | |
| 7136 register int i; | 7377 register int i; |
| 7137 | 7378 |
| 7138 inhibit_sentinels = 0; | 7379 inhibit_sentinels = 0; |
| 7139 | 7380 |
| 7140 #ifdef SIGCHLD | 7381 #ifdef SIGCHLD |
| 7229 && release[1] == '.')) { | 7470 && release[1] == '.')) { |
| 7230 Vprocess_connection_type = Qnil; | 7471 Vprocess_connection_type = Qnil; |
| 7231 } | 7472 } |
| 7232 } | 7473 } |
| 7233 #endif | 7474 #endif |
| 7475 #endif /* subprocesses */ | |
| 7476 kbd_is_on_hold = 0; | |
| 7234 } | 7477 } |
| 7235 | 7478 |
| 7236 void | 7479 void |
| 7237 syms_of_process (void) | 7480 syms_of_process (void) |
| 7238 { | 7481 { |
| 7482 #ifdef subprocesses | |
| 7483 | |
| 7239 Qprocessp = intern_c_string ("processp"); | 7484 Qprocessp = intern_c_string ("processp"); |
| 7240 staticpro (&Qprocessp); | 7485 staticpro (&Qprocessp); |
| 7241 Qrun = intern_c_string ("run"); | 7486 Qrun = intern_c_string ("run"); |
| 7242 staticpro (&Qrun); | 7487 staticpro (&Qrun); |
| 7243 Qstop = intern_c_string ("stop"); | 7488 Qstop = intern_c_string ("stop"); |
| 7304 staticpro (&Qreal); | 7549 staticpro (&Qreal); |
| 7305 Qnetwork = intern_c_string ("network"); | 7550 Qnetwork = intern_c_string ("network"); |
| 7306 staticpro (&Qnetwork); | 7551 staticpro (&Qnetwork); |
| 7307 Qserial = intern_c_string ("serial"); | 7552 Qserial = intern_c_string ("serial"); |
| 7308 staticpro (&Qserial); | 7553 staticpro (&Qserial); |
| 7309 | |
| 7310 QCname = intern_c_string (":name"); | |
| 7311 staticpro (&QCname); | |
| 7312 QCbuffer = intern_c_string (":buffer"); | 7554 QCbuffer = intern_c_string (":buffer"); |
| 7313 staticpro (&QCbuffer); | 7555 staticpro (&QCbuffer); |
| 7314 QChost = intern_c_string (":host"); | 7556 QChost = intern_c_string (":host"); |
| 7315 staticpro (&QChost); | 7557 staticpro (&QChost); |
| 7316 QCservice = intern_c_string (":service"); | 7558 QCservice = intern_c_string (":service"); |
| 7317 staticpro (&QCservice); | 7559 staticpro (&QCservice); |
| 7318 QCtype = intern_c_string (":type"); | |
| 7319 staticpro (&QCtype); | |
| 7320 QClocal = intern_c_string (":local"); | 7560 QClocal = intern_c_string (":local"); |
| 7321 staticpro (&QClocal); | 7561 staticpro (&QClocal); |
| 7322 QCremote = intern_c_string (":remote"); | 7562 QCremote = intern_c_string (":remote"); |
| 7323 staticpro (&QCremote); | 7563 staticpro (&QCremote); |
| 7324 QCcoding = intern_c_string (":coding"); | 7564 QCcoding = intern_c_string (":coding"); |
| 7345 | 7585 |
| 7346 staticpro (&Vprocess_alist); | 7586 staticpro (&Vprocess_alist); |
| 7347 #ifdef SIGCHLD | 7587 #ifdef SIGCHLD |
| 7348 staticpro (&deleted_pid_list); | 7588 staticpro (&deleted_pid_list); |
| 7349 #endif | 7589 #endif |
| 7590 | |
| 7591 #endif /* subprocesses */ | |
| 7592 | |
| 7593 QCname = intern_c_string (":name"); | |
| 7594 staticpro (&QCname); | |
| 7595 QCtype = intern_c_string (":type"); | |
| 7596 staticpro (&QCtype); | |
| 7350 | 7597 |
| 7351 Qeuid = intern_c_string ("euid"); | 7598 Qeuid = intern_c_string ("euid"); |
| 7352 staticpro (&Qeuid); | 7599 staticpro (&Qeuid); |
| 7353 Qegid = intern_c_string ("egid"); | 7600 Qegid = intern_c_string ("egid"); |
| 7354 staticpro (&Qegid); | 7601 staticpro (&Qegid); |
| 7415 doc: /* *Non-nil means delete processes immediately when they exit. | 7662 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. */); | 7663 A value of nil means don't delete them until `list-processes' is run. */); |
| 7417 | 7664 |
| 7418 delete_exited_processes = 1; | 7665 delete_exited_processes = 1; |
| 7419 | 7666 |
| 7667 #ifdef subprocesses | |
| 7420 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type, | 7668 DEFVAR_LISP ("process-connection-type", &Vprocess_connection_type, |
| 7421 doc: /* Control type of device used to communicate with subprocesses. | 7669 doc: /* Control type of device used to communicate with subprocesses. |
| 7422 Values are nil to use a pipe, or t or `pty' to use a pty. | 7670 Values are nil to use a pipe, or t or `pty' to use a pty. |
| 7423 The value has no effect if the system has no ptys or if all ptys are busy: | 7671 The value has no effect if the system has no ptys or if all ptys are busy: |
| 7424 then a pipe is used in any case. | 7672 then a pipe is used in any case. |
| 7439 Vprocess_adaptive_read_buffering = Qt; | 7687 Vprocess_adaptive_read_buffering = Qt; |
| 7440 #endif | 7688 #endif |
| 7441 | 7689 |
| 7442 defsubr (&Sprocessp); | 7690 defsubr (&Sprocessp); |
| 7443 defsubr (&Sget_process); | 7691 defsubr (&Sget_process); |
| 7444 defsubr (&Sget_buffer_process); | |
| 7445 defsubr (&Sdelete_process); | 7692 defsubr (&Sdelete_process); |
| 7446 defsubr (&Sprocess_status); | 7693 defsubr (&Sprocess_status); |
| 7447 defsubr (&Sprocess_exit_status); | 7694 defsubr (&Sprocess_exit_status); |
| 7448 defsubr (&Sprocess_id); | 7695 defsubr (&Sprocess_id); |
| 7449 defsubr (&Sprocess_name); | 7696 defsubr (&Sprocess_name); |
| 7456 defsubr (&Sprocess_filter); | 7703 defsubr (&Sprocess_filter); |
| 7457 defsubr (&Sset_process_sentinel); | 7704 defsubr (&Sset_process_sentinel); |
| 7458 defsubr (&Sprocess_sentinel); | 7705 defsubr (&Sprocess_sentinel); |
| 7459 defsubr (&Sset_process_window_size); | 7706 defsubr (&Sset_process_window_size); |
| 7460 defsubr (&Sset_process_inherit_coding_system_flag); | 7707 defsubr (&Sset_process_inherit_coding_system_flag); |
| 7461 defsubr (&Sprocess_inherit_coding_system_flag); | |
| 7462 defsubr (&Sset_process_query_on_exit_flag); | 7708 defsubr (&Sset_process_query_on_exit_flag); |
| 7463 defsubr (&Sprocess_query_on_exit_flag); | 7709 defsubr (&Sprocess_query_on_exit_flag); |
| 7464 defsubr (&Sprocess_contact); | 7710 defsubr (&Sprocess_contact); |
| 7465 defsubr (&Sprocess_plist); | 7711 defsubr (&Sprocess_plist); |
| 7466 defsubr (&Sset_process_plist); | 7712 defsubr (&Sset_process_plist); |
| 7503 defsubr (&Sprocess_type); | 7749 defsubr (&Sprocess_type); |
| 7504 defsubr (&Sset_process_coding_system); | 7750 defsubr (&Sset_process_coding_system); |
| 7505 defsubr (&Sprocess_coding_system); | 7751 defsubr (&Sprocess_coding_system); |
| 7506 defsubr (&Sset_process_filter_multibyte); | 7752 defsubr (&Sset_process_filter_multibyte); |
| 7507 defsubr (&Sprocess_filter_multibyte_p); | 7753 defsubr (&Sprocess_filter_multibyte_p); |
| 7508 defsubr (&Slist_system_processes); | 7754 |
| 7509 defsubr (&Sprocess_attributes); | 7755 #endif /* subprocesses */ |
| 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 | |
| 7607 /* Exit now if the cell we're waiting for became non-nil. */ | |
| 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 | 7756 |
| 7977 defsubr (&Sget_buffer_process); | 7757 defsubr (&Sget_buffer_process); |
| 7978 defsubr (&Sprocess_inherit_coding_system_flag); | 7758 defsubr (&Sprocess_inherit_coding_system_flag); |
| 7979 defsubr (&Slist_system_processes); | 7759 defsubr (&Slist_system_processes); |
| 7980 defsubr (&Sprocess_attributes); | 7760 defsubr (&Sprocess_attributes); |
| 7981 } | 7761 } |
| 7982 | 7762 |
| 7983 | |
| 7984 #endif /* not subprocesses */ | |
| 7985 | |
| 7986 /* arch-tag: 3706c011-7b9a-4117-bd4f-59e7f701a4c4 | 7763 /* arch-tag: 3706c011-7b9a-4117-bd4f-59e7f701a4c4 |
| 7987 (do not change this comment) */ | 7764 (do not change this comment) */ |
