X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Funixsock.c;h=d729477bbc54db999322dedfe581834dc9725c21;hb=e44afcf744af2337983b41c6e7a3617595692ddd;hp=38f9025ef541104a34a50676b2a08e9d3143d657;hpb=5b5fff5bbdc5515d7f4c2a01df47373f4ac44847;p=collectd.git diff --git a/src/unixsock.c b/src/unixsock.c index 38f9025e..d729477b 100644 --- a/src/unixsock.c +++ b/src/unixsock.c @@ -53,7 +53,8 @@ static const char *config_keys[] = { "SocketFile", "SocketGroup", - "SocketPerms" + "SocketPerms", + "DeleteSocket" }; static int config_keys_num = STATIC_ARRAY_SIZE (config_keys); @@ -64,6 +65,7 @@ static int sock_fd = -1; 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; @@ -88,10 +90,27 @@ static int us_open_socket (void) 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) { @@ -387,6 +406,13 @@ static int us_config (const char *key, const char *val) { 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);