summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c471476)
raw | patch | inline | side by side (parent: c471476)
author | Florian Forster <octo@noris.net> | |
Thu, 11 Nov 2010 15:56:32 +0000 (16:56 +0100) | ||
committer | Florian Forster <octo@noris.net> | |
Thu, 11 Nov 2010 15:57:12 +0000 (16:57 +0100) |
src/collectd.conf.in | patch | blob | history | |
src/collectd.conf.pod | patch | blob | history | |
src/unixsock.c | patch | blob | history |
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index 42addd270084f09c41f9ead41de8704773d22e18..e194d142d60c1db25114184456ade85c6116209d 100644 (file)
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
# SocketFile "@prefix@/var/run/@PACKAGE_NAME@-unixsock"
# SocketGroup "collectd"
# SocketPerms "0660"
+# DeleteSocket false
#</Plugin>
#<Plugin uuid>
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 1da35982d032d716474d14a208679a23ff6ba212..1c31d97f0975a57965ff9b8a5319c7b60621feb5 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
@@ -4558,6 +4558,13 @@ Change the file permissions of the UNIX-socket after it has been created. The
permissions must be given as a numeric, octal value as you would pass to
L<chmod(1)>. Defaults to B<0770>.
+=item B<DeleteSocket> B<false>|B<true>
+
+If set to B<true>, delete the socket file before calling L<bind(2)>, if a file
+with the given name already exists. If I<collectd> crashes a socket file may be
+left over, preventing the daemon from opening a new socket when restarted.
+Since this is potentially dangerous, this defaults to B<false>.
+
=back
=head2 Plugin C<uuid>
diff --git a/src/unixsock.c b/src/unixsock.c
index 0b897482c9d956547d74be3f905f9d9941b157be..6de1395662161a66aaacafa389efa1e680583bf9 100644 (file)
--- a/src/unixsock.c
+++ b/src/unixsock.c
{
"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)
{
{
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);