summaryrefslogtreecommitdiffstats
path: root/tmux.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2011-01-08 01:52:36 +0000
committerNicholas Marriott <nicm@openbsd.org>2011-01-08 01:52:36 +0000
commit69cb1f830e4fd2282ddcbc7ee2bbe30069b9e4cd (patch)
tree49efff28238bbba524974db0512859a310d0b09c /tmux.c
parent703160b5d6b64e45a684894260693c60b5524d51 (diff)
Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things like "tmux ls && cat").
Diffstat (limited to 'tmux.c')
-rw-r--r--tmux.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/tmux.c b/tmux.c
index 007d81fd..3b40da12 100644
--- a/tmux.c
+++ b/tmux.c
@@ -194,12 +194,25 @@ makesocketpath(const char *label)
return (path);
}
+void
+setblocking(int fd, int state)
+{
+ int mode;
+
+ if ((mode = fcntl(fd, F_GETFL)) != -1) {
+ if (!state)
+ mode |= O_NONBLOCK;
+ else
+ mode &= ~O_NONBLOCK;
+ fcntl(fd, F_SETFL, mode);
+ }
+}
+
__dead void
shell_exec(const char *shell, const char *shellcmd)
{
const char *shellname, *ptr;
char *argv0;
- int mode;
ptr = strrchr(shell, '/');
if (ptr != NULL && *(ptr + 1) != '\0')
@@ -212,12 +225,9 @@ shell_exec(const char *shell, const char *shellcmd)
xasprintf(&argv0, "%s", shellname);
setenv("SHELL", shell, 1);
- if ((mode = fcntl(STDIN_FILENO, F_GETFL)) != -1)
- fcntl(STDIN_FILENO, F_SETFL, mode & ~O_NONBLOCK);
- if ((mode = fcntl(STDOUT_FILENO, F_GETFL)) != -1)
- fcntl(STDOUT_FILENO, F_SETFL, mode & ~O_NONBLOCK);
- if ((mode = fcntl(STDERR_FILENO, F_GETFL)) != -1)
- fcntl(STDERR_FILENO, F_SETFL, mode & ~O_NONBLOCK);
+ setblocking(STDIN_FILENO, 1);
+ setblocking(STDOUT_FILENO, 1);
+ setblocking(STDERR_FILENO, 1);
closefrom(STDERR_FILENO + 1);
execl(shell, argv0, "-c", shellcmd, (char *) NULL);