Update of /cvsroot/tmux/tmux
In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv4990
Modified Files:
client.c cmd-pipe-pane.c job.c server-client.c server.c tmux.c
tmux.h tty.c window.c
Log Message:
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").
Index: server-client.c
===================================================================
RCS file: /cvsroot/tmux/tmux/server-client.c,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- server-client.c 7 Jan 2011 14:34:45 -0000 1.51
+++ server-client.c 21 Jan 2011 23:44:13 -0000 1.52
@@ -52,13 +52,9 @@
server_client_create(int fd)
{
struct client *c;
- int mode;
u_int i;
- if ((mode = fcntl(fd, F_GETFL)) == -1)
- fatal("fcntl failed");
- if (fcntl(fd, F_SETFL, mode|O_NONBLOCK) == -1)
- fatal("fcntl failed");
+ setblocking(fd, 0);
c = xcalloc(1, sizeof *c);
c->references = 0;
@@ -123,16 +119,22 @@
if (c->flags & CLIENT_TERMINAL)
tty_free(&c->tty);
- if (c->stdin_fd != -1)
+ if (c->stdin_fd != -1) {
+ setblocking(c->stdin_fd, 1);
close(c->stdin_fd);
+ }
if (c->stdin_event != NULL)
bufferevent_free(c->stdin_event);
- if (c->stdout_fd != -1)
+ if (c->stdout_fd != -1) {
+ setblocking(c->stdout_fd, 1);
close(c->stdout_fd);
+ }
if (c->stdout_event != NULL)
bufferevent_free(c->stdout_event);
- if (c->stderr_fd != -1)
+ if (c->stderr_fd != -1) {
+ setblocking(c->stderr_fd, 1);
close(c->stderr_fd);
+ }
if (c->stderr_event != NULL)
bufferevent_free(c->stderr_event);
@@ -631,6 +633,7 @@
return;
bufferevent_disable(c->stdin_event, EV_READ|EV_WRITE);
+ setblocking(c->stdin_fd, 1);
close(c->stdin_fd);
c->stdin_fd = -1;
@@ -646,6 +649,7 @@
struct client *c = data;
bufferevent_disable(c->stdout_event, EV_READ|EV_WRITE);
+ setblocking(c->stdout_fd, 1);
close(c->stdout_fd);
c->stdout_fd = -1;
}
@@ -658,6 +662,7 @@
struct client *c = data;
bufferevent_disable(c->stderr_event, EV_READ|EV_WRITE);
+ setblocking(c->stderr_fd, 1);
close(c->stderr_fd);
c->stderr_fd = -1;
}
@@ -671,7 +676,6 @@
struct msg_identify_data identifydata;
struct msg_environ_data environdata;
ssize_t n, datalen;
- int mode;
if ((n = imsg_read(&c->ibuf)) == -1 || n == 0)
return (-1);
@@ -711,9 +715,7 @@
NULL, NULL, server_client_in_callback, c);
if (c->stdin_event == NULL)
fatalx("failed to create stdin event");
-
- if ((mode = fcntl(c->stdin_fd, F_GETFL)) != -1)
- fcntl(c->stdin_fd, F_SETFL, mode|O_NONBLOCK);
+ setblocking(c->stdin_fd, 0);
server_client_msg_identify(c, &identifydata, imsg.fd);
break;
@@ -728,9 +730,8 @@
NULL, NULL, server_client_out_callback, c);
if (c->stdout_event == NULL)
fatalx("failed to create stdout event");
+ setblocking(c->stdout_fd, 0);
- if ((mode = fcntl(c->stdout_fd, F_GETFL)) != -1)
- fcntl(c->stdout_fd, F_SETFL, mode|O_NONBLOCK);
break;
case MSG_STDERR:
if (datalen != 0)
@@ -743,9 +744,8 @@
NULL, NULL, server_client_err_callback, c);
if (c->stderr_event == NULL)
fatalx("failed to create stderr event");
+ setblocking(c->stderr_fd, 0);
- if ((mode = fcntl(c->stderr_fd, F_GETFL)) != -1)
- fcntl(c->stderr_fd, F_SETFL, mode|O_NONBLOCK);
break;
case MSG_RESIZE:
if (datalen != 0)
Index: cmd-pipe-pane.c
===================================================================
RCS file: /cvsroot/tmux/tmux/cmd-pipe-pane.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- cmd-pipe-pane.c 7 Jan 2011 14:45:34 -0000 1.16
+++ cmd-pipe-pane.c 21 Jan 2011 23:44:13 -0000 1.17
@@ -52,7 +52,7 @@
struct client *c;
struct window_pane *wp;
char *command;
- int old_fd, pipe_fd[2], null_fd, mode;
+ int old_fd, pipe_fd[2], null_fd;
if ((c = cmd_find_client(ctx, NULL)) == NULL)
return (-1);
@@ -126,10 +126,7 @@
NULL, NULL, cmd_pipe_pane_error_callback, wp);
bufferevent_enable(wp->pipe_event, EV_WRITE);
- if ((mode = fcntl(wp->pipe_fd, F_GETFL)) == -1)
- fatal("fcntl failed");
- if (fcntl(wp->pipe_fd, F_SETFL, mode|O_NONBLOCK) == -1)
- fatal("fcntl failed");
+ setblocking(wp->pipe_fd, 0);
return (0);
}
}
Index: tty.c
===================================================================
RCS file: /cvsroot/tmux/tmux/tty.c,v
retrieving revision 1.199
retrieving revision 1.200
diff -u -d -r1.199 -r1.200
--- tty.c 7 Jan 2011 14:34:45 -0000 1.199
+++ tty.c 21 Jan 2011 23:44:13 -0000 1.200
@@ -165,15 +165,11 @@
tty_start_tty(struct tty *tty)
{
struct termios tio;
- int mode;
if (tty->fd == -1)
return;
- if ((mode = fcntl(tty->fd, F_GETFL)) == -1)
- fatal("fcntl failed");
- if (fcntl(tty->fd, F_SETFL, mode|O_NONBLOCK) == -1)
- fatal("fcntl failed");
+ setblocking(tty->fd, 0);
bufferevent_enable(tty->event, EV_READ|EV_WRITE);
@@ -220,7 +216,6 @@
tty_stop_tty(struct tty *tty)
{
struct winsize ws;
- int mode;
if (!(tty->flags & TTY_STARTED))
return;
@@ -251,8 +246,7 @@
tty_raw(tty, tty_term_string(tty->term, TTYC_RMCUP));
- if ((mode = fcntl(tty->fd, F_GETFL)) != -1)
- fcntl(tty->fd, F_SETFL, mode & ~O_NONBLOCK);
+ setblocking(tty->fd, 1);
}
void
Index: job.c
===================================================================
RCS file: /cvsroot/tmux/tmux/job.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- job.c 24 Oct 2010 00:45:57 -0000 1.19
+++ job.c 21 Jan 2011 23:44:13 -0000 1.20
@@ -136,7 +136,7 @@
int
job_run(struct job *job)
{
- int nullfd, out[2], mode;
+ int nullfd, out[2];
if (job->fd != -1 || job->pid != -1)
return (0);
@@ -176,10 +176,7 @@
close(out[1]);
job->fd = out[0];
- if ((mode = fcntl(job->fd, F_GETFL)) == -1)
- fatal("fcntl failed");
- if (fcntl(job->fd, F_SETFL, mode|O_NONBLOCK) == -1)
- fatal("fcntl failed");
+ setblocking(job->fd, 0);
if (job->event != NULL)
bufferevent_free(job->event);
Index: server.c
===================================================================
RCS file: /cvsroot/tmux/tmux/server.c,v
retrieving revision 1.251
retrieving revision 1.252
diff -u -d -r1.251 -r1.252
--- server.c 3 Jan 2011 23:27:54 -0000 1.251
+++ server.c 21 Jan 2011 23:44:13 -0000 1.252
@@ -73,7 +73,7 @@
struct sockaddr_un sa;
size_t size;
mode_t mask;
- int fd, mode;
+ int fd;
memset(&sa, 0, sizeof sa);
sa.sun_family = AF_UNIX;
@@ -94,11 +94,7 @@
if (listen(fd, 16) == -1)
fatal("listen failed");
-
- if ((mode = fcntl(fd, F_GETFL)) == -1)
- fatal("fcntl failed");
- if (fcntl(fd, F_SETFL, mode|O_NONBLOCK) == -1)
- fatal("fcntl failed");
+ setblocking(fd, 0);
server_update_socket();
Index: tmux.c
===================================================================
RCS file: /cvsroot/tmux/tmux/tmux.c,v
retrieving revision 1.233
retrieving revision 1.234
diff -u -d -r1.233 -r1.234
--- tmux.c 7 Jan 2011 14:34:45 -0000 1.233
+++ tmux.c 21 Jan 2011 23:44:13 -0000 1.234
@@ -197,12 +197,25 @@
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 @@
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);
Index: client.c
===================================================================
RCS file: /cvsroot/tmux/tmux/client.c,v
retrieving revision 1.100
retrieving revision 1.101
diff -u -d -r1.100 -r1.101
--- client.c 24 Oct 2010 19:54:41 -0000 1.100
+++ client.c 21 Jan 2011 23:44:13 -0000 1.101
@@ -54,7 +54,7 @@
{
struct sockaddr_un sa;
size_t size;
- int fd, mode;
+ int fd;
memset(&sa, 0, sizeof sa);
sa.sun_family = AF_UNIX;
@@ -84,10 +84,7 @@
}
}
- if ((mode = fcntl(fd, F_GETFL)) == -1)
- fatal("fcntl failed");
- if (fcntl(fd, F_SETFL, mode|O_NONBLOCK) == -1)
- fatal("fcntl failed");
+ setblocking(fd, 0);
return (fd);
failed:
Index: window.c
===================================================================
RCS file: /cvsroot/tmux/tmux/window.c,v
retrieving revision 1.143
retrieving revision 1.144
diff -u -d -r1.143 -r1.144
--- window.c 7 Jan 2011 16:55:40 -0000 1.143
+++ window.c 21 Jan 2011 23:44:13 -0000 1.144
@@ -560,7 +560,6 @@
const char *cwd, struct environ *env, struct termios *tio, char **cause)
{
struct winsize ws;
- int mode;
char *argv0;
const char *ptr;
struct termios tio2;
@@ -634,10 +633,8 @@
fatal("execl failed");
}
- if ((mode = fcntl(wp->fd, F_GETFL)) == -1)
- fatal("fcntl failed");
- if (fcntl(wp->fd, F_SETFL, mode|O_NONBLOCK) == -1)
- fatal("fcntl failed");
+ setblocking(wp->fd, 0);
+
wp->event = bufferevent_new(wp->fd,
window_pane_read_callback, NULL, window_pane_error_callback, wp);
bufferevent_enable(wp->event, EV_READ|EV_WRITE);
Index: tmux.h
===================================================================
RCS file: /cvsroot/tmux/tmux/tmux.h,v
retrieving revision 1.603
retrieving revision 1.604
diff -u -d -r1.603 -r1.604
--- tmux.h 7 Jan 2011 16:55:40 -0000 1.603
+++ tmux.h 21 Jan 2011 23:44:13 -0000 1.604
@@ -1304,6 +1304,7 @@
const char *getshell(void);
int checkshell(const char *);
int areshell(const char *);
+void setblocking(int, int);
__dead void shell_exec(const char *, const char *);
/* cfg.c */
------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires
February 28th, so secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
tmux-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tmux-cvs