X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Flibrrdc.c;h=93d94209cac5fdd6a21a6fcb572bf0c87209f527;hb=e52c79f087fadbab671e81f982b9137184a4d9d0;hp=25d0afab0c92165acecdfde5743a9295bedb0b4d;hpb=884e71de19074f046632dce4403ebfb6843af9f5;p=rrdd.git diff --git a/src/librrdc.c b/src/librrdc.c index 25d0afa..93d9420 100644 --- a/src/librrdc.c +++ b/src/librrdc.c @@ -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 */ /*