diff options
author | Arne Welzel <arne.welzel@corelight.com> | 2020-07-08 17:18:09 +0200 |
---|---|---|
committer | Arne Welzel <arne.welzel@corelight.com> | 2020-07-08 17:19:19 +0200 |
commit | 0226be42dbf107e80f9f3a0210a9fda23b3b066a (patch) | |
tree | 2be9c5b5ce4334abeb74742791ef9c3ffcd9095c /src/firejail/util.c | |
parent | Okular profile fixes (#3489) (diff) | |
download | firejail-0226be42dbf107e80f9f3a0210a9fda23b3b066a.tar.gz firejail-0226be42dbf107e80f9f3a0210a9fda23b3b066a.tar.zst firejail-0226be42dbf107e80f9f3a0210a9fda23b3b066a.zip |
Ignore SIGTTOU during flush_stdin()
fixes #3500
Diffstat (limited to 'src/firejail/util.c')
-rw-r--r-- | src/firejail/util.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/firejail/util.c b/src/firejail/util.c index 6bfc80903..3aa0584d6 100644 --- a/src/firejail/util.c +++ b/src/firejail/util.c | |||
@@ -957,16 +957,27 @@ int remove_overlay_directory(void) { | |||
957 | return 0; | 957 | return 0; |
958 | } | 958 | } |
959 | 959 | ||
960 | // flush stdin if it is connected to a tty and has input | ||
960 | void flush_stdin(void) { | 961 | void flush_stdin(void) { |
961 | if (isatty(STDIN_FILENO)) { | 962 | if (!isatty(STDIN_FILENO)) |
962 | int cnt = 0; | 963 | return; |
963 | int rv = ioctl(STDIN_FILENO, FIONREAD, &cnt); | 964 | |
964 | if (rv == 0 && cnt) { | 965 | int cnt = 0; |
965 | fwarning("removing %d bytes from stdin\n", cnt); | 966 | int rv = ioctl(STDIN_FILENO, FIONREAD, &cnt); |
966 | rv = ioctl(STDIN_FILENO, TCFLSH, TCIFLUSH); | 967 | if (rv != 0 || cnt == 0) |
967 | (void) rv; | 968 | return; |
968 | } | 969 | |
969 | } | 970 | fwarning("removing %d bytes from stdin\n", cnt); |
971 | |||
972 | // If this process is backgrounded, below ioctl() will trigger | ||
973 | // SIGTTOU and stop us. We avoid this by ignoring SIGTTOU for | ||
974 | // the duration of the ioctl. | ||
975 | sighandler_t hdlr = signal(SIGTTOU, SIG_IGN); | ||
976 | rv = ioctl(STDIN_FILENO, TCFLSH, TCIFLUSH); | ||
977 | signal(SIGTTOU, hdlr); | ||
978 | |||
979 | if (rv) | ||
980 | fwarning("Flushing stdin failed: %s\n", strerror(errno)); | ||
970 | } | 981 | } |
971 | 982 | ||
972 | // return 1 if new directory was created, else return 0 | 983 | // return 1 if new directory was created, else return 0 |