Handle EINTR from write(2) when writing to pipes and socket pairs.

This commit is contained in:
Todd C. Miller
2014-05-27 10:16:49 -06:00
parent 9e5a68627f
commit d628e17ead
3 changed files with 28 additions and 7 deletions

View File

@@ -877,7 +877,10 @@ handler(int s, siginfo_t *info, void *context)
* The pipe is non-blocking, if we overflow the kernel's pipe * The pipe is non-blocking, if we overflow the kernel's pipe
* buffer we drop the signal. This is not a problem in practice. * buffer we drop the signal. This is not a problem in practice.
*/ */
ignore_result(write(signal_pipe[1], &signo, sizeof(signo))); while (write(signal_pipe[1], &signo, sizeof(signo)) == -1) {
if (errno != EINTR)
break;
}
} }
#else #else
void void
@@ -889,7 +892,10 @@ handler(int s)
* The pipe is non-blocking, if we overflow the kernel's pipe * The pipe is non-blocking, if we overflow the kernel's pipe
* buffer we drop the signal. This is not a problem in practice. * buffer we drop the signal. This is not a problem in practice.
*/ */
ignore_result(write(signal_pipe[1], &signo, sizeof(signo))); while (write(signal_pipe[1], &signo, sizeof(signo)) == -1) {
if (errno != EINTR)
break;
}
} }
#endif #endif
@@ -911,7 +917,10 @@ handler_user_only(int s, siginfo_t *info, void *context)
* The pipe is non-blocking, if we overflow the kernel's pipe * The pipe is non-blocking, if we overflow the kernel's pipe
* buffer we drop the signal. This is not a problem in practice. * buffer we drop the signal. This is not a problem in practice.
*/ */
ignore_result(write(signal_pipe[1], &signo, sizeof(signo))); while (write(signal_pipe[1], &signo, sizeof(signo)) == -1) {
if (errno != EINTR)
break;
}
} }
} }
#endif /* SA_SIGINFO */ #endif /* SA_SIGINFO */

View File

@@ -148,7 +148,10 @@ mon_handler(int s, siginfo_t *info, void *context)
* The pipe is non-blocking, if we overflow the kernel's pipe * The pipe is non-blocking, if we overflow the kernel's pipe
* buffer we drop the signal. This is not a problem in practice. * buffer we drop the signal. This is not a problem in practice.
*/ */
ignore_result(write(signal_pipe[1], &signo, sizeof(signo))); while (write(signal_pipe[1], &signo, sizeof(signo)) == -1) {
if (errno != EINTR)
break;
}
} }
#else #else
static void static void
@@ -160,7 +163,10 @@ mon_handler(int s)
* The pipe is non-blocking, if we overflow the kernel's pipe * The pipe is non-blocking, if we overflow the kernel's pipe
* buffer we drop the signal. This is not a problem in practice. * buffer we drop the signal. This is not a problem in practice.
*/ */
ignore_result(write(signal_pipe[1], &signo, sizeof(signo))); while (write(signal_pipe[1], &signo, sizeof(signo)) == -1) {
if (errno != EINTR)
break;
}
} }
#endif #endif
@@ -1281,7 +1287,10 @@ exec_monitor(struct command_details *details, int backchannel)
/* setup tty and exec command */ /* setup tty and exec command */
exec_pty(details, &cstat, errpipe[1]); exec_pty(details, &cstat, errpipe[1]);
ignore_result(write(errpipe[1], &cstat, sizeof(cstat))); while (write(errpipe[1], &cstat, sizeof(cstat)) == -1) {
if (errno != EINTR)
break;
}
_exit(1); _exit(1);
} }
close(errpipe[1]); close(errpipe[1]);

View File

@@ -102,7 +102,10 @@ sudo_handler(int signo)
* The pipe is non-blocking, if we overflow the kernel's pipe * The pipe is non-blocking, if we overflow the kernel's pipe
* buffer we drop the signal. This is not a problem in practice. * buffer we drop the signal. This is not a problem in practice.
*/ */
ignore_result(write(signal_pipe[1], &signo, sizeof(signo))); while (write(signal_pipe[1], &signo, sizeof(signo)) == -1) {
if (errno != EINTR)
break;
}
} }
/* /*