Mercurial > emacs
comparison src/process.c @ 76794:fbe60d04cec2
(wait_reading_process_output) [HAVE_PTYS]:
When EIO happens, clear channel from descriptor masks before raising
SIGCHLD signal to avoid busy loop between read and sigchld_handler.
(sigchld_handler): Remove sleep (2007-03-11 & 2007-03-26 changes).
| author | Kim F. Storm <storm@cua.dk> |
|---|---|
| date | Thu, 29 Mar 2007 21:24:38 +0000 |
| parents | e3f8914e3f5e |
| children | e9b4790481bc dc002877ce12 4ef881a120fe |
comparison
equal
deleted
inserted
replaced
| 76793:0fe998c0f487 | 76794:fbe60d04cec2 |
|---|---|
| 4815 available now and a closed pipe. | 4815 available now and a closed pipe. |
| 4816 With luck, a closed pipe will be accompanied by | 4816 With luck, a closed pipe will be accompanied by |
| 4817 subprocess termination and SIGCHLD. */ | 4817 subprocess termination and SIGCHLD. */ |
| 4818 else if (nread == 0 && !NETCONN_P (proc)) | 4818 else if (nread == 0 && !NETCONN_P (proc)) |
| 4819 ; | 4819 ; |
| 4820 #endif /* O_NDELAY */ | 4820 #endif /* O_NDELAY */ |
| 4821 #endif /* O_NONBLOCK */ | 4821 #endif /* O_NONBLOCK */ |
| 4822 #ifdef HAVE_PTYS | 4822 #ifdef HAVE_PTYS |
| 4823 /* On some OSs with ptys, when the process on one end of | 4823 /* On some OSs with ptys, when the process on one end of |
| 4824 a pty exits, the other end gets an error reading with | 4824 a pty exits, the other end gets an error reading with |
| 4825 errno = EIO instead of getting an EOF (0 bytes read). | 4825 errno = EIO instead of getting an EOF (0 bytes read). |
| 4826 Therefore, if we get an error reading and errno = | 4826 Therefore, if we get an error reading and errno = |
| 4827 EIO, just continue, because the child process has | 4827 EIO, just continue, because the child process has |
| 4828 exited and should clean itself up soon (e.g. when we | 4828 exited and should clean itself up soon (e.g. when we |
| 4829 get a SIGCHLD). | 4829 get a SIGCHLD). |
| 4830 | 4830 |
| 4831 However, it has been known to happen that the SIGCHLD | 4831 However, it has been known to happen that the SIGCHLD |
| 4832 got lost. So raise the signl again just in case. | 4832 got lost. So raise the signal again just in case. |
| 4833 It can't hurt. */ | 4833 It can't hurt. */ |
| 4834 else if (nread == -1 && errno == EIO) | 4834 else if (nread == -1 && errno == EIO) |
| 4835 kill (getpid (), SIGCHLD); | 4835 { |
| 4836 #endif /* HAVE_PTYS */ | 4836 /* Clear the descriptor now, so we only raise the signal once. */ |
| 4837 FD_CLR (channel, &input_wait_mask); | |
| 4838 FD_CLR (channel, &non_keyboard_wait_mask); | |
| 4839 | |
| 4840 kill (getpid (), SIGCHLD); | |
| 4841 } | |
| 4842 #endif /* HAVE_PTYS */ | |
| 4837 /* If we can detect process termination, don't consider the process | 4843 /* If we can detect process termination, don't consider the process |
| 4838 gone just because its pipe is closed. */ | 4844 gone just because its pipe is closed. */ |
| 4839 #ifdef SIGCHLD | 4845 #ifdef SIGCHLD |
| 4840 else if (nread == 0 && !NETCONN_P (proc)) | 4846 else if (nread == 0 && !NETCONN_P (proc)) |
| 4841 ; | 4847 ; |
| 6512 #define WUNTRACED 0 | 6518 #define WUNTRACED 0 |
| 6513 #endif /* no WUNTRACED */ | 6519 #endif /* no WUNTRACED */ |
| 6514 /* Keep trying to get a status until we get a definitive result. */ | 6520 /* Keep trying to get a status until we get a definitive result. */ |
| 6515 do | 6521 do |
| 6516 { | 6522 { |
| 6517 /* For some reason, this sleep() prevents Emacs from sending | |
| 6518 loadavg to 5-8(!) for ~10 seconds. | |
| 6519 See http://thread.gmane.org/gmane.emacs.devel/67722 or | |
| 6520 http://www.google.com/search?q=busyloop+in+sigchld_handler */ | |
| 6521 usleep (1000); | |
| 6522 errno = 0; | 6523 errno = 0; |
| 6523 pid = wait3 (&w, WNOHANG | WUNTRACED, 0); | 6524 pid = wait3 (&w, WNOHANG | WUNTRACED, 0); |
| 6524 } | 6525 } |
| 6525 while (pid < 0 && errno == EINTR); | 6526 while (pid < 0 && errno == EINTR); |
| 6526 | 6527 |
