From 012b412eb5165f331dc378e9b6d00517b8003e0b Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Fri, 10 Jan 2014 09:06:33 +0100 Subject: [PATCH] unixsock utils: Retry reading from socket if the call was interrupted. --- src/utils/unixsock.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) 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'; -- 2.30.2