From: phk Date: Mon, 7 Aug 2006 16:05:21 +0000 (+0000) Subject: Handle read errors on the cli pipes. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e203f3ab83d0f758dacf8aee546833b7234cdb1b;p=varnish Handle read errors on the cli pipes. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@727 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/lib/libvarnish/cli_common.c b/varnish-cache/lib/libvarnish/cli_common.c index 494f481d..7b89462e 100644 --- a/varnish-cache/lib/libvarnish/cli_common.c +++ b/varnish-cache/lib/libvarnish/cli_common.c @@ -73,9 +73,9 @@ cli_writeres(int fd, struct cli *cli) } static int -read_tmo(int fd, void *ptr, unsigned len, double tmo) +read_tmo(int fd, char *ptr, unsigned len, double tmo) { - int i; + int i, j; struct pollfd pfd; pfd.fd = fd; @@ -85,7 +85,17 @@ read_tmo(int fd, void *ptr, unsigned len, double tmo) errno = ETIMEDOUT; return (-1); } - return (read(fd, ptr, len)); + for (j = 0; len > 0; ) { + i = read(fd, ptr, len); + if (i < 0) + return (i); + if (i == 0) + break; + len -= i; + ptr += i; + j += i; + } + return (j); } int @@ -97,9 +107,12 @@ cli_readres(int fd, unsigned *status, char **ptr, double tmo) char *p; i = read_tmo(fd, res, CLI_LINE0_LEN, tmo); - if (i < 0) - return (i); - assert(i == CLI_LINE0_LEN); /* XXX: handle */ + if (i != CLI_LINE0_LEN) { + if (status != NULL) + *status = CLIS_COMMS; + return (1); + } + assert(i == CLI_LINE0_LEN); assert(res[3] == ' '); assert(res[CLI_LINE0_LEN - 1] == '\n'); j = sscanf(res, "%u %u\n", &u, &v);