[PATCH] policycoreutils/run_init: fix EINTR/EAGAIN checking in open_init_pty
Stephen Smalley <[email protected]>
| Newsgroups | org.kernel.vger.selinux |
|---|---|
| Message-ID | <[email protected]> |
open_init_pty was incorrectly checking the number of bytes read/written against EINTR/EAGAIN. Check errno instead, and only check it if the return value is less than 0 since otherwise errno could have been set by an earlier operation. Signed-off-by: Stephen Smalley <[email protected]> --- policycoreutils/run_init/open_init_pty.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/policycoreutils/run_init/open_init_pty.c b/policycoreutils/run_init/open_init_pty.c index a51320a5..bd65c991 100644 --- a/policycoreutils/run_init/open_init_pty.c +++ b/policycoreutils/run_init/open_init_pty.c @@ -371,7 +371,8 @@ int main(int argc, char *argv[]) fprintf(stderr, "stdout can be written\n"); #endif ssize_t n = rb_write(&outbuf, STDOUT_FILENO); - if (n <= 0 && n != EINTR && n != EAGAIN) + if (n == 0 || + (n < 0 && errno != EINTR && errno != EAGAIN)) err_n_stdout++; #ifdef DEBUG if (n >= 0) @@ -387,7 +388,8 @@ int main(int argc, char *argv[]) fprintf(stderr, "pty_master can be written\n"); #endif ssize_t n = rb_write(&inbuf, pty_master); - if (n <= 0 && n != EINTR && n != EAGAIN) + if (n == 0 || + (n < 0 && errno != EINTR && errno != EAGAIN)) err_n_wpty++; #ifdef DEBUG if (n >= 0) @@ -404,7 +406,8 @@ int main(int argc, char *argv[]) fprintf(stderr, "stdin can be read\n"); #endif ssize_t n = rb_read(&inbuf, STDIN_FILENO); - if (n <= 0 && n != EINTR && n != EAGAIN) + if (n == 0 || + (n < 0 && errno != EINTR && errno != EAGAIN)) err_n_stdin++; #ifdef DEBUG if (n >= 0) @@ -420,7 +423,8 @@ int main(int argc, char *argv[]) fprintf(stderr, "pty_master can be read\n"); #endif ssize_t n = rb_read(&outbuf, pty_master); - if (n <= 0 && n != EINTR && n != EAGAIN) + if (n == 0 || + (n < 0 && errno != EINTR && errno != EAGAIN)) err_n_rpty++; #ifdef DEBUG if (n >= 0) -- 2.55.0