From: Florian Forster Date: Sat, 21 Jun 2008 16:17:07 +0000 (+0200) Subject: src/librrdc.c: When sending an `update', wait for the reply before closing the socket. X-Git-Url: https://git.octo.it/?p=rrdd.git;a=commitdiff_plain;h=1bbaed0ca88432568a6ae9f9d643aa3a27bf9a01 src/librrdc.c: When sending an `update', wait for the reply before closing the socket. Not doing so will (still!) crash rrdd, but it's not nice either hence this fix. --- diff --git a/src/librrdc.c b/src/librrdc.c index 25d0afa..1a21260 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; @@ -155,14 +153,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 */ /*