summaryrefslogtreecommitdiffstats
path: root/plugins/imuxsock
diff options
context:
space:
mode:
authorLennart Poettering <mailto:lennart@poettering.net>2010-09-07 13:06:04 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2010-09-07 13:06:04 +0200
commit41327992680cfb8dd602ea92d6902448dd66413d (patch)
treeee83c9b70509f7c71ef48f12eaebd6e54ab4332e /plugins/imuxsock
parent73ebadd5980f91079416a14ba6463d576ecb6207 (diff)
downloadrsyslog-41327992680cfb8dd602ea92d6902448dd66413d.tar.gz
rsyslog-41327992680cfb8dd602ea92d6902448dd66413d.tar.xz
rsyslog-41327992680cfb8dd602ea92d6902448dd66413d.zip
acquire /dev/log socket optionally from systemd
Diffstat (limited to 'plugins/imuxsock')
-rw-r--r--plugins/imuxsock/Makefile.am4
-rw-r--r--plugins/imuxsock/imuxsock.c50
2 files changed, 47 insertions, 7 deletions
diff --git a/plugins/imuxsock/Makefile.am b/plugins/imuxsock/Makefile.am
index a2fe0baa..8803937f 100644
--- a/plugins/imuxsock/Makefile.am
+++ b/plugins/imuxsock/Makefile.am
@@ -1,6 +1,6 @@
pkglib_LTLIBRARIES = imuxsock.la
-imuxsock_la_SOURCES = imuxsock.c
+imuxsock_la_SOURCES = imuxsock.c ../../runtime/sd-daemon.c ../../runtime/sd-daemon.h
imuxsock_la_CPPFLAGS = -I$(top_srcdir) $(PTHREADS_CFLAGS) $(RSRT_CFLAGS)
imuxsock_la_LDFLAGS = -module -avoid-version
-imuxsock_la_LIBADD =
+imuxsock_la_LIBADD =
diff --git a/plugins/imuxsock/imuxsock.c b/plugins/imuxsock/imuxsock.c
index 046f12f0..db53fcb6 100644
--- a/plugins/imuxsock/imuxsock.c
+++ b/plugins/imuxsock/imuxsock.c
@@ -47,6 +47,7 @@
#include "prop.h"
#include "debug.h"
#include "unlimited_select.h"
+#include "sd-daemon.h"
MODULE_TYPE_INPUT
@@ -74,7 +75,7 @@ DEFobjCurrIf(prop)
static prop_t *pLocalHostIP = NULL; /* there is only one global IP for all internally-generated messages */
static prop_t *pInputName = NULL; /* our inputName currently is always "imudp", and this will hold it */
-static int startIndexUxLocalSockets; /* process funix from that index on (used to
+static int startIndexUxLocalSockets; /* process funix from that index on (used to
* suppress local logging. rgerhards 2005-08-01
* read-only after startup
*/
@@ -177,7 +178,7 @@ static rsRetVal discardFunixn(void)
prop.Destruct(&(funixHName[i]));
}
}
-
+
return RS_RET_OK;
}
@@ -190,6 +191,40 @@ static int create_unix_socket(const char *path, int bCreatePath)
if (path[0] == '\0')
return -1;
+ if (strcmp(path, _PATH_LOG) == 0) {
+ int r;
+
+ /* Check whether an FD was passed in from systemd. If
+ * so, it's the /dev/log socket, so use it. */
+
+ r = sd_listen_fds(0);
+ if (r < 0) {
+ errmsg.LogError(-r, NO_ERRCODE, "Failed to acquire systemd socket");
+ return -1;
+ }
+
+ if (r > 1) {
+ errmsg.LogError(EINVAL, NO_ERRCODE, "Wrong number of systemd sockets passed");
+ return -1;
+ }
+
+ if (r == 1) {
+ fd = SD_LISTEN_FDS_START;
+ r = sd_is_socket_unix(fd, SOCK_DGRAM, -1, _PATH_LOG, 0);
+ if (r < 0) {
+ errmsg.LogError(-r, NO_ERRCODE, "Failed to verify systemd socket type");
+ return -1;
+ }
+
+ if (!r) {
+ errmsg.LogError(EINVAL, NO_ERRCODE, "Passed systemd socket of wrong type");
+ return -1;
+ }
+
+ return fd;
+ }
+ }
+
unlink(path);
memset(&sunx, 0, sizeof(sunx));
@@ -391,12 +426,17 @@ CODESTARTafterRun
int i;
/* do cleanup here */
/* Close the UNIX sockets. */
- for (i = 0; i < nfunix; i++)
+ for (i = 0; i < nfunix; i++)
if (funix[i] != -1)
close(funix[i]);
- /* Clean-up files. */
- for(i = startIndexUxLocalSockets; i < nfunix; i++)
+ /* Clean-up files. If systemd passed us a socket it is
+ * systemd's job to clean it up.*/
+ if (sd_listen_fds(0) > 0)
+ i = 1;
+ else
+ i = startIndexUxLocalSockets;
+ for(; i < nfunix; i++)
if (funixn[i] && funix[i] != -1)
unlink((char*) funixn[i]);
/* free no longer needed string */