X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Futils%2Funixsock.c;h=9a5c3fab8c91de6c510a99d8740e4ae2301e0a01;hb=9ee6c7fc9932e3fcb6d8aebe5364b1da3116af05;hp=138205d936bfc6573d08b99c77246f7c93e103ea;hpb=fa5c130fbd0c75f3c47f1b28feb8d76a4791a93e;p=sysdb.git diff --git a/src/utils/unixsock.c b/src/utils/unixsock.c index 138205d..9a5c3fa 100644 --- a/src/utils/unixsock.c +++ b/src/utils/unixsock.c @@ -25,8 +25,8 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "utils/error.h" #include "utils/unixsock.h" -#include "core/error.h" #include #include @@ -113,7 +113,7 @@ sdb_unixsock_parse_cell(char *string, int type, sdb_data_t *data) case SDB_TYPE_BINARY: /* we don't support any binary information containing 0-bytes */ data->data.binary.length = strlen(string); - data->data.binary.datum = (const unsigned char *)string; + data->data.binary.datum = (unsigned char *)string; break; default: sdb_log(SDB_LOG_ERR, "unixsock: Unexpected type %i while " @@ -258,6 +258,9 @@ sdb_unixsock_client_connect(sdb_unixsock_client_t *client) return -1; } + /* enable line-buffering */ + setvbuf(client->fh, NULL, _IOLBF, 0); + client->shutdown = 0; return 0; } /* sdb_unixsock_client_connect */ @@ -289,26 +292,35 @@ 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'; buflen = strlen(buffer); - while ((buffer[buflen - 1] == '\n') || (buffer[buflen - 1] == '\r')) { + while (buflen && ((buffer[buflen - 1] == '\n') || (buffer[buflen - 1] == '\r'))) { buffer[buflen - 1] = '\0'; --buflen; }