/**
* collectd - src/unixsock.c
- * Copyright (C) 2007 Florian octo Forster
+ * Copyright (C) 2007,2008 Florian octo Forster
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
#include "common.h"
#include "plugin.h"
#include "configfile.h"
+
#include "utils_cmd_putval.h"
+#include "utils_cmd_putnotif.h"
/* Folks without pthread will need to disable this plugin. */
#include <pthread.h>
#include <sys/socket.h>
+#include <sys/stat.h>
#include <sys/un.h>
#include <grp.h>
/* Linked list and auxilliary variables for saving values */
static value_cache_t *cache_head = NULL;
static pthread_mutex_t cache_lock = PTHREAD_MUTEX_INITIALIZER;
-static unsigned int cache_oldest = UINT_MAX;
+static time_t cache_oldest = -1;
/*
* Functions
cache_head = vc;
vc->time = vl->time;
- if (vc->time < cache_oldest)
+ if ((vc->time < cache_oldest) || (-1 == cache_oldest))
cache_oldest = vc->time;
pthread_mutex_unlock (&cache_lock);
vc->ds = ds;
vc->time = vl->time;
- if (vc->time < cache_oldest)
+ if ((vc->time < cache_oldest) || (-1 == cache_oldest))
cache_oldest = vc->time;
pthread_mutex_unlock (&cache_lock);
sizeof (sa.sun_path) - 1);
/* unlink (sa.sun_path); */
+ DEBUG ("unixsock plugin: socket path = %s", sa.sun_path);
+
status = bind (sock_fd, (struct sockaddr *) &sa, sizeof (sa));
if (status != 0)
{
char errbuf[1024];
sstrerror (errno, errbuf, sizeof (errbuf));
- DEBUG ("bind failed: %s; sa.sun_path = %s", errbuf, sa.sun_path);
ERROR ("unixsock plugin: bind failed: %s", errbuf);
close (sock_fd);
sock_fd = -1;
return (-1);
}
+ chmod (sa.sun_path, sock_perms);
+
status = listen (sock_fd, 8);
if (status != 0)
{
{
us_handle_listval (fh, fields, fields_num);
}
+ else if (strcasecmp (fields[0], "putnotif") == 0)
+ {
+ handle_putnotif (fh, fields, fields_num);
+ }
else
{
fprintf (fh, "-1 Unknown command: %s\n", fields[0]);
while (loop != 0)
{
- DEBUG ("Calling accept..");
+ DEBUG ("unixsock plugin: Calling accept..");
status = accept (sock_fd, NULL, NULL);
if (status < 0)
{