Code

plugin: Make sdb_plugin_info_t public.
[sysdb.git] / src / utils / unixsock.c
index 256cf9f7ba7ed56f8917b9110acee9fefdfded15..1a4373abb4ee92bc38b0cb23982f36d93b61f490 100644 (file)
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#if HAVE_CONFIG_H
+#      include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include "utils/error.h"
 #include "utils/unixsock.h"
-#include "core/error.h"
 
 #include <assert.h>
 #include <errno.h>
@@ -113,7 +117,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 "
@@ -292,26 +296,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;
        }