src/{lib,}rrdc.c: Make `rrdd_connect' use the default path if path == NULL.
[rrdd.git] / src / librrdc.c
index 25d0afa..93d9420 100644 (file)
@@ -22,8 +22,6 @@
 #include "rrdd.h"
 #include "rrdc.h"
 
-#define SOCK_TEMPLATE "/tmp/rrdc.sock.XXXXXX"
-
 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
 static int sd;
 static FILE *sh;
@@ -65,6 +63,9 @@ int rrdd_connect (const char *path)
   struct sockaddr_un sa;
   int status;
 
+  if (path == NULL)
+    path = RRDD_SOCK_PATH;
+
   pthread_mutex_lock (&lock);
 
   if (sh != NULL)
@@ -155,14 +156,29 @@ int rrdd_update (const char *filename, int values_num,
   if (sh == NULL)
   {
     pthread_mutex_unlock (&lock);
-    return (-1);
+    return (ENOTCONN);
   }
 
   status = write (sd, buffer, sizeof (buffer) - buffer_size);
 
+  status = read (sd, buffer, sizeof (buffer));
+  if (status < 0)
+  {
+    status = errno;
+    pthread_mutex_unlock (&lock);
+    return (status);
+  }
+  else if (status == 0)
+  {
+    pthread_mutex_unlock (&lock);
+    return (ENODATA);
+  }
+
+  status = atoi (buffer);
+
   pthread_mutex_unlock (&lock);
 
-  return (0);
+  return (status);
 } /* int rrd_update_daemon */
 
 /*