X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Futils%2Funixsock.c;h=256cf9f7ba7ed56f8917b9110acee9fefdfded15;hb=fc2a03c89e88d7c286630070fc014fd9d45147c9;hp=bc9806cfad8b367ef3af2d0170ab4a3c3f5e4774;hpb=b7cd97981cd4d5534cd0437d27564899047f0ac7;p=sysdb.git diff --git a/src/utils/unixsock.c b/src/utils/unixsock.c index bc9806c..256cf9f 100644 --- a/src/utils/unixsock.c +++ b/src/utils/unixsock.c @@ -26,7 +26,7 @@ */ #include "utils/unixsock.h" -#include "utils/error.h" +#include "core/error.h" #include #include @@ -117,7 +117,7 @@ sdb_unixsock_parse_cell(char *string, int type, sdb_data_t *data) break; default: sdb_log(SDB_LOG_ERR, "unixsock: Unexpected type %i while " - "parsing query result.\n", type); + "parsing query result.", type); return -1; } @@ -126,13 +126,13 @@ sdb_unixsock_parse_cell(char *string, int type, sdb_data_t *data) if (errno || (string == endptr)) { char errbuf[1024]; sdb_log(SDB_LOG_ERR, "unixsock: Failed to parse string " - "'%s' as numeric value (type %i): %s\n", string, type, + "'%s' as numeric value (type %i): %s", string, type, sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; } else if (endptr && (*endptr != '\0')) sdb_log(SDB_LOG_WARNING, "unixsock: Ignoring garbage after " - "number while parsing numeric value (type %i): %s.\n", + "number while parsing numeric value (type %i): %s.", type, endptr); } @@ -159,7 +159,7 @@ sdb_unixsock_client_process_one_line(sdb_unixsock_client_t *client, if (! line) { /* this must no happen */ sdb_log(SDB_LOG_ERR, "unixsock: Unexpected EOL while " "parsing line (expected %i columns delimited by '%s'; " - "got %i): %s\n", column_count, delim, + "got %i): %s", column_count, delim, /* last line number */ i, orig_line); return -1; } @@ -231,7 +231,7 @@ sdb_unixsock_client_connect(sdb_unixsock_client_t *client) fd = socket(AF_UNIX, SOCK_STREAM, /* protocol = */ 0); if (fd < 0) { char errbuf[1024]; - sdb_log(SDB_LOG_ERR, "unixsock: Failed to open socket: %s\n", + sdb_log(SDB_LOG_ERR, "unixsock: Failed to open socket: %s", sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; } @@ -242,7 +242,7 @@ sdb_unixsock_client_connect(sdb_unixsock_client_t *client) if (connect(fd, (struct sockaddr *)&sa, sizeof(sa))) { char errbuf[1024]; - sdb_log(SDB_LOG_ERR, "unixsock: Failed to connect to %s: %s\n", + sdb_log(SDB_LOG_ERR, "unixsock: Failed to connect to %s: %s", sa.sun_path, sdb_strerror(errno, errbuf, sizeof(errbuf))); close(fd); return -1; @@ -252,12 +252,15 @@ sdb_unixsock_client_connect(sdb_unixsock_client_t *client) if (! client->fh) { char errbuf[1024]; sdb_log(SDB_LOG_ERR, "unixsock: Failed to open I/O " - "stream for %s: %s\n", sa.sun_path, + "stream for %s: %s", sa.sun_path, sdb_strerror(errno, errbuf, sizeof(errbuf))); close(fd); return -1; } + /* enable line-buffering */ + setvbuf(client->fh, NULL, _IOLBF, 0); + client->shutdown = 0; return 0; } /* sdb_unixsock_client_connect */ @@ -278,7 +281,7 @@ sdb_unixsock_client_send(sdb_unixsock_client_t *client, if (status < 0) { char errbuf[1024]; sdb_log(SDB_LOG_ERR, "unixsock: Failed to write to " - "socket (%s): %s\n", client->path, + "socket (%s): %s", client->path, sdb_strerror(errno, errbuf, sizeof(errbuf))); return status; } @@ -300,7 +303,7 @@ sdb_unixsock_client_recv(sdb_unixsock_client_t *client, if (! feof(client->fh)) { char errbuf[1024]; sdb_log(SDB_LOG_ERR, "unixsock: Failed to read " - "from socket (%s): %s\n", client->path, + "from socket (%s): %s", client->path, sdb_strerror(errno, errbuf, sizeof(errbuf))); } return buffer; @@ -342,7 +345,7 @@ sdb_unixsock_client_process_lines(sdb_unixsock_client_t *client, if ((types[i] < 1) || (types[i] > SDB_TYPE_BINARY)) { sdb_log(SDB_LOG_ERR, "unixsock: Unknown column " "type %i while processing response from the " - "UNIX socket @ %s.\n", types[i], client->path); + "UNIX socket @ %s.", types[i], client->path); va_end(ap); free(types); return -1; @@ -375,8 +378,8 @@ sdb_unixsock_client_process_lines(sdb_unixsock_client_t *client, if ((n_cols >= 0) && (n_cols != column_count)) { sdb_log(SDB_LOG_ERR, "unixsock: number of columns (%i) " "does not match the number of requested columns (%i) " - "while processing response from the UNIX socket @ %s: " - "%s\n", column_count, n_cols, client->path, line); + "while processing response from the UNIX socket @ %s: %s", + column_count, n_cols, client->path, line); continue; } @@ -395,7 +398,7 @@ sdb_unixsock_client_process_lines(sdb_unixsock_client_t *client, || sdb_unixsock_client_error(client)) { char errbuf[1024]; sdb_log(SDB_LOG_ERR, "unixsock: Unexpected end of data while " - "reading from socket (%s): %s\n", client->path, + "reading from socket (%s): %s", client->path, sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; }