Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Neovim interferes with mutt #2086

Closed
Stebalien opened this issue Mar 3, 2015 · 20 comments
Closed

Neovim interferes with mutt #2086

Stebalien opened this issue Mar 3, 2015 · 20 comments
Assignees
Labels
bug issues reporting wrong behavior tui

Comments

@Stebalien
Copy link

It's impossible to add attachments (a) or abort a message (q) in mutt after composing a message with neovim. To reproduce, run EDITOR=nvim mutt, hit m to compose a message, type in a random email address, type in a random subject, write a random body into neovim, save and quite neovim, and then try the a and q (mutt) commands (send, y, works fine).

This happens on every terminal I have tried (termite, urxvt, a linux virtual terminal) and with a clean mutt/neovim configs and vim doesn't cause this bug.

I'm running Arch Linux (using the neovim-git package from the AUR) if in case that helps.

Here is an strace snippet starting from when I saved the message in neovim and ending where I closed my terminal.

write(1, "\33[?1h\33=", 7)              = 7
stat("/tmp/mutt-bistromath-0-15646-490577392207529363", {st_mode=S_IFREG|0600, st_size=0, ...}) = 0
open("/tmp/mutt-bistromath-0-15646-490577392207529363", O_RDWR|O_CREAT|O_APPEND, 0666) = 3
fstat(3, {st_mode=S_IFREG|0600, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x3c4c9743000
fstat(3, {st_mode=S_IFREG|0600, st_size=0, ...}) = 0
lseek(3, 18446744073709547520, SEEK_SET) = -1 EINVAL (Invalid argument)
read(3, "", 4096)                       = 0
write(3, "\n", 1)                       = 1
close(3)                                = 0
munmap(0x3c4c9743000, 4096)             = 0
stat("/tmp/mutt-bistromath-0-15646-490577392207529363", {st_mode=S_IFREG|0600, st_size=1, ...}) = 0
stat("/tmp/mutt-bistromath-0-15646-490577392207529363", {st_mode=S_IFREG|0600, st_size=1, ...}) = 0
open("/tmp/mutt-bistromath-0-15646-490577392207529363", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0600, st_size=1, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x3c4c9743000
lseek(3, 0, SEEK_SET)                   = 0
read(3, "\n", 4096)                     = 1
read(3, "", 4096)                       = 0
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0x3c4c9743000, 4096)             = 0
write(1, "\33[?25l", 6)                 = 6
stat("/tmp/mutt-bistromath-0-15646-490577392207529363", {st_mode=S_IFREG|0600, st_size=1, ...}) = 0
ioctl(1, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
ioctl(1, TIOCGWINSZ, {ws_row=66, ws_col=224, ws_xpixel=0, ws_ypixel=0}) = 0
ioctl(1, SNDCTL_TMR_STOP or SNDRV_TIMER_IOCTL_GINFO or TCSETSW, {B38400 opost isig -icanon -echo ...}) = 0
write(1, "\33[?1h\33=", 7)              = 7
write(1, "\33[?1049h\33[1;66r\33[?25l", 21) = 21
write(1, "\33[39;49m\33(B\33[m\33[4l\33[?7h\33[39;49m\33"..., 1186) = 1186
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER, 0x3c4c88fa540}, NULL, 8) = 0
poll([{fd=0, events=POLLIN}], 1, 600000) = 1 ([{fd=0, revents=POLLIN}])
read(0, "q", 1)                         = 1
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER|SA_RESTART, 0x3c4c88fa540}, NULL, 8) = 0
write(1, "\33[?12l\33[?25h", 12)        = 12
write(1, "\r\33[66dPostpone this message? ([y"..., 41) = 41
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER, 0x3c4c88fa540}, NULL, 8) = 0
read(0, 0x3ee0aa21fef, 1)               = -1 EAGAIN (Resource temporarily unavailable)
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER|SA_RESTART, 0x3c4c88fa540}, NULL, 8) = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig -icanon -echo ...}) = 0
write(1, "\33[?25l", 6)                 = 6
write(1, "\r\33[J\33[13;224H", 13)      = 13
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER, 0x3c4c88fa540}, NULL, 8) = 0
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER|SA_RESTART, 0x3c4c88fa540}, NULL, 8) = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig -icanon -echo ...}) = 0
write(1, "\33[?12l\33[?25h", 12)        = 12
write(1, "\33[?25l", 6)                 = 6
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER, 0x3c4c88fa540}, NULL, 8) = 0
poll([{fd=0, events=POLLIN}], 1, 600000) = 1 ([{fd=0, revents=POLLIN}])
read(0, "q", 1)                         = 1
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER|SA_RESTART, 0x3c4c88fa540}, NULL, 8) = 0
write(1, "\33[?12l\33[?25h", 12)        = 12
write(1, "\r\33[66dPostpone this message? ([y"..., 41) = 41
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER, 0x3c4c88fa540}, NULL, 8) = 0
read(0, 0x3ee0aa21fef, 1)               = -1 EAGAIN (Resource temporarily unavailable)
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER|SA_RESTART, 0x3c4c88fa540}, NULL, 8) = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig -icanon -echo ...}) = 0
write(1, "\33[?25l", 6)                 = 6
write(1, "\r\33[J\33[13;224H", 13)      = 13
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER, 0x3c4c88fa540}, NULL, 8) = 0
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER|SA_RESTART, 0x3c4c88fa540}, NULL, 8) = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig -icanon -echo ...}) = 0
write(1, "\33[?12l\33[?25h", 12)        = 12
write(1, "\33[?25l", 6)                 = 6
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER, 0x3c4c88fa540}, NULL, 8) = 0
poll([{fd=0, events=POLLIN}], 1, 600000) = 1 ([{fd=0, revents=POLLIN}])
read(0, "q", 1)                         = 1
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER|SA_RESTART, 0x3c4c88fa540}, NULL, 8) = 0
write(1, "\33[?12l\33[?25h", 12)        = 12
write(1, "\r\33[66dPostpone this message? ([y"..., 41) = 41
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER, 0x3c4c88fa540}, NULL, 8) = 0
read(0, 0x3ee0aa21fef, 1)               = -1 EAGAIN (Resource temporarily unavailable)
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER|SA_RESTART, 0x3c4c88fa540}, NULL, 8) = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig -icanon -echo ...}) = 0
write(1, "\33[?25l", 6)                 = 6
write(1, "\r\33[J\33[13;224H", 13)      = 13
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER, 0x3c4c88fa540}, NULL, 8) = 0
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER|SA_RESTART, 0x3c4c88fa540}, NULL, 8) = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig -icanon -echo ...}) = 0
write(1, "\33[?12l\33[?25h", 12)        = 12
write(1, "\33[?25l", 6)                 = 6
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER, 0x3c4c88fa540}, NULL, 8) = 0
poll([{fd=0, events=POLLIN}], 1, 600000) = 1 ([{fd=0, revents=POLLIN|POLLERR|POLLHUP}])
read(0, "", 1)                          = 0
rt_sigaction(SIGINT, {0x4645c0, [], SA_RESTORER|SA_RESTART, 0x3c4c88fa540}, NULL, 8) = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x3ee0aa21ff0) = -1 EIO (Input/output error)
write(1, "\33[39;49m\r\33[66d\33[K\33[66;1H\33[?12l\33["..., 36) = -1 EIO (Input/output error)
write(1, "\33[?1049l\r\33[?1l\33>", 16) = -1 EIO (Input/output error)
ioctl(1, SNDCTL_TMR_STOP or SNDRV_TIMER_IOCTL_GINFO or TCSETSW, {B38400 opost isig icanon echo ...}) = -1 EIO (Input/output error)
exit_group(1)                           = ?
+++ exited with 1 +++

Note: The "Postpone this message?" prompt present in this trace is never displayed.

@justinmk
Copy link
Member

justinmk commented Mar 3, 2015

The "Postpone this message?" prompt present in this trace is never displayed.

Sounds like the same problem as #1044 #1496 #1716 ?

@Stebalien
Copy link
Author

It might be related but it isn't the same problem. All of those bugs manifest when running commands inside of neovim while this problem shows up after neovim has exited. Basically, mutt is giving control of the terminal to neovim and then neovim doesn't appear to be giving full control back when it exits.

@tarruda tarruda self-assigned this Mar 3, 2015
@tarruda
Copy link
Member

tarruda commented Mar 3, 2015

@Stebalien can you tell me if this patch helps?

diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c
index cdea867..3e749e0 100644
--- a/src/nvim/tui/tui.c
+++ b/src/nvim/tui/tui.c
@@ -2,6 +2,9 @@
 #include <stdbool.h>
 #include <stdio.h>

+#include <termios.h>
+#include <sys/ioctl.h>
+
 #include <uv.h>
 #include <unibilium.h>

@@ -36,7 +39,8 @@ typedef struct {
   TermInput *input;
   uv_loop_t *write_loop;
   unibi_term *ut;
-  uv_tty_t output_handle;
+  struct termios orig_termios;
+  uv_pipe_t output_handle;
   uv_signal_t winch_handle;
   Rect scroll_region;
   kvec_t(Rect) invalid_regions;
@@ -114,10 +118,19 @@ void tui_start(void)

   // setup output handle in a separate event loop(we wanna do synchronous
   // write to the tty)
+  tcgetattr(data->out_fd, &data->orig_termios);
+  struct termios new_termios = data->orig_termios;
+  new_termios.c_iflag &= ~(unsigned)(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
+  new_termios.c_oflag |= (ONLCR);
+  new_termios.c_cflag |= (CS8);
+  new_termios.c_lflag &= ~(unsigned)(ECHO | ICANON | IEXTEN | ISIG);
+  new_termios.c_cc[VMIN] = 1;
+  new_termios.c_cc[VTIME] = 0;
+  tcsetattr(data->out_fd, TCSADRAIN, &new_termios);
   data->write_loop = xmalloc(sizeof(uv_loop_t));
   uv_loop_init(data->write_loop);
-  uv_tty_init(data->write_loop, &data->output_handle, data->out_fd, 0);
-  uv_tty_set_mode(&data->output_handle, UV_TTY_MODE_RAW);
+  uv_pipe_init(data->write_loop, &data->output_handle, 0);
+  uv_pipe_open(&data->output_handle, data->out_fd);

   // Obtain screen dimensions
   update_size(ui);
@@ -174,7 +187,7 @@ static void tui_stop(UI *ui)
   // Disable bracketed paste
   unibi_out(ui, (int)data->unibi_ext.disable_bracketed_paste);
   flush_buf(ui);
-  uv_tty_reset_mode();
+  tcsetattr(data->out_fd, TCSANOW, &data->orig_termios);
   uv_close((uv_handle_t *)&data->output_handle, NULL);
   uv_run(data->write_loop, UV_RUN_DEFAULT);
   if (uv_loop_close(data->write_loop)) {
@@ -596,7 +609,10 @@ static void update_size(UI *ui)
   TUIData *data = ui->data;
   int width = 0, height = 0;
   // 1 - try from a system call(ioctl/TIOCGWINSZ on unix)
-  if (!uv_tty_get_winsize(&data->output_handle, &width, &height)) {
+  struct winsize ws;
+  if (!ioctl(data->out_fd, TIOCGWINSZ, &ws)) {
+    width = ws.ws_col;
+    height = ws.ws_row;
     goto end;
   }

@Stebalien
Copy link
Author

Sorry, it doesn't make a difference (thanks for the quick response however).

@ntnn
Copy link

ntnn commented Mar 3, 2015

@Stebalien What version of mutt do you use? It works fine for me (neovim compiled today, mutt 1.5.23 [which may be a bit outdated] on F21 using urxvt).

@Stebalien
Copy link
Author

Same versions here. Mutt 1.5.23, neovim commit 6b7ece6.

@ntnn
Copy link

ntnn commented Mar 3, 2015

Yup, I'm on the same commit. Did you try to compile neovim without AUR? I honestly have no idea how far AUR can customize the process, but that would be my next step.

@Stebalien
Copy link
Author

I tried both. I am using a patched kernel (grsecurity) but that shouldn't be causing this problem.

-- Edit: Disabling grsecurity doesn't fix the bug.

@ghost
Copy link

ghost commented Mar 4, 2015

I am also experiencing the same behavior as @Stebalien.

Arch Linux
neovim-git package.
mutt 1.5.23 - with sidebar patch
neovim commit 6b7ece6
urxvt-unicode v9.21

@justinmk justinmk added the bug issues reporting wrong behavior label Mar 4, 2015
@ntnn
Copy link

ntnn commented Mar 24, 2015

I reinstalled fedora 21 today and I experience the same issue now, additionally I can't postpone or abort the message or open the pgp menu.

Imho thats really strange, since it is basically the same software aside from that I installed Fedora 21 Workstation now, while I had beend using an upgraded version of Fedora 21 beta.

>mutt -v
Mutt 1.5.23 (2014-03-12)
Copyright (C) 1996-2009 Michael R. Elkins and others.
Mutt comes with ABSOLUTELY NO WARRANTY; for details type `mutt -vv'.
Mutt is free software, and you are welcome to redistribute it
under certain conditions; type `mutt -vv' for details.

System: Linux 3.17.4-301.fc21.x86_64 (x86_64)
ncurses: ncurses 5.9.20140323 (compiled with 5.9)
libidn: 1.28 (compiled with 1.28)
hcache backend: tokyocabinet 1.4.48

Compiler:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.9.2/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.9.2-20141101/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.9.2-20141101/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.9.2 20141101 (Red Hat 4.9.2-1) (GCC) 

Configure options: '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--program-prefix=' '--disable-dependency-tracking' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' 'SENDMAIL=/usr/sbin/sendmail' 'ISPELL=/usr/bin/hunspell' '--enable-debug' '--enable-pop' '--enable-imap' '--enable-smtp' '--enable-hcache' '--without-gdbm' '--without-qdbm' '--with-gnutls' '--with-sasl' '--with-gss' '--enable-gpgme' '--with-docdir=/usr/share/doc/mutt' 'build_alias=x86_64-redhat-linux-gnu' 'host_alias=x86_64-redhat-linux-gnu' 'CFLAGS=-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches  -m64 -mtune=generic' 'LDFLAGS=-Wl,-z,relro '

Compilation CFLAGS: -Wall -pedantic -Wno-long-long -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches  -m64 -mtune=generic

Compile options:
-DOMAIN
+DEBUG
-HOMESPOOL  +USE_SETGID  -USE_DOTLOCK  +DL_STANDALONE  +USE_FCNTL  -USE_FLOCK   
+USE_POP  +USE_IMAP  +USE_SMTP  
-USE_SSL_OPENSSL  +USE_SSL_GNUTLS  +USE_SASL  +USE_GSS  +HAVE_GETADDRINFO  
+HAVE_REGCOMP  -USE_GNU_REGEX  
+HAVE_COLOR  +HAVE_START_COLOR  +HAVE_TYPEAHEAD  +HAVE_BKGDSET  
+HAVE_CURS_SET  +HAVE_META  +HAVE_RESIZETERM  
+CRYPT_BACKEND_CLASSIC_PGP  +CRYPT_BACKEND_CLASSIC_SMIME  +CRYPT_BACKEND_GPGME  
-EXACT_ADDRESS  -SUN_ATTACHMENT  
+ENABLE_NLS  -LOCALES_HACK  +HAVE_WC_FUNCS  +HAVE_LANGINFO_CODESET  +HAVE_LANGINFO_YESEXPR  
+HAVE_ICONV  -ICONV_NONTRANS  +HAVE_LIBIDN  +HAVE_GETSID  +USE_HCACHE  
ISPELL="/usr/bin/hunspell"
SENDMAIL="/usr/sbin/sendmail"
MAILPATH="/var/mail"
PKGDATADIR="/usr/share/mutt"
SYSCONFDIR="/etc"
EXECSHELL="/bin/sh"
-MIXMASTER
To contact the developers, please mail to <mutt-dev@mutt.org>.
To report a bug, please visit http://bugs.mutt.org/.
>nvim --version
NVIM 0.0.0-alpha+201503241204 (compiled Mar 24 2015 16:55:55)
Commit: 5860d65f9cf4205b845e4fb5e8512ef8929cf227
Build type: Debug
Compilation: /bin/cc -Wconversion -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -DINCLUDE_GENERATED_DECLARATIONS -DHAVE_CONFIG_H -I/home/ntnn/prog/neovim/build/config -I/home/ntnn/prog/neovim/src -I/home/ntnn/prog/neovim/.deps/usr/include -I/home/ntnn/prog/neovim/.deps/usr/include -I/home/ntnn/prog/neovim/.deps/usr/include/luajit-2.0 -I/home/ntnn/prog/neovim/.deps/usr/include -I/home/ntnn/prog/neovim/.deps/usr/include -I/home/ntnn/prog/neovim/.deps/usr/include -I/usr/include -I/home/ntnn/prog/neovim/build/src/nvim/auto -I/home/ntnn/prog/neovim/build/include
Compiled by root@Persephone

Optional features included (+) or not (-): +acl  +iconv 
For differences from Vim, see :help vim-differences

   system vimrc file: "$VIM/nvimrc"
     user vimrc file: "~/.nvimrc"
 2nd user vimrc file: "~/.nvim/nvimrc"
      user exrc file: "~/.exrc"
  fall-back for $VIM: "/usr/local/share/nvim"

@Dru89
Copy link

Dru89 commented Mar 25, 2015

I'm having a similar problem with the code review tool that we use: Arcanist.

It seems to occur when something would prompt you for a value after you exit the editor. When I run this for arcanist, I get the following result:

Commit message has errors:

      - Invalid or missing field "Test Plan": You must provide a test plan.
      Describe the actions you performed to verify the behavior of this
      change.

You must resolve these errors to continue.

    Do you want to edit the message? [Y/n]

It never actually lets me answer the prompt, though, and goes straight to the default option.

I think can reproduce this behaviour with the following simple shell file:

# /Users/drew/testnvim
nvim /tmp/whatever
read -p "Reading a value: " value

This produces the following result:

Reading a value...: /Users/drew/bin/testnvim: line 3: read: read error: 0: Resource temporarily unavailable

I see that that same Resource temporarily unavailable error also seems to be repeated from mutt.

@justinmk
Copy link
Member

@Dru89 That sounds more like #1044. That is, any command that operates in "interactive mode" will exhibit that behavior. The workaround is #2076.

@tarruda tarruda added the tui label Apr 8, 2015
@bigeagle
Copy link

I'm suffering from this bug, too.

@ryanmorillo
Copy link

Here is a strace after I've written the message and getting ready to hit the 'p' key in mutt. We can see that mutt is trying to write the menu (it works the same with q), and every once in a while, you can see something pop up on the status line. #2076 doesn't work. Same behavior is exhibited. (Ends with me sending SIGHUP)

select(1, [0], NULL, NULL, {5, 0}) = 0 (Timeout)
rt_sigaction(SIGINT, {0x46bcf0, [], SA_RESTORER|SA_RESTART, 0x7feec8733180}, NULL, 8) = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig -icanon -echo ...}) = 0
write(1, "\33[?12l\33[?25h", 12) = 12
write(1, "\33[?25l", 6) = 6
rt_sigaction(SIGINT, {0x46bcf0, [], SA_RESTORER, 0x7feec8733180}, NULL, 8) = 0
select(1, [0], NULL, NULL, {5, 0}) = 1 (in [0], left {2, 643643})
read(0, "p", 1) = 1
rt_sigaction(SIGINT, {0x46bcf0, [], SA_RESTORER|SA_RESTART, 0x7feec8733180}, NULL, 8) = 0
write(1, "\33[?12l\33[?25h", 12) = 12
write(1, "\r\33[68d\33[37m\33[40mPGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, (i)nline format, or (c)lear? \33(B\33[m\33[39;49m\33[37m\33[40m", 111) = 111
rt_sigaction(SIGINT, {0x46bcf0, [], SA_RESTORER, 0x7feec8733180}, NULL, 8) = 0
read(0, 0x7ffe03419f1f, 1) = -1 EAGAIN (Resource temporarily unavailable)
rt_sigaction(SIGINT, {0x46bcf0, [], SA_RESTORER|SA_RESTART, 0x7feec8733180}, NULL, 8) = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400 opost isig -icanon -echo ...}) = 0
write(1, "\r\33[37m\33[40m\33[J\33(B\33[m\33[39;49m\33[37m\33[40m", 38) = 38
write(1, "\33[?25l", 6) = 6
write(1, "\33[13;119H", 9) = 9
rt_sigaction(SIGINT, {0x46bcf0, [], SA_RESTORER, 0x7feec8733180}, NULL, 8) = 0
rt_sigaction(SIGINT, {0x46bcf0, [], SA_RESTORER|SA_RESTART, 0x7feec8733180}, NULL, 8) = 0
Caught signal 1... Exiting. or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, {B38400

@justinmk
Copy link
Member

justinmk commented May 7, 2015

@Stebalien @ntnn @ryanmorillo @bigeagle #2598 may fix this issue if you want to try.

@ntnn
Copy link

ntnn commented May 7, 2015

@justinmk Works like a charm, awesome work!

justinmk added a commit to justinmk/neovim that referenced this issue May 24, 2015
If stdin is non-blocking, many tools (e.g. cat(1), read(1)) which assume
that stdin is blocking, will break in odd ways:

  read: read error: 0: Resource temporarily unavailable
  cat: -: Resource temporarily unavailable
  rm: error closing file

libuv puts stdin in nonblocking mode, and leaves it that way at exit
(this is apparently by design). So, before this commit, this always
works (because the shell clobbers O_NONBLOCK):

  $ nvim --cmd q
  $ read

...but these forms do _not_ work:

  $ nvim --cmd q && read
  $ echo foo | nvim --cmd q && read
  $ nvim && read

After this commit, all of the above forms work.

Background:

fish-shell/fish-shell@437b439#diff-41f4d294430cd8c36538999d62681ae2
fish-shell/fish-shell#176 (comment)

- bash (and other shells: zsh, tcsh, fish), upon returning to the
  foreground, always sets fd 0 back to blocking mode. This practice only
  applies to stdin, _not_ stdout or stderr (in practice these fds may be
  affected anyways).
- bash/zsh/tcsh/fish do _not_ restore the non-blocking status of stdin
  when _resuming a job_.
- We do _not_ save/restore the original flags visible to
  fcntl(F_[SG]ETFL), because (counterintuitively) that isn't expected.

Helped-by: oni-link <knil.ino@gmail.com>

Closes neovim#2086
Closes neovim#2377
justinmk added a commit to justinmk/neovim that referenced this issue May 24, 2015
If stdin is non-blocking, many tools (e.g. cat(1), read(1)) which assume
that stdin is blocking, will break in odd ways:

  read: read error: 0: Resource temporarily unavailable
  cat: -: Resource temporarily unavailable
  rm: error closing file

libuv puts stdin in nonblocking mode, and leaves it that way at exit
(this is apparently by design). So, before this commit, this always
works (because the shell clobbers O_NONBLOCK):

  $ nvim --cmd q
  $ read

...but these forms do _not_ work:

  $ nvim --cmd q && read
  $ echo foo | nvim --cmd q && read
  $ nvim && read

After this commit, all of the above forms work.

Background:

fish-shell/fish-shell@437b439#diff-41f4d294430cd8c36538999d62681ae2
fish-shell/fish-shell#176 (comment)

- bash (and other shells: zsh, tcsh, fish), upon returning to the
  foreground, always sets fd 0 back to blocking mode. This practice only
  applies to stdin, _not_ stdout or stderr (in practice these fds may be
  affected anyways).
- bash/zsh/tcsh/fish do _not_ restore the non-blocking status of stdin
  when _resuming a job_.
- We do _not_ save/restore the original flags visible to
  fcntl(F_[SG]ETFL), because (counterintuitively) that isn't expected.

Helped-by: oni-link <knil.ino@gmail.com>

Closes neovim#2086
Closes neovim#2377
justinmk added a commit to justinmk/neovim that referenced this issue May 25, 2015
If stdin is non-blocking, many tools (e.g. cat(1), read(1)) which assume
that stdin is blocking, will break in odd ways:

  read: read error: 0: Resource temporarily unavailable
  cat: -: Resource temporarily unavailable
  rm: error closing file

libuv puts stdin in nonblocking mode, and leaves it that way at exit
(this is apparently by design). So, before this commit, this always
works (because the shell clobbers O_NONBLOCK):

  $ nvim --cmd q
  $ read

...but these forms do _not_ work:

  $ nvim --cmd q && read
  $ echo foo | nvim --cmd q && read
  $ nvim && read

After this commit, all of the above forms work.

Background:

fish-shell/fish-shell@437b439#diff-41f4d294430cd8c36538999d62681ae2
fish-shell/fish-shell#176 (comment)

- bash (and other shells: zsh, tcsh, fish), upon returning to the
  foreground, always sets fd 0 back to blocking mode. This practice only
  applies to stdin, _not_ stdout or stderr (in practice these fds may be
  affected anyways).
- bash/zsh/tcsh/fish do _not_ restore the non-blocking status of stdin
  when _resuming a job_.
- We do _not_ save/restore the original flags visible to
  fcntl(F_[SG]ETFL), because (counterintuitively) that isn't expected.

Helped-by: oni-link <knil.ino@gmail.com>

Closes neovim#2086
Closes neovim#2377

---

Note: The following implementation of stream_set_blocking() was
discarded, because it resulted in a failed libuv assertion[1]:

  int stream_set_blocking(int fd, bool blocking)
  {
    uv_pipe_t stream;
    uv_pipe_init(uv_default_loop(), &stream, 0);
    uv_pipe_open(&stream, fd);
    int retval = uv_stream_set_blocking((uv_stream_t *)&stream, blocking);
    uv_close((uv_handle_t *)&stream, NULL);
    return retval;
  }

[1] .deps/build/src/libuv/src/unix/core.c:833: uv__io_stop: Assertion `loop->watchers[w->fd] == w' failed.
justinmk added a commit to justinmk/neovim that referenced this issue May 25, 2015
If stdin is non-blocking, many tools (e.g. cat(1), read(1)) which assume
that stdin is blocking, will break in odd ways:

  read: read error: 0: Resource temporarily unavailable
  cat: -: Resource temporarily unavailable
  rm: error closing file

libuv puts stdin in nonblocking mode, and leaves it that way at exit
(this is apparently by design). So, before this commit, this always
works (because the shell clobbers O_NONBLOCK):

  $ nvim --cmd q
  $ read

...but these forms do _not_ work:

  $ nvim --cmd q && read
  $ echo foo | nvim --cmd q && read
  $ nvim && read

After this commit, all of the above forms work.

Background:

fish-shell/fish-shell@437b439#diff-41f4d294430cd8c36538999d62681ae2
fish-shell/fish-shell#176 (comment)

- bash (and other shells: zsh, tcsh, fish), upon returning to the
  foreground, always sets fd 0 back to blocking mode. This practice only
  applies to stdin, _not_ stdout or stderr (in practice these fds may be
  affected anyways).
- bash/zsh/tcsh/fish do _not_ restore the non-blocking status of stdin
  when _resuming a job_.
- We do _not_ save/restore the original flags visible to
  fcntl(F_[SG]ETFL), because (counterintuitively) that isn't expected.

Helped-by: oni-link <knil.ino@gmail.com>

Closes neovim#2086
Closes neovim#2377

---

Note: The following implementation of stream_set_blocking() was
discarded, because it resulted in a failed libuv assertion[1]:

  int stream_set_blocking(int fd, bool blocking)
  {
    uv_pipe_t stream;
    uv_pipe_init(uv_default_loop(), &stream, 0);
    uv_pipe_open(&stream, fd);
    int retval = uv_stream_set_blocking((uv_stream_t *)&stream, blocking);
    uv_close((uv_handle_t *)&stream, NULL);
    return retval;
  }

[1] .deps/build/src/libuv/src/unix/core.c:833: uv__io_stop: Assertion `loop->watchers[w->fd] == w' failed.
justinmk added a commit to justinmk/neovim that referenced this issue May 25, 2015
If stdin is non-blocking, many tools (e.g. cat(1), read(1)) which assume
that stdin is blocking, will break in odd ways:

  read: read error: 0: Resource temporarily unavailable
  cat: -: Resource temporarily unavailable
  rm: error closing file

libuv puts stdin in nonblocking mode, and leaves it that way at exit
(this is apparently by design). So, before this commit, this always
works (because the shell clobbers O_NONBLOCK):

  $ nvim --cmd q
  $ read

...but these forms do _not_ work:

  $ nvim --cmd q && read
  $ echo foo | nvim --cmd q && read
  $ nvim && read

After this commit, all of the above forms work.

Background:

fish-shell/fish-shell@437b439#diff-41f4d294430cd8c36538999d62681ae2
fish-shell/fish-shell#176 (comment)

- bash (and other shells: zsh, tcsh, fish), upon returning to the
  foreground, always sets fd 0 back to blocking mode. This practice only
  applies to stdin, _not_ stdout or stderr (in practice these fds may be
  affected anyways).
- bash/zsh/tcsh/fish do _not_ restore the non-blocking status of stdin
  when _resuming a job_.
- We do _not_ save/restore the original flags visible to
  fcntl(F_[SG]ETFL), because (counterintuitively) that isn't expected.

Helped-by: oni-link <knil.ino@gmail.com>

Closes neovim#2086
Closes neovim#2377

---

Note: The following implementation of stream_set_blocking() was
discarded, because it resulted in a failed libuv assertion[1]:

  int stream_set_blocking(int fd, bool blocking)
  {
    uv_pipe_t stream;
    uv_pipe_init(uv_default_loop(), &stream, 0);
    uv_pipe_open(&stream, fd);
    int retval = uv_stream_set_blocking((uv_stream_t *)&stream, blocking);
    uv_close((uv_handle_t *)&stream, NULL);
    return retval;
  }

[1] .deps/build/src/libuv/src/unix/core.c:833: uv__io_stop: Assertion `loop->watchers[w->fd] == w' failed.
@justinmk
Copy link
Member

Should be fixed now, please say if not!

@Stebalien
Copy link
Author

Works for me. Thanks!

@bigeagle
Copy link

Works for me, too. Cheers!

On 15-05-27 06:54, Steven Allen wrote:

Works for me. Thanks!


Reply to this email directly or view it on GitHub:
#2086 (comment)

Justin Wong

Blog: https://bigeagle.me/
Fingerprint: 15CC 6A61 738B 1599 0095 E256 CB67 DA7A 865B AC3A

@nicoe
Copy link

nicoe commented Jun 5, 2015

Works for me too.

Dru89 added a commit to Dru89/dotfiles that referenced this issue Feb 27, 2016
I have to change my editor in mutt until
neovim/neovim#2086 (comment)
is fixed.

Neovim is sending some characters to stdout, which is preventing some
applications that rely on keys being sent afterwards from functioning
correctly.  Vim works just fine for these, though.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issues reporting wrong behavior tui
Projects
None yet
Development

No branches or pull requests

8 participants