X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Funixsock.c;h=54a1e20d48aedf40a347bf901ff1718e518d00d5;hb=6e6c1eecf05ac8bc9e59b0967cb87e578253d5a0;hp=e6c75a65644e7441425183fb1b041c9bb93274c0;hpb=7bab45b57d6ef99ae55c499c51478dd63c3b1397;p=collectd.git diff --git a/src/unixsock.c b/src/unixsock.c index e6c75a65..73037e49 100644 --- a/src/unixsock.c +++ b/src/unixsock.c @@ -25,9 +25,9 @@ **/ #include "collectd.h" + #include "common.h" #include "plugin.h" -#include "configfile.h" #include "utils_cmd_flush.h" #include "utils_cmd_getval.h" @@ -36,9 +36,6 @@ #include "utils_cmd_putval.h" #include "utils_cmd_putnotif.h" -/* Folks without pthread will need to disable this plugin. */ -#include - #include #include @@ -79,7 +76,7 @@ static pthread_t listen_thread = (pthread_t) 0; */ static int us_open_socket (void) { - struct sockaddr_un sa; + struct sockaddr_un sa = { 0 }; int status; sock_fd = socket (PF_UNIX, SOCK_STREAM, 0); @@ -91,7 +88,6 @@ static int us_open_socket (void) return (-1); } - memset (&sa, '\0', sizeof (sa)); sa.sun_family = AF_UNIX; sstrncpy (sa.sun_path, (sock_file != NULL) ? sock_file : US_DEFAULT_PATH, sizeof (sa.sun_path)); @@ -127,7 +123,16 @@ static int us_open_socket (void) return (-1); } - chmod (sa.sun_path, sock_perms); + status = chmod (sa.sun_path, sock_perms); + if (status == -1) + { + char errbuf[1024]; + ERROR ("unixsock plugin: chmod failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + close (sock_fd); + sock_fd = -1; + return (-1); + } status = listen (sock_fd, 8); if (status != 0) @@ -142,7 +147,7 @@ static int us_open_socket (void) do { - char *grpname; + const char *grpname; struct group *g; struct group sg; char grbuf[2048]; @@ -284,7 +289,7 @@ static void *us_handle_client (void *arg) if (strcasecmp (fields[0], "getval") == 0) { - handle_getval (fhout, buffer); + cmd_handle_getval (fhout, buffer); } else if (strcasecmp (fields[0], "getthreshold") == 0) { @@ -292,11 +297,11 @@ static void *us_handle_client (void *arg) } else if (strcasecmp (fields[0], "putval") == 0) { - handle_putval (fhout, buffer); + cmd_handle_putval (fhout, buffer); } else if (strcasecmp (fields[0], "listval") == 0) { - handle_listval (fhout, buffer); + cmd_handle_listval (fhout, buffer); } else if (strcasecmp (fields[0], "putnotif") == 0) { @@ -304,7 +309,7 @@ static void *us_handle_client (void *arg) } else if (strcasecmp (fields[0], "flush") == 0) { - handle_flush (fhout, buffer); + cmd_handle_flush (fhout, buffer); } else { @@ -359,7 +364,7 @@ static void *us_server_thread (void __attribute__((unused)) *arg) pthread_exit ((void *) 1); } - remote_fd = (int *) malloc (sizeof (int)); + remote_fd = malloc (sizeof (*remote_fd)); if (remote_fd == NULL) { char errbuf[1024];