Except making standard fds to blocking state, everything works perfectly fine without the patch.
On Wed, Nov 16, 2016 at 2:43 PM, Nicholas Marriott < [email protected]> wrote: > > does this happen without the patch? > > > > On Wed, Nov 16, 2016 at 09:57:49AM +0530, Prabhuram K wrote: > > Hi Nicholas, > > Many thanks. It now sets non-blocking always with the patch. > > However get in to another issue now. It works till I have only one > window > > in the session. > > As soon as I attach a new-window to this existing session, the tmux > just > > freezes. Though I could see prints are coming in to the screen, input > is > > not working. As soon as I killed the new-window, everything backs to > > normal. Any Idea? > > > > Thanks, > > Prabhu > > On Wed, Nov 16, 2016 at 6:14 AM, Nicholas Marriott > > <[1][email protected]> wrote: > > > > Right, but if you run an application in a terminal, they will all be > > dup()'d file descriptors referencing the same object (open()ed from > some > > /dev/pty). On most (maybe all) *nix, O_NONBLOCK is an attribute of > that > > object, not the descriptors - if you change one, you change them > all. > > > > tmux only changes stdin, but your stdout and stderr point to the > same > > object so they will be changed too. > > > > On Wed, Nov 16, 2016 at 06:01:43AM +0530, Prabhuram K wrote: > > >** ** As for as I know STDIN STDOUT STDERR fds are defined with 0, > 1 > > and 2. I > > >** ** can try the patch anyway.** Thanks again. > > > > > >** ** On Nov 16, 2016 5:54 AM, "Nicholas Marriott" > > >** ** <[1][2][email protected]> wrote: > > > > > >** ** ** stdin and stdout and stderr are probably all the same file > > descriptor. > > > > > >** ** ** On Wed, Nov 16, 2016 at 05:53:52AM +0530, Prabhuram K > wrote: > > >** ** ** >** ** Hi Nicholas, > > >** ** ** >** ** Thanks a lot for the patch. But it's not just > STDIN. > > setting to > > >** ** ** blocking. > > >** ** ** >** ** Even STDOUT and STDERR also going back to blocking > > state. Do I > > >** ** ** need to add > > >** ** ** >** ** similar code for other fds? > > >** ** ** > > > >** ** ** >** ** BTW: Your question on why reinitialize back, I am > > running with a > > >** ** ** real time > > >** ** ** >** ** system and I run my application multiple instances > > under tmux and > > >** ** ** >** ** sometimes simultaneously. So I don't want this to > be > > done from my > > >** ** ** >** ** application rather from tmux itself. > > >** ** ** > > > >** ** ** >** ** Thanks a lot for your help > > >** ** ** > > > >** ** ** >** ** Regards, > > >** ** ** >** ** Prabhu > > >** ** ** > > > >** ** ** >** ** On Nov 16, 2016 5:17 AM, "Nicholas Marriott" > > >** ** ** >** ** <[1][2][3][email protected]> wrote: > > >** ** ** > > > >** ** ** >** ** ** You could try this: > > >** ** ** > > > >** ** ** >** ** ** Index: client.c > > >** ** ** >** ** ** > > >** ** ** > > =================================================================== > > >** ** ** >** ** ** RCS file: /cvs/src/usr.bin/tmux/client.c,v > > >** ** ** >** ** ** retrieving revision 1.114 > > >** ** ** >** ** ** diff -u -p -r1.114 client.c > > >** ** ** >** ** ** --- client.c** ** 3 Oct 2016 22:52:11 -0000** > ** ** > > **1.114 > > >** ** ** >** ** ** +++ client.c** ** 15 Nov 2016 23:47:22 -0000 > > >** ** ** >** ** ** @@ -38,6 +38,7 @@ static struct tmuxproc** ** > ** ** > > >** ** ** *client_proc; > > >** ** ** >** ** ** **static struct tmuxpeer *client_peer; > > >** ** ** >** ** ** **static int** ** ** ** ** ** ** client_flags; > > >** ** ** >** ** ** **static struct event** ** **client_stdin; > > >** ** ** >** ** ** +static int** ** ** ** ** ** ** > > client_stdin_blocking; > > >** ** ** >** ** ** **static enum { > > >** ** ** >** ** ** ** ** ** ** CLIENT_EXIT_NONE, > > >** ** ** >** ** ** ** ** ** ** CLIENT_EXIT_DETACHED, > > >** ** ** >** ** ** @@ -306,10 +307,12 @@ client_main(struct > event_base > > *base, int > > >** ** ** >** ** ** ** ** ** ** options_free(global_w_options); > > >** ** ** >** ** ** ** ** ** ** environ_free(global_environ); > > >** ** ** > > > >** ** ** >** ** ** -** ** ** **/* Create stdin handler. */ > > >** ** ** >** ** ** -** ** ** **setblocking(STDIN_FILENO, 0); > > >** ** ** >** ** ** +** ** ** **/* Create stdin event. */ > > >** ** ** >** ** ** ** ** ** ** event_set(&client_stdin, > STDIN_FILENO, > > >** ** ** EV_READ|EV_PERSIST, > > >** ** ** >** ** ** ** ** ** ** ** ** client_stdin_callback, NULL); > > >** ** ** >** ** ** +** ** ** **client_stdin_blocking = > > getblocking(STDIN_FILENO); > > >** ** ** >** ** ** + > > >** ** ** >** ** ** +** ** ** **/* Configure terminal for control > mode. > > */ > > >** ** ** >** ** ** ** ** ** ** if (client_flags & > > CLIENT_CONTROLCONTROL) { > > >** ** ** >** ** ** ** ** ** ** ** ** ** ** if > (tcgetattr(STDIN_FILENO, > > >** ** ** &saved_tio) != 0) > > >** ** ** >** ** ** ** ** ** ** ** ** ** ** ** ** ** ** > fatal("tcgetattr > > failed"); > > >** ** ** >** ** ** @@ -375,7 +378,7 @@ client_main(struct > event_base > > *base, int > > >** ** ** >** ** ** ** ** ** ** ** ** ** ** tcsetattr(STDOUT_FILENO, > > TCSAFLUSH, > > >** ** ** &saved_tio); > > >** ** ** >** ** ** ** ** ** ** } else if (client_exitreason != > > CLIENT_EXIT_NONE) > > >** ** ** >** ** ** ** ** ** ** ** ** ** ** fprintf(stderr, "%s\n", > > >** ** ** client_exit_message()); > > >** ** ** >** ** ** -** ** ** **setblocking(STDIN_FILENO, 1); > > >** ** ** >** ** ** +** ** ** **setblocking(STDIN_FILENO, > > client_stdin_blocking); > > >** ** ** >** ** ** ** ** ** ** return (client_exitval); > > >** ** ** >** ** ** **} > > >** ** ** > > > >** ** ** >** ** ** @@ -585,6 +588,7 @@ client_dispatch_wait(struct > imsg > > *imsg, > > >** ** ** >** ** ** ** ** ** ** ** ** ** ** if (datalen != 0) > > >** ** ** >** ** ** ** ** ** ** ** ** ** ** ** ** ** ** fatalx("bad > > MSG_STDIN > > >** ** ** size"); > > >** ** ** > > > >** ** ** >** ** ** +** ** ** ** ** ** ** > **setblocking(STDIN_FILENO, > > 0); > > >** ** ** >** ** ** ** ** ** ** ** ** ** ** event_add(&client_stdin, > > NULL); > > >** ** ** >** ** ** ** ** ** ** ** ** ** ** break; > > >** ** ** >** ** ** ** ** ** ** case MSG_STDOUT: > > >** ** ** >** ** ** Index: tmux.c > > >** ** ** >** ** ** > > >** ** ** > > =================================================================== > > >** ** ** >** ** ** RCS file: /cvs/src/usr.bin/tmux/tmux.c,v > > >** ** ** >** ** ** retrieving revision 1.172 > > >** ** ** >** ** ** diff -u -p -r1.172 tmux.c > > >** ** ** >** ** ** --- tmux.c** ** ** 11 Oct 2016 13:21:59 -0000** > ** > > ** 1.172 > > >** ** ** >** ** ** +++ tmux.c** ** ** 15 Nov 2016 23:47:22 -0000 > > >** ** ** >** ** ** @@ -150,18 +150,31 @@ fail: > > >** ** ** >** ** ** ** ** ** ** return (NULL); > > >** ** ** >** ** ** **} > > >** ** ** > > > >** ** ** >** ** ** +int > > >** ** ** >** ** ** +getblocking(int fd) > > >** ** ** >** ** ** +{ > > >** ** ** >** ** ** +** ** ** **int** ** **mode; > > >** ** ** >** ** ** + > > >** ** ** >** ** ** +** ** ** **if ((mode = fcntl(fd, F_GETFL)) == > -1) > > >** ** ** >** ** ** +** ** ** ** ** ** ** **return (-1); > > >** ** ** >** ** ** +** ** ** **if (mode & O_NONBLOCK) > > >** ** ** >** ** ** +** ** ** ** ** ** ** **return (0); > > >** ** ** >** ** ** +** ** ** **return (1); > > >** ** ** >** ** ** +} > > >** ** ** >** ** ** + > > >** ** ** >** ** ** **void > > >** ** ** >** ** ** **setblocking(int fd, int state) > > >** ** ** >** ** ** **{ > > >** ** ** >** ** ** -** ** ** **int mode; > > >** ** ** >** ** ** +** ** ** **int** ** **mode, new_mode; > > >** ** ** > > > >** ** ** >** ** ** -** ** ** **if ((mode = fcntl(fd, F_GETFL)) != > -1) { > > >** ** ** >** ** ** -** ** ** ** ** ** ** **if (!state) > > >** ** ** >** ** ** -** ** ** ** ** ** ** ** ** ** ** **mode |= > > O_NONBLOCK; > > >** ** ** >** ** ** -** ** ** ** ** ** ** **else > > >** ** ** >** ** ** -** ** ** ** ** ** ** ** ** ** ** **mode &= > > ~O_NONBLOCK; > > >** ** ** >** ** ** +** ** ** **if (state == -1 || (mode = fcntl(fd, > > F_GETFL)) == > > >** ** ** -1) > > >** ** ** >** ** ** +** ** ** ** ** ** ** **return; > > >** ** ** >** ** ** +** ** ** **if (state) > > >** ** ** >** ** ** +** ** ** ** ** ** ** **new_mode = (mode | > > O_NONBLOCK); > > >** ** ** >** ** ** +** ** ** **else > > >** ** ** >** ** ** +** ** ** ** ** ** ** **new_mode = (mode & > > ~O_NONBLOCK); > > >** ** ** >** ** ** +** ** ** **if (new_mode != mode) > > >** ** ** >** ** ** ** ** ** ** ** ** ** ** fcntl(fd, F_SETFL, > mode); > > >** ** ** >** ** ** -** ** ** **} > > >** ** ** >** ** ** **} > > >** ** ** > > > >** ** ** >** ** ** **const char * > > >** ** ** >** ** ** Index: tmux.h > > >** ** ** >** ** ** > > >** ** ** > > =================================================================== > > >** ** ** >** ** ** RCS file: /cvs/src/usr.bin/tmux/tmux.h,v > > >** ** ** >** ** ** retrieving revision 1.677 > > >** ** ** >** ** ** diff -u -p -r1.677 tmux.h > > >** ** ** >** ** ** --- tmux.h** ** ** 15 Nov 2016 15:17:28 -0000** > ** > > ** 1.677 > > >** ** ** >** ** ** +++ tmux.h** ** ** 15 Nov 2016 23:47:23 -0000 > > >** ** ** >** ** ** @@ -1105,6 +1105,7 @@ struct tty { > > >** ** ** >** ** ** ** ** ** ** struct tty_term *term; > > >** ** ** > > > >** ** ** >** ** ** ** ** ** ** int** ** ** ** ** ** ** fd; > > >** ** ** >** ** ** +** ** ** **int** ** ** ** ** ** ** blocking; > > >** ** ** >** ** ** ** ** ** ** struct bufferevent *event; > > >** ** ** > > > >** ** ** >** ** ** ** ** ** ** struct termios** **tio; > > >** ** ** >** ** ** @@ -1512,6 +1513,7 @@ extern struct environ** ** > > >** ** ** ***global_environ; > > >** ** ** >** ** ** **extern struct timeval** **start_time; > > >** ** ** >** ** ** **extern const char** ** ** *socket_path; > > >** ** ** >** ** ** **int** ** ** ** ** ** **areshell(const char *); > > >** ** ** >** ** ** +int** ** ** ** ** ** **getblocking(int); > > >** ** ** >** ** ** **void** ** ** ** ** ** setblocking(int, int); > > >** ** ** >** ** ** **const char** ** ***find_home(void); > > >** ** ** > > > >** ** ** >** ** ** Index: tty.c > > >** ** ** >** ** ** > > >** ** ** > > =================================================================== > > >** ** ** >** ** ** RCS file: /cvs/src/usr.bin/tmux/tty.c,v > > >** ** ** >** ** ** retrieving revision 1.214 > > >** ** ** >** ** ** diff -u -p -r1.214 tty.c > > >** ** ** >** ** ** --- tty.c** ** ** **15 Nov 2016 15:17:28 > -0000** ** > > ** 1.214 > > >** ** ** >** ** ** +++ tty.c** ** ** **15 Nov 2016 23:47:23 -0000 > > >** ** ** >** ** ** @@ -237,6 +237,7 @@ tty_init_termios(int fd, > struct > > termios > > >** ** ** >** ** ** **void > > >** ** ** >** ** ** **tty_start_tty(struct tty *tty) > > >** ** ** >** ** ** **{ > > >** ** ** >** ** ** +** ** ** **tty->blocking = > getblocking(tty->fd); > > >** ** ** >** ** ** ** ** ** ** tty_init_termios(tty->fd, &tty->tio, > > tty->event); > > >** ** ** > > > >** ** ** >** ** ** ** ** ** ** tty_putcode(tty, TTYC_SMCUP); > > >** ** ** >** ** ** @@ -330,7 +331,7 @@ tty_stop_tty(struct tty > *tty) > > >** ** ** >** ** ** ** ** ** ** ** ** ** ** tty_raw(tty, > "\033[?69l"); > > /* DECLRMM > > >** ** ** */ > > >** ** ** >** ** ** ** ** ** ** tty_raw(tty, > tty_term_string(tty->term, > > >** ** ** TTYC_RMCUP)); > > >** ** ** > > > >** ** ** >** ** ** -** ** ** **setblocking(tty->fd, 1); > > >** ** ** >** ** ** +** ** ** **setblocking(tty->fd, tty->blocking); > > >** ** ** >** ** ** **} > > >** ** ** > > > >** ** ** >** ** ** **void > > >** ** ** > > > >** ** ** >** ** ** On Tue, Nov 15, 2016 at 11:33:02PM +0000, > Nicholas > > Marriott > > >** ** ** wrote: > > >** ** ** >** ** ** > tmux sets stdin nonblocking then sets it > blocking > > again on > > >** ** ** exit, we > > >** ** ** >** ** ** > could probably not do that unless we are > going to > > use it, > > >** ** ** and restore > > >** ** ** >** ** ** > it only if it wasn't already nonblocking. But > TBH > > does it > > >** ** ** matter that > > >** ** ** >** ** ** > much? Why not just set it nonblocking yourself > > after you run > > >** ** ** tmux? > > >** ** ** >** ** ** > > > >** ** ** >** ** ** > > > >** ** ** >** ** ** > On Tue, Nov 15, 2016 at 11:01:54PM +0530, > > Prabhuram K wrote: > > >** ** ** >** ** ** > >** ** Hi, > > >** ** ** >** ** ** > >** ** I have an application and run it under > > tmux. > > >** ** ** >** ** ** > >** ** The application sets** STDIN_FILENO, > > STDOUT_FILENO > > >** ** ** and > > >** ** ** >** ** ** STDERR_FILENO to > > >** ** ** >** ** ** > >** ** nonblocking using fcntl calls. > > >** ** ** >** ** ** > >** ** The application internally loads the > tmux > > >** ** ** configuration file > > >** ** ** >** ** ** using system > > >** ** ** >** ** ** > >** ** command (tmux source-file xxx). Soon > after > > this is > > >** ** ** executed > > >** ** ** >** ** ** inside from my > > >** ** ** >** ** ** > >** ** application, all the > STDIN/STDOUT/STDERR > > fds sets > > >** ** ** back to > > >** ** ** >** ** ** blocking state. > > >** ** ** >** ** ** > >** ** Not sure what is the problem here. Why > tmux > > always > > >** ** ** sets the fds > > >** ** ** >** ** ** to > > >** ** ** >** ** ** > >** ** blocking state. Is there a way to > always > > set to > > >** ** ** non-blocking. > > >** ** ** >** ** ** > >** ** Any help is highly appreciated. > > >** ** ** >** ** ** > > > > >** ** ** >** ** ** > >** ** Thanks, > > >** ** ** >** ** ** > >** ** Prabhu > > >** ** ** >** ** ** > > > > >** ** ** >** ** ** > >** ** -- > > >** ** ** >** ** ** > >** ** You received this message because you > are > > subscribed > > >** ** ** to the > > >** ** ** >** ** ** Google Groups > > >** ** ** >** ** ** > >** ** "tmux-users" group. > > >** ** ** >** ** ** > >** ** To unsubscribe from this group and stop > > receiving > > >** ** ** emails from > > >** ** ** >** ** ** it, send an > > >** ** ** >** ** ** > >** ** email to > > >** ** ** [1][2][3][4][email protected]. > > >** ** ** >** ** ** > >** ** To post to this group, send email to > > >** ** ** >** ** ** [2][3][4][5][email protected]. > > >** ** ** >** ** ** > >** ** For more options, visit > > >** ** ** >** ** ** [3][4][5][6]https://groups.google.com/d/optout. > > >** ** ** >** ** ** > > > > >** ** ** >** ** ** > > References > > >** ** ** >** ** ** > > > > >** ** ** >** ** ** > >** ** Visible links > > >** ** ** >** ** ** > >** ** 1. > > >** ** ** mailto:[5][6][7][email protected] > > >** ** ** >** ** ** > >** ** 2. > > mailto:[6][7][8][email protected] > > >** ** ** >** ** ** > >** ** 3. > > [7][8][9]https://groups.google.com/d/optout > > >** ** ** > > > >** ** ** > References > > >** ** ** > > > >** ** ** >** ** Visible links > > >** ** ** >** ** 1. mailto:[9][10][email protected] > > >** ** ** >** ** 2. > > mailto:[10][11]tmux-users%[email protected] > > >** ** ** >** ** 3. mailto:[11][12][email protected] > > >** ** ** >** ** 4. [12][13]https://groups.google.com/d/optout > > >** ** ** >** ** 5. > > mailto:[13][14]tmux-users%[email protected] > > >** ** ** >** ** 6. mailto:[14][15][email protected] > > >** ** ** >** ** 7. [15][16]https://groups.google.com/d/optout > > > > > >** ** -- > > >** ** You received this message because you are subscribed to the > > Google Groups > > >** ** "tmux-users" group. > > >** ** To unsubscribe from this group and stop receiving emails > from it, > > send an > > >** ** email to [16][17][email protected]. > > >** ** To post to this group, send email to > > [17][18][email protected]. > > >** ** For more options, visit > > [18][19]https://groups.google.com/d/optout. > > > > > > References > > > > > >** ** Visible links > > >** ** 1. mailto:[20][email protected] > > >** ** 2. mailto:[21][email protected] > > >** ** 3. mailto:[22]tmux-users%[email protected] > > >** ** 4. mailto:[23][email protected] > > >** ** 5. [24]https://groups.google.com/d/optout > > >** ** 6. mailto:[25]tmux-users%[email protected] > > >** ** 7. mailto:[26][email protected] > > >** ** 8. [27]https://groups.google.com/d/optout > > >** ** 9. mailto:[28][email protected] > > >** **10. mailto:[29]tmux-users%[email protected] > > >** **11. mailto:[30][email protected] > > >** **12. [31]https://groups.google.com/d/optout > > >** **13. mailto:[32]tmux-users%[email protected] > > >** **14. mailto:[33][email protected] > > >** **15. [34]https://groups.google.com/d/optout > > >** **16. mailto:[35][email protected] > > >** **17. mailto:[36][email protected] > > >** **18. [37]https://groups.google.com/d/optout > > > > -- > > You received this message because you are subscribed to the Google > Groups > > "tmux-users" group. > > To unsubscribe from this group and stop receiving emails from it, > send an > > email to [38][email protected]. > > To post to this group, send email to [39][email protected]. > > For more options, visit [40]https://groups.google.com/d/optout. > > > > References > > > > Visible links > > 1. mailto:[email protected] > > 2. mailto:[email protected] > > 3. mailto:[email protected] > > 4. mailto:tmux-users%[email protected] > > 5. mailto:[email protected] > > 6. https://groups.google.com/d/optout > > 7. mailto:tmux-users%[email protected] > > 8. mailto:[email protected] > > 9. https://groups.google.com/d/optout > > 10. mailto:[email protected] > > 11. mailto:tmux-users%[email protected] > > 12. mailto:[email protected] > > 13. https://groups.google.com/d/optout > > 14. mailto:tmux-users%[email protected] > > 15. mailto:[email protected] > > 16. https://groups.google.com/d/optout > > 17. mailto:tmux-users%[email protected] > > 18. mailto:[email protected] > > 19. https://groups.google.com/d/optout > > 20. mailto:[email protected] > > 21. mailto:[email protected] > > 22. mailto:tmux-users%[email protected] > > 23. mailto:[email protected] > > 24. https://groups.google.com/d/optout > > 25. mailto:tmux-users%[email protected] > > 26. mailto:[email protected] > > 27. https://groups.google.com/d/optout > > 28. mailto:[email protected] > > 29. mailto:tmux-users%[email protected] > > 30. mailto:[email protected] > > 31. https://groups.google.com/d/optout > > 32. mailto:tmux-users%[email protected] > > 33. mailto:[email protected] > > 34. https://groups.google.com/d/optout > > 35. mailto:tmux-users%[email protected] > > 36. mailto:[email protected] > > 37. https://groups.google.com/d/optout > > 38. mailto:[email protected] > > 39. mailto:[email protected] > > 40. https://groups.google.com/d/optout > -- You received this message because you are subscribed to the Google Groups "tmux-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
