I mean the same underlying file description of course, they are
naturally different file descriptors.


On Wed, Nov 16, 2016 at 12:24:39AM +0000, Nicholas Marriott 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][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][email protected].
> >      > >** ** To post to this group, send email to
> >      [2][3][email protected].
> >      > >** ** For more options, visit
> >      [3][4]https://groups.google.com/d/optout.
> >      > >
> >      > > References
> >      > >
> >      > >** ** Visible links
> >      > >** ** 1. mailto:[5][email protected]
> >      > >** ** 2. mailto:[6][email protected]
> >      > >** ** 3. [7]https://groups.google.com/d/optout
> > 
> > References
> > 
> >    Visible links
> >    1. mailto:[email protected]
> >    2. mailto:tmux-users%[email protected]
> >    3. mailto:[email protected]
> >    4. https://groups.google.com/d/optout
> >    5. mailto:tmux-users%[email protected]
> >    6. mailto:[email protected]
> >    7. 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.

Reply via email to