aboutsummaryrefslogtreecommitdiff
path: root/tmux.c
diff options
context:
space:
mode:
authorTiago Cunha <tcunha@gmx.com>2011-01-21 23:44:13 +0000
committerTiago Cunha <tcunha@gmx.com>2011-01-21 23:44:13 +0000
commit492e3aa4373f0f20a8685cfb3591a9730bb0454a (patch)
tree3f11c4b5b3b68706442324e1be636c07e25d3db5 /tmux.c
parent6b19621112c2fccdcde88f864291ef0939820b0d (diff)
downloadrtmux-492e3aa4373f0f20a8685cfb3591a9730bb0454a.tar.gz
rtmux-492e3aa4373f0f20a8685cfb3591a9730bb0454a.tar.bz2
rtmux-492e3aa4373f0f20a8685cfb3591a9730bb0454a.zip
Sync OpenBSD patchset 834:
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.c26
1 files changed, 18 insertions, 8 deletions
diff --git a/tmux.c b/tmux.c
index ca6956ff..83b213d2 100644
--- a/tmux.c
+++ b/tmux.c
@@ -1,4 +1,4 @@
-/* $Id: tmux.c,v 1.233 2011-01-07 14:34:45 tcunha Exp $ */
+/* $Id: tmux.c,v 1.234 2011-01-21 23:44:13 tcunha Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -197,12 +197,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')
@@ -215,12 +228,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);