diff options
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 122 |
1 files changed, 64 insertions, 58 deletions
diff --git a/src/process.c b/src/process.c index 5006c85fe9d..592c43acc2d 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -224,8 +224,9 @@ static EMACS_INT update_tick; | |||
| 224 | /* Only W32 has this, it really means that select can't take write mask. */ | 224 | /* Only W32 has this, it really means that select can't take write mask. */ |
| 225 | #ifdef BROKEN_NON_BLOCKING_CONNECT | 225 | #ifdef BROKEN_NON_BLOCKING_CONNECT |
| 226 | #undef NON_BLOCKING_CONNECT | 226 | #undef NON_BLOCKING_CONNECT |
| 227 | #define SELECT_CANT_DO_WRITE_MASK | 227 | enum { SELECT_CAN_DO_WRITE_MASK = false }; |
| 228 | #else | 228 | #else |
| 229 | enum { SELECT_CAN_DO_WRITE_MASK = true }; | ||
| 229 | #ifndef NON_BLOCKING_CONNECT | 230 | #ifndef NON_BLOCKING_CONNECT |
| 230 | #ifdef HAVE_SELECT | 231 | #ifdef HAVE_SELECT |
| 231 | #if defined (HAVE_GETPEERNAME) || defined (GNU_LINUX) | 232 | #if defined (HAVE_GETPEERNAME) || defined (GNU_LINUX) |
| @@ -281,7 +282,7 @@ static void create_process (Lisp_Object, char **, Lisp_Object); | |||
| 281 | static bool keyboard_bit_set (fd_set *); | 282 | static bool keyboard_bit_set (fd_set *); |
| 282 | #endif | 283 | #endif |
| 283 | static void deactivate_process (Lisp_Object); | 284 | static void deactivate_process (Lisp_Object); |
| 284 | static void status_notify (struct Lisp_Process *); | 285 | static int status_notify (struct Lisp_Process *, struct Lisp_Process *); |
| 285 | static int read_process_output (Lisp_Object, int); | 286 | static int read_process_output (Lisp_Object, int); |
| 286 | static void handle_child_signal (int); | 287 | static void handle_child_signal (int); |
| 287 | static void create_pty (Lisp_Object); | 288 | static void create_pty (Lisp_Object); |
| @@ -860,7 +861,7 @@ nil, indicating the current buffer's process. */) | |||
| 860 | { | 861 | { |
| 861 | pset_status (p, list2 (Qexit, make_number (0))); | 862 | pset_status (p, list2 (Qexit, make_number (0))); |
| 862 | p->tick = ++process_tick; | 863 | p->tick = ++process_tick; |
| 863 | status_notify (p); | 864 | status_notify (p, NULL); |
| 864 | redisplay_preserve_echo_area (13); | 865 | redisplay_preserve_echo_area (13); |
| 865 | } | 866 | } |
| 866 | else | 867 | else |
| @@ -880,7 +881,7 @@ nil, indicating the current buffer's process. */) | |||
| 880 | pset_status (p, list2 (Qsignal, make_number (SIGKILL))); | 881 | pset_status (p, list2 (Qsignal, make_number (SIGKILL))); |
| 881 | 882 | ||
| 882 | p->tick = ++process_tick; | 883 | p->tick = ++process_tick; |
| 883 | status_notify (p); | 884 | status_notify (p, NULL); |
| 884 | redisplay_preserve_echo_area (13); | 885 | redisplay_preserve_echo_area (13); |
| 885 | } | 886 | } |
| 886 | } | 887 | } |
| @@ -3986,12 +3987,13 @@ is nil, from any process) before the timeout expired. */) | |||
| 3986 | nsecs = 0; | 3987 | nsecs = 0; |
| 3987 | 3988 | ||
| 3988 | return | 3989 | return |
| 3989 | (wait_reading_process_output (secs, nsecs, 0, 0, | 3990 | ((wait_reading_process_output (secs, nsecs, 0, 0, |
| 3990 | Qnil, | 3991 | Qnil, |
| 3991 | !NILP (process) ? XPROCESS (process) : NULL, | 3992 | !NILP (process) ? XPROCESS (process) : NULL, |
| 3992 | NILP (just_this_one) ? 0 : | 3993 | NILP (just_this_one) ? 0 : |
| 3993 | !INTEGERP (just_this_one) ? 1 : -1) | 3994 | !INTEGERP (just_this_one) ? 1 : -1) |
| 3994 | ? Qt : Qnil); | 3995 | <= 0) |
| 3996 | ? Qnil : Qt); | ||
| 3995 | } | 3997 | } |
| 3996 | 3998 | ||
| 3997 | /* Accept a connection for server process SERVER on CHANNEL. */ | 3999 | /* Accept a connection for server process SERVER on CHANNEL. */ |
| @@ -4262,10 +4264,11 @@ wait_reading_process_output_1 (void) | |||
| 4262 | (suspending output from other processes). A negative value | 4264 | (suspending output from other processes). A negative value |
| 4263 | means don't run any timers either. | 4265 | means don't run any timers either. |
| 4264 | 4266 | ||
| 4265 | Return true if we received input from WAIT_PROC, or from any | 4267 | Return positive if we received input from WAIT_PROC (or from any |
| 4266 | process if WAIT_PROC is null. */ | 4268 | process if WAIT_PROC is null), zero if we attempted to receive |
| 4269 | input but got none, and negative if we didn't even try. */ | ||
| 4267 | 4270 | ||
| 4268 | bool | 4271 | int |
| 4269 | wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | 4272 | wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, |
| 4270 | bool do_display, | 4273 | bool do_display, |
| 4271 | Lisp_Object wait_for_cell, | 4274 | Lisp_Object wait_for_cell, |
| @@ -4280,8 +4283,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4280 | int xerrno; | 4283 | int xerrno; |
| 4281 | Lisp_Object proc; | 4284 | Lisp_Object proc; |
| 4282 | struct timespec timeout, end_time; | 4285 | struct timespec timeout, end_time; |
| 4283 | int wait_channel = -1; | 4286 | int got_some_input = -1; |
| 4284 | bool got_some_input = 0; | ||
| 4285 | ptrdiff_t count = SPECPDL_INDEX (); | 4287 | ptrdiff_t count = SPECPDL_INDEX (); |
| 4286 | 4288 | ||
| 4287 | FD_ZERO (&Available); | 4289 | FD_ZERO (&Available); |
| @@ -4292,10 +4294,6 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4292 | && EQ (XCAR (wait_proc->status), Qexit))) | 4294 | && EQ (XCAR (wait_proc->status), Qexit))) |
| 4293 | message1 ("Blocking call to accept-process-output with quit inhibited!!"); | 4295 | message1 ("Blocking call to accept-process-output with quit inhibited!!"); |
| 4294 | 4296 | ||
| 4295 | /* If wait_proc is a process to watch, set wait_channel accordingly. */ | ||
| 4296 | if (wait_proc != NULL) | ||
| 4297 | wait_channel = wait_proc->infd; | ||
| 4298 | |||
| 4299 | record_unwind_protect_int (wait_reading_process_output_unwind, | 4297 | record_unwind_protect_int (wait_reading_process_output_unwind, |
| 4300 | waiting_for_user_input_p); | 4298 | waiting_for_user_input_p); |
| 4301 | waiting_for_user_input_p = read_kbd; | 4299 | waiting_for_user_input_p = read_kbd; |
| @@ -4332,6 +4330,10 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4332 | if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell))) | 4330 | if (! NILP (wait_for_cell) && ! NILP (XCAR (wait_for_cell))) |
| 4333 | break; | 4331 | break; |
| 4334 | 4332 | ||
| 4333 | /* After reading input, vacuum up any leftovers without waiting. */ | ||
| 4334 | if (0 <= got_some_input) | ||
| 4335 | nsecs = -1; | ||
| 4336 | |||
| 4335 | /* Compute time from now till when time limit is up. */ | 4337 | /* Compute time from now till when time limit is up. */ |
| 4336 | /* Exit if already run out. */ | 4338 | /* Exit if already run out. */ |
| 4337 | if (nsecs < 0) | 4339 | if (nsecs < 0) |
| @@ -4450,7 +4452,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4450 | /* It's okay for us to do this and then continue with | 4452 | /* It's okay for us to do this and then continue with |
| 4451 | the loop, since timeout has already been zeroed out. */ | 4453 | the loop, since timeout has already been zeroed out. */ |
| 4452 | clear_waiting_for_input (); | 4454 | clear_waiting_for_input (); |
| 4453 | status_notify (NULL); | 4455 | got_some_input = status_notify (NULL, wait_proc); |
| 4454 | if (do_display) redisplay_preserve_echo_area (13); | 4456 | if (do_display) redisplay_preserve_echo_area (13); |
| 4455 | } | 4457 | } |
| 4456 | } | 4458 | } |
| @@ -4472,18 +4474,23 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4472 | while (wait_proc->infd >= 0) | 4474 | while (wait_proc->infd >= 0) |
| 4473 | { | 4475 | { |
| 4474 | int nread = read_process_output (proc, wait_proc->infd); | 4476 | int nread = read_process_output (proc, wait_proc->infd); |
| 4475 | 4477 | if (nread < 0) | |
| 4476 | if (nread == 0) | 4478 | { |
| 4477 | break; | 4479 | if (errno == EIO || errno == EAGAIN) |
| 4478 | 4480 | break; | |
| 4479 | if (nread > 0) | ||
| 4480 | got_some_input = read_some_bytes = 1; | ||
| 4481 | else if (nread == -1 && (errno == EIO || errno == EAGAIN)) | ||
| 4482 | break; | ||
| 4483 | #ifdef EWOULDBLOCK | 4481 | #ifdef EWOULDBLOCK |
| 4484 | else if (nread == -1 && EWOULDBLOCK == errno) | 4482 | if (errno == EWOULDBLOCK) |
| 4485 | break; | 4483 | break; |
| 4486 | #endif | 4484 | #endif |
| 4485 | } | ||
| 4486 | else | ||
| 4487 | { | ||
| 4488 | if (got_some_input < nread) | ||
| 4489 | got_some_input = nread; | ||
| 4490 | if (nread == 0) | ||
| 4491 | break; | ||
| 4492 | read_some_bytes = true; | ||
| 4493 | } | ||
| 4487 | } | 4494 | } |
| 4488 | if (read_some_bytes && do_display) | 4495 | if (read_some_bytes && do_display) |
| 4489 | redisplay_preserve_echo_area (10); | 4496 | redisplay_preserve_echo_area (10); |
| @@ -4514,12 +4521,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4514 | else | 4521 | else |
| 4515 | Available = input_wait_mask; | 4522 | Available = input_wait_mask; |
| 4516 | Writeok = write_mask; | 4523 | Writeok = write_mask; |
| 4517 | #ifdef SELECT_CANT_DO_WRITE_MASK | 4524 | check_delay = wait_proc ? 0 : process_output_delay_count; |
| 4518 | check_write = 0; | 4525 | check_write = SELECT_CAN_DO_WRITE_MASK; |
| 4519 | #else | ||
| 4520 | check_write = 1; | ||
| 4521 | #endif | ||
| 4522 | check_delay = wait_channel >= 0 ? 0 : process_output_delay_count; | ||
| 4523 | } | 4526 | } |
| 4524 | 4527 | ||
| 4525 | /* If frame size has changed or the window is newly mapped, | 4528 | /* If frame size has changed or the window is newly mapped, |
| @@ -4545,6 +4548,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4545 | { | 4548 | { |
| 4546 | nfds = read_kbd ? 0 : 1; | 4549 | nfds = read_kbd ? 0 : 1; |
| 4547 | no_avail = 1; | 4550 | no_avail = 1; |
| 4551 | FD_ZERO (&Available); | ||
| 4548 | } | 4552 | } |
| 4549 | 4553 | ||
| 4550 | if (!no_avail) | 4554 | if (!no_avail) |
| @@ -4554,7 +4558,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4554 | /* Set the timeout for adaptive read buffering if any | 4558 | /* Set the timeout for adaptive read buffering if any |
| 4555 | process has non-zero read_output_skip and non-zero | 4559 | process has non-zero read_output_skip and non-zero |
| 4556 | read_output_delay, and we are not reading output for a | 4560 | read_output_delay, and we are not reading output for a |
| 4557 | specific wait_channel. It is not executed if | 4561 | specific process. It is not executed if |
| 4558 | Vprocess_adaptive_read_buffering is nil. */ | 4562 | Vprocess_adaptive_read_buffering is nil. */ |
| 4559 | if (process_output_skip && check_delay > 0) | 4563 | if (process_output_skip && check_delay > 0) |
| 4560 | { | 4564 | { |
| @@ -4667,12 +4671,6 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4667 | report_file_errno ("Failed select", Qnil, xerrno); | 4671 | report_file_errno ("Failed select", Qnil, xerrno); |
| 4668 | } | 4672 | } |
| 4669 | 4673 | ||
| 4670 | if (no_avail) | ||
| 4671 | { | ||
| 4672 | FD_ZERO (&Available); | ||
| 4673 | check_write = 0; | ||
| 4674 | } | ||
| 4675 | |||
| 4676 | /* Check for keyboard input */ | 4674 | /* Check for keyboard input */ |
| 4677 | /* If there is any, return immediately | 4675 | /* If there is any, return immediately |
| 4678 | to give it higher priority than subprocesses */ | 4676 | to give it higher priority than subprocesses */ |
| @@ -4739,9 +4737,6 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4739 | handle_input_available_signal (SIGIO); | 4737 | handle_input_available_signal (SIGIO); |
| 4740 | #endif | 4738 | #endif |
| 4741 | 4739 | ||
| 4742 | if (! wait_proc) | ||
| 4743 | got_some_input |= nfds > 0; | ||
| 4744 | |||
| 4745 | /* If checking input just got us a size-change event from X, | 4740 | /* If checking input just got us a size-change event from X, |
| 4746 | obey it now if we should. */ | 4741 | obey it now if we should. */ |
| 4747 | if (read_kbd || ! NILP (wait_for_cell)) | 4742 | if (read_kbd || ! NILP (wait_for_cell)) |
| @@ -4773,12 +4768,6 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4773 | /* If waiting for this channel, arrange to return as | 4768 | /* If waiting for this channel, arrange to return as |
| 4774 | soon as no more input to be processed. No more | 4769 | soon as no more input to be processed. No more |
| 4775 | waiting. */ | 4770 | waiting. */ |
| 4776 | if (wait_channel == channel) | ||
| 4777 | { | ||
| 4778 | wait_channel = -1; | ||
| 4779 | nsecs = -1; | ||
| 4780 | got_some_input = 1; | ||
| 4781 | } | ||
| 4782 | proc = chan_process[channel]; | 4771 | proc = chan_process[channel]; |
| 4783 | if (NILP (proc)) | 4772 | if (NILP (proc)) |
| 4784 | continue; | 4773 | continue; |
| @@ -4794,6 +4783,8 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 4794 | buffered-ahead character if we have one. */ | 4783 | buffered-ahead character if we have one. */ |
| 4795 | 4784 | ||
| 4796 | nread = read_process_output (proc, channel); | 4785 | nread = read_process_output (proc, channel); |
| 4786 | if ((!wait_proc || wait_proc == XPROCESS (proc)) && got_some_input < nread) | ||
| 4787 | got_some_input = nread; | ||
| 4797 | if (nread > 0) | 4788 | if (nread > 0) |
| 4798 | { | 4789 | { |
| 4799 | /* Since read_process_output can run a filter, | 4790 | /* Since read_process_output can run a filter, |
| @@ -5814,7 +5805,7 @@ process_send_signal (Lisp_Object process, int signo, Lisp_Object current_group, | |||
| 5814 | p->tick = ++process_tick; | 5805 | p->tick = ++process_tick; |
| 5815 | if (!nomsg) | 5806 | if (!nomsg) |
| 5816 | { | 5807 | { |
| 5817 | status_notify (NULL); | 5808 | status_notify (NULL, NULL); |
| 5818 | redisplay_preserve_echo_area (13); | 5809 | redisplay_preserve_echo_area (13); |
| 5819 | } | 5810 | } |
| 5820 | } | 5811 | } |
| @@ -6337,14 +6328,20 @@ exec_sentinel (Lisp_Object proc, Lisp_Object reason) | |||
| 6337 | /* Report all recent events of a change in process status | 6328 | /* Report all recent events of a change in process status |
| 6338 | (either run the sentinel or output a message). | 6329 | (either run the sentinel or output a message). |
| 6339 | This is usually done while Emacs is waiting for keyboard input | 6330 | This is usually done while Emacs is waiting for keyboard input |
| 6340 | but can be done at other times. */ | 6331 | but can be done at other times. |
| 6341 | 6332 | ||
| 6342 | static void | 6333 | Return positive if any input was received from WAIT_PROC (or from |
| 6343 | status_notify (struct Lisp_Process *deleting_process) | 6334 | any process if WAIT_PROC is null), zero if input was attempted but |
| 6335 | none received, and negative if we didn't even try. */ | ||
| 6336 | |||
| 6337 | static int | ||
| 6338 | status_notify (struct Lisp_Process *deleting_process, | ||
| 6339 | struct Lisp_Process *wait_proc) | ||
| 6344 | { | 6340 | { |
| 6345 | register Lisp_Object proc; | 6341 | Lisp_Object proc; |
| 6346 | Lisp_Object tail, msg; | 6342 | Lisp_Object tail, msg; |
| 6347 | struct gcpro gcpro1, gcpro2; | 6343 | struct gcpro gcpro1, gcpro2; |
| 6344 | int got_some_input = -1; | ||
| 6348 | 6345 | ||
| 6349 | tail = Qnil; | 6346 | tail = Qnil; |
| 6350 | msg = Qnil; | 6347 | msg = Qnil; |
| @@ -6374,8 +6371,14 @@ status_notify (struct Lisp_Process *deleting_process) | |||
| 6374 | /* Network or serial process not stopped: */ | 6371 | /* Network or serial process not stopped: */ |
| 6375 | && ! EQ (p->command, Qt) | 6372 | && ! EQ (p->command, Qt) |
| 6376 | && p->infd >= 0 | 6373 | && p->infd >= 0 |
| 6377 | && p != deleting_process | 6374 | && p != deleting_process) |
| 6378 | && read_process_output (proc, p->infd) > 0); | 6375 | { |
| 6376 | int nread = read_process_output (proc, p->infd); | ||
| 6377 | if (got_some_input < nread) | ||
| 6378 | got_some_input = nread; | ||
| 6379 | if (nread <= 0) | ||
| 6380 | break; | ||
| 6381 | } | ||
| 6379 | 6382 | ||
| 6380 | /* Get the text to use for the message. */ | 6383 | /* Get the text to use for the message. */ |
| 6381 | if (p->raw_status_new) | 6384 | if (p->raw_status_new) |
| @@ -6407,6 +6410,7 @@ status_notify (struct Lisp_Process *deleting_process) | |||
| 6407 | 6410 | ||
| 6408 | update_mode_lines = 24; /* In case buffers use %s in mode-line-format. */ | 6411 | update_mode_lines = 24; /* In case buffers use %s in mode-line-format. */ |
| 6409 | UNGCPRO; | 6412 | UNGCPRO; |
| 6413 | return got_some_input; | ||
| 6410 | } | 6414 | } |
| 6411 | 6415 | ||
| 6412 | DEFUN ("internal-default-process-sentinel", Finternal_default_process_sentinel, | 6416 | DEFUN ("internal-default-process-sentinel", Finternal_default_process_sentinel, |
| @@ -6618,9 +6622,11 @@ extern int sys_select (int, fd_set *, fd_set *, fd_set *, | |||
| 6618 | DO_DISPLAY means redisplay should be done to show subprocess | 6622 | DO_DISPLAY means redisplay should be done to show subprocess |
| 6619 | output that arrives. | 6623 | output that arrives. |
| 6620 | 6624 | ||
| 6621 | Return true if we received input from any process. */ | 6625 | Return positive if we received input from WAIT_PROC (or from any |
| 6626 | process if WAIT_PROC is null), zero if we attempted to receive | ||
| 6627 | input but got none, and negative if we didn't even try. */ | ||
| 6622 | 6628 | ||
| 6623 | bool | 6629 | int |
| 6624 | wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | 6630 | wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, |
| 6625 | bool do_display, | 6631 | bool do_display, |
| 6626 | Lisp_Object wait_for_cell, | 6632 | Lisp_Object wait_for_cell, |
| @@ -6808,7 +6814,7 @@ wait_reading_process_output (intmax_t time_limit, int nsecs, int read_kbd, | |||
| 6808 | 6814 | ||
| 6809 | start_polling (); | 6815 | start_polling (); |
| 6810 | 6816 | ||
| 6811 | return 0; | 6817 | return -1; |
| 6812 | } | 6818 | } |
| 6813 | 6819 | ||
| 6814 | #endif /* not subprocesses */ | 6820 | #endif /* not subprocesses */ |