bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash sets O_NONBLOCK on pts


From: Stephane Chazelas
Subject: Re: bash sets O_NONBLOCK on pts
Date: Wed, 2 Oct 2019 20:06:34 +0100
User-agent: NeoMutt/20171215

2019-10-03 02:49:36 +0900, Andrew Church:
> >Well, it's not so uncommon, I had it a few times. Reading on internet
> >it seems that other users have it but don't notice it.
> 
> The fault could be in some other program accessing the terminal.  Bash
> does not clear O_NONBLOCK on displaying a prompt, so if a previously
> executed program sets O_NONBLOCK on stdin and then exits, that state
> will remain until some other program unsets it.  For example:
> 
> $ cat >foo.c
> #include <fcntl.h>
> int main(void) {fcntl(0, F_SETFL, O_NONBLOCK); return 0;}
> ^D
> $ cc foo.c
> $ ./a.out
> $ cat
> cat: -: Resource temporarily unavailable
[...]

Good point.

I see a difference between versions of bash there:

With GNU dd:

~$ bash5 --norc
bash5-5.0$ dd iflag=nonblock
dd: error reading 'standard input': Resource temporarily unavailable
0+0 records in
0+0 records out
0 bytes copied, 0.000150515 s, 0.0 kB/s
bash5-5.0$ cat
^C
bash5-5.0$ exit

~$ bash --norc
bash-4.4$ dd iflag=nonblock
dd: error reading 'standard input': Resource temporarily unavailable
0+0 records in
0+0 records out
0 bytes copied, 0.000126312 s, 0.0 kB/s
bash-4.4$ cat
cat: -: Resource temporarily unavailable

In bash5, with strace, we see:

fcntl(0, F_GETFL)                       = 0x8802 (flags 
O_RDWR|O_NONBLOCK|O_LARGEFILE)
fcntl(0, F_SETFL, O_RDWR|O_LARGEFILE)   = 0

That seems to be done by sh_unset_nodelay_mode()

Which points to this change:

commit bc371472444f900d44050414e3472f7349a7aec7
Author: Chet Ramey <chet.ramey@case.edu>
Date:   Mon Jan 30 15:50:08 2017 -0500

    commit bash-20170127 snapshot

diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog
index b8436d64..74a0463e 100644
--- a/CWRU/CWRU.chlog
+++ b/CWRU/CWRU.chlog
@@ -13027,3 +13027,21 @@ subst.c
          after reading a double-quoted string, make sure the W_NOCOMSUB and
          W_NOPROCSUB flags make it to the recursive invocation.  Fixes bug
          reported by Jens Heyens <jens.heyens@cispa.saarland>
+
+                                  1/23
+                                  ----
+lib/readline/signals.c
+       - _rl_orig_sigset: original signal mask, set and restored by
+         rl_set_signals (rl_clear_signals doesn't block signals).  If we
+         are not installing signal handlers, just save signal mask each
+         time rl_set_signals is called
+
+lib/readline/input.c
+       - rl_getc: use _rl_orig_sigmask in the call to pselect(), so we block
+         the set of signals originally blocked by the calling application.
+         Fixes bug reported by Frédéric Brière <fbriere@fbriere.net>
+
+parse.y
+       - yy_readline_get: try to unset NONBLOCK mode on readline's input
+         file descriptor before calling readline(). Inspired by report from
+         Siteshwar Vashisht <svashisht@redhat.com>



Given that the OP is running 5.0.7, they should have that change already.

Maybe the fcntl(O_NONBLOCK) is done by a command run by a completion
widget.

-- 
Stephane




reply via email to

[Prev in Thread] Current Thread [Next in Thread]