From: Sebastian Harl Date: Fri, 10 Jan 2014 08:06:33 +0000 (+0100) Subject: unixsock utils: Retry reading from socket if the call was interrupted. X-Git-Tag: sysdb-0.1.0~244 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=012b412eb5165f331dc378e9b6d00517b8003e0b;p=sysdb.git unixsock utils: Retry reading from socket if the call was interrupted. --- diff --git a/src/utils/unixsock.c b/src/utils/unixsock.c index 59bf563..da992c9 100644 --- a/src/utils/unixsock.c +++ b/src/utils/unixsock.c @@ -292,21 +292,30 @@ char * sdb_unixsock_client_recv(sdb_unixsock_client_t *client, char *buffer, size_t buflen) { + char *tmp; + if ((! client) || (! client->fh) || (! buffer)) return NULL; if (client->shutdown & SDB_SHUT_RD) /* reconnect */ sdb_unixsock_client_connect(client); - buffer = fgets(buffer, (int)buflen - 1, client->fh); - if (! buffer) { - if (! feof(client->fh)) { - char errbuf[1024]; - sdb_log(SDB_LOG_ERR, "unixsock: Failed to read " - "from socket (%s): %s", client->path, - sdb_strerror(errno, errbuf, sizeof(errbuf))); + tmp = NULL; + while (tmp == NULL) { + errno = 0; + tmp = fgets(buffer, (int)buflen - 1, client->fh); + if (! tmp) { + if ((errno == EAGAIN) || (errno == EINTR)) + continue; + + if (! feof(client->fh)) { + char errbuf[1024]; + sdb_log(SDB_LOG_ERR, "unixsock: Failed to read " + "from socket (%s): %s", client->path, + sdb_strerror(errno, errbuf, sizeof(errbuf))); + } + return NULL; } - return buffer; } buffer[buflen - 1] = '\0';