diff --git a/src/unixsock.c b/src/unixsock.c
index 344424715e6e0cc23c938c38a17b280686a19168..2c1665fc9fcbbdffc3c91935838a720e4fbf6d6f 100644 (file)
--- a/src/unixsock.c
+++ b/src/unixsock.c
#include "utils_cmd_flush.h"
#include "utils_cmd_getval.h"
-#include "utils_cmd_getthreshold.h"
#include "utils_cmd_listval.h"
#include "utils_cmd_putval.h"
#include "utils_cmd_putnotif.h"
{
"SocketFile",
"SocketGroup",
- "SocketPerms"
+ "SocketPerms",
+ "DeleteSocket"
};
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
static char *sock_file = NULL;
static char *sock_group = NULL;
static int sock_perms = S_IRWXU | S_IRWXG;
+static _Bool delete_socket = 0;
static pthread_t listen_thread = (pthread_t) 0;
sa.sun_family = AF_UNIX;
sstrncpy (sa.sun_path, (sock_file != NULL) ? sock_file : US_DEFAULT_PATH,
sizeof (sa.sun_path));
- /* unlink (sa.sun_path); */
DEBUG ("unixsock plugin: socket path = %s", sa.sun_path);
+ if (delete_socket)
+ {
+ errno = 0;
+ status = unlink (sa.sun_path);
+ if ((status != 0) && (errno != ENOENT))
+ {
+ char errbuf[1024];
+ WARNING ("unixsock plugin: Deleting socket file \"%s\" failed: %s",
+ sa.sun_path,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ }
+ else if (status == 0)
+ {
+ INFO ("unixsock plugin: Successfully deleted socket file \"%s\".",
+ sa.sun_path);
+ }
+ }
+
status = bind (sock_fd, (struct sockaddr *) &sa, sizeof (sa));
if (status != 0)
{
errno = 0;
if (fgets (buffer, sizeof (buffer), fhin) == NULL)
{
+ if ((errno == EINTR) || (errno == EAGAIN))
+ continue;
+
if (errno != 0)
{
char errbuf[1024];
{
handle_getval (fhout, buffer);
}
- else if (strcasecmp (fields[0], "getthreshold") == 0)
- {
- handle_getthreshold (fhout, buffer);
- }
else if (strcasecmp (fields[0], "putval") == 0)
{
handle_putval (fhout, buffer);
DEBUG ("Spawning child to handle connection on fd #%i", *remote_fd);
- status = pthread_create (&th, &th_attr, us_handle_client, (void *) remote_fd);
+ status = plugin_thread_create (&th, &th_attr,
+ us_handle_client, (void *) remote_fd);
if (status != 0)
{
char errbuf[1024];
{
sock_perms = (int) strtol (val, NULL, 8);
}
+ else if (strcasecmp (key, "DeleteSocket") == 0)
+ {
+ if (IS_TRUE (val))
+ delete_socket = 1;
+ else
+ delete_socket = 0;
+ }
else
{
return (-1);
loop = 1;
- status = pthread_create (&listen_thread, NULL, us_server_thread, NULL);
+ status = plugin_thread_create (&listen_thread, NULL,
+ us_server_thread, NULL);
if (status != 0)
{
char errbuf[1024];