=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/client.c,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- src/usr.bin/tmux/client.c 2009/09/02 20:15:49 1.16 +++ src/usr.bin/tmux/client.c 2009/09/02 23:49:25 1.17 @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.16 2009/09/02 20:15:49 nicm Exp $ */ +/* $OpenBSD: client.c,v 1.17 2009/09/02 23:49:25 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -152,12 +152,21 @@ client_main(struct client_ctx *cctx) { struct pollfd pfd; - int nfds; + int n, nfds; siginit(); logfile("client"); + /* + * imsg_read in the first client poll loop (before the terminal has + * been initialiased) may have read messages into the buffer after the + * MSG_READY switched to here. Process anything outstanding now so poll + * doesn't hang waiting for messages that have already arrived. + */ + if (client_msg_dispatch(cctx) != 0) + goto out; + for (;;) { if (sigterm) client_write_server(cctx, MSG_EXITING, NULL, 0); @@ -190,6 +199,10 @@ fatalx("socket error"); if (pfd.revents & POLLIN) { + if ((n = imsg_read(&cctx->ibuf)) == -1 || n == 0) { + cctx->exittype = CCTX_DIED; + break; + } if (client_msg_dispatch(cctx) != 0) break; } @@ -201,7 +214,8 @@ } } } - + +out: if (sigterm) { printf("[terminated]\n"); return (1); @@ -251,11 +265,6 @@ struct imsg imsg; struct msg_print_data printdata; ssize_t n, datalen; - - if ((n = imsg_read(&cctx->ibuf)) == -1 || n == 0) { - cctx->exittype = CCTX_DIED; - return (-1); - } for (;;) { if ((n = imsg_get(&cctx->ibuf, &imsg)) == -1)