static int sd;
static FILE *sh;
+static int buffer_add_string (const char *str,
+ char **buffer_ret, size_t *buffer_size_ret)
+{
+ size_t str_size;
+
+ str_size = strlen (str) + 1;
+
+ if (*buffer_size_ret < str_size)
+ return (-1);
+
+ memcpy (*buffer_ret, str, str_size);
+ *buffer_ret += str_size;
+ *buffer_size_ret -= str_size;
+
+ return (0);
+} /* int buffer_add_string */
+
+static int buffer_add_value (const char *value,
+ char **buffer_ret, size_t *buffer_size_ret)
+{
+ char temp[4096];
+
+ if (strncmp (value, "N:", 2) == 0)
+ snprintf (temp, sizeof (temp), "%lu:%s",
+ (unsigned long) time (NULL), value + 2);
+ else
+ strncpy (temp, value, sizeof (temp));
+ temp[sizeof (temp) - 1] = 0;
+
+ return (buffer_add_string (temp, buffer_ret, buffer_size_ret));
+} /* int buffer_add_value */
+
int rrdd_connect (const char *path)
{
struct sockaddr_un sa;
int rrdd_update (const char *filename, int values_num,
const char * const *values)
{
+ char buffer[4096];
+ char *buffer_ptr;
+ size_t buffer_size;
+ int status;
+ int i;
+
+ memset (buffer, 0, sizeof (buffer));
+ buffer_ptr = &buffer[0];
+ buffer_size = sizeof (buffer) - 1;
+
+ buffer_add_string (filename, &buffer_ptr, &buffer_size);
+ for (i = 0; i < values_num; i++)
+ buffer_add_value (values[i], &buffer_ptr, &buffer_size);
+
pthread_mutex_lock (&lock);
if (sh == NULL)
return (-1);
}
+ status = write (sd, buffer, sizeof (buffer) - buffer_size);
+
pthread_mutex_unlock (&lock);
return (0);