diff --git a/client.c b/client.c index a388216f..b0f175b9 100644 --- a/client.c +++ b/client.c @@ -1,4 +1,4 @@ -/* $Id: client.c,v 1.69 2009-09-02 20:17:23 nicm Exp $ */ +/* $Id: client.c,v 1.70 2009-09-03 21:06:30 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -156,12 +156,21 @@ int 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); @@ -194,6 +203,10 @@ client_main(struct client_ctx *cctx) 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; } @@ -205,7 +218,8 @@ client_main(struct client_ctx *cctx) } } } - + +out: if (sigterm) { printf("[terminated]\n"); return (1); @@ -256,11 +270,6 @@ client_msg_dispatch(struct client_ctx *cctx) 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) fatalx("imsg_get failed");