[PATCH 1/2] Revert "open_init_pty: Do not make stdin and stdout non-blocking"

2017-07-18 Thread Stephen Smalley
Making stdin/stdout non-blocking causes open_init_pty to hang if
they are closed, ala
./open_init_pty bash -c 'echo hello; exec >&- 2>&- <&-; sleep 1; '
and per
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=474956#10

This reverts commit fb081eb64b36a9de5a43f3d69d9e628b6eb1afc7.

Reported-by: Laurent Bigonville 
Signed-off-by: Stephen Smalley 
---
 policycoreutils/run_init/open_init_pty.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/policycoreutils/run_init/open_init_pty.c 
b/policycoreutils/run_init/open_init_pty.c
index b37ae4d..6e25ea3 100644
--- a/policycoreutils/run_init/open_init_pty.c
+++ b/policycoreutils/run_init/open_init_pty.c
@@ -276,8 +276,10 @@ int main(int argc, char *argv[])
}
}
 
-   /* Non blocking mode for the pty master. */
+   /* Non blocking mode for all file descriptors. */
setfd_nonblock(pty_master);
+   setfd_nonblock(STDIN_FILENO);
+   setfd_nonblock(STDOUT_FILENO);
 
if (isatty(STDIN_FILENO)) {
if (tty_semi_raw(STDIN_FILENO) < 0) {
-- 
2.9.4



Re: open_init_pty: Do not make stdin and stdout non-blocking

2017-07-14 Thread Laurent Bigonville
commit fb081eb64b36a9de5a43f3d69d9e628b6eb1afc7 (HEAD -> master, 
origin/master)

Author: Stephen Smalley <s...@tycho.nsa.gov>
Date:   Mon Jul 10 13:03:01 2017 -0400

open_init_pty: Do not make stdin and stdout non-blocking

It is unclear why this was being done in the first place, and
it has caused multiple bugs with run_init/open_init_pty usage.

Fixes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=863187
Fixes: https://bugs.gentoo.org/show_bug.cgi?id=621062
Signed-off-by: Stephen Smalley <s...@tycho.nsa.gov>


I see you fixed the issue with run_init/open_init_pty messing up with 
the terminals but I think it's introducing an other issue :/


FTR I found the reason why stdin/stdout were not blocking, it's a fix 
for this: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=474956#10


Apparently if the descriptors are closed, open_init_pty hangs, example:

./open_init_pty bash -c 'echo hello; exec >&- 2>&- <&-; sleep 1; '



[PATCH] open_init_pty: Do not make stdin and stdout non-blocking

2017-07-10 Thread Stephen Smalley
It is unclear why this was being done in the first place, and
it has caused multiple bugs with run_init/open_init_pty usage.

Fixes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=863187
Fixes: https://bugs.gentoo.org/show_bug.cgi?id=621062
Signed-off-by: Stephen Smalley 
---
 policycoreutils/run_init/open_init_pty.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/policycoreutils/run_init/open_init_pty.c 
b/policycoreutils/run_init/open_init_pty.c
index 6e25ea3..b37ae4d 100644
--- a/policycoreutils/run_init/open_init_pty.c
+++ b/policycoreutils/run_init/open_init_pty.c
@@ -276,10 +276,8 @@ int main(int argc, char *argv[])
}
}
 
-   /* Non blocking mode for all file descriptors. */
+   /* Non blocking mode for the pty master. */
setfd_nonblock(pty_master);
-   setfd_nonblock(STDIN_FILENO);
-   setfd_nonblock(STDOUT_FILENO);
 
if (isatty(STDIN_FILENO)) {
if (tty_semi_raw(STDIN_FILENO) < 0) {
-- 
2.9.4