- Improved systemd socket activation support to allow multiple
unix sockets and activation in forking mode (bnc#656197). OBS-URL: https://build.opensuse.org/package/show/Base:System/rsyslog?expand=0&rev=34
This commit is contained in:
@@ -1,57 +1,39 @@
|
||||
commit c5132c84fc1a678b5d93fcc430871c141110b82c
|
||||
Merge: c4026ec f9a4091
|
||||
Author: Marius Tomaschewski <mt@suse.de>
|
||||
Date: Fri Dec 3 18:07:40 2010 +0100
|
||||
From 8b7ca000dec71f6dcb73a8ab738093c17bd293c1 Mon Sep 17 00:00:00 2001
|
||||
From: Lennart Poettering <mailto:lennart@poettering.net>
|
||||
Date: Tue, 7 Sep 2010 13:06:04 +0200
|
||||
Subject: [PATCH 1/4] acquire /dev/log socket optionally from systemd
|
||||
|
||||
Merge branch 'v5.6.1-systemd1' into v5.6.2-systemd1
|
||||
[skipped whitespace-only changes -- mt@suse.de]
|
||||
---
|
||||
ChangeLog | 2 +
|
||||
plugins/imuxsock/Makefile.am | 2 +-
|
||||
plugins/imuxsock/imuxsock.c | 44 ++++++++++++++++++++++++++++++++++++++++-
|
||||
runtime/Makefile.am | 5 ++++
|
||||
tools/syslogd.c | 3 ++
|
||||
5 files changed, 53 insertions(+), 3 deletions(-)
|
||||
|
||||
commit f9a409137bdcd04ebf4851a23f573c436a14e5b2
|
||||
Author: Rainer Gerhards <rgerhards@adiscon.com>
|
||||
Date: Wed Sep 8 12:46:03 2010 +0200
|
||||
|
||||
moved systemd interface to rsyslog convenience lib
|
||||
|
||||
Mostly a refresh of sd-daemon.[ch] from its source plus some make file changes.
|
||||
We now have systemd interfaces inside rsyslog, so that all plugins interested can
|
||||
call the interfaces. Seems not to be totally necessary right now, but will help
|
||||
in the long term.
|
||||
|
||||
commit be3d81ee54088180a657ac37899d1def8ef4b36c
|
||||
Author: Rainer Gerhards <rgerhards@adiscon.com>
|
||||
Date: Tue Sep 7 14:19:05 2010 +0200
|
||||
|
||||
added forgotten files
|
||||
|
||||
commit 8b7ca000dec71f6dcb73a8ab738093c17bd293c1
|
||||
Author: Lennart Poettering <mailto:lennart@poettering.net>
|
||||
Date: Tue Sep 7 13:06:04 2010 +0200
|
||||
|
||||
acquire /dev/log socket optionally from systemd
|
||||
|
||||
[skipped whitespace-only changes -- mt@suse.de]
|
||||
diff --git a/ChangeLog b/ChangeLog
|
||||
index ca13d48..1ea95b2 100644
|
||||
index 506650d..4d4c17c 100644
|
||||
--- a/ChangeLog
|
||||
+++ b/ChangeLog
|
||||
@@ -1,3 +1,5 @@
|
||||
+- acquire /dev/log socket optionally from systemd
|
||||
+ thanks to Lennart Poettering for this patch
|
||||
---------------------------------------------------------------------------
|
||||
Version 5.6.2 [V5-STABLE] (rgerhards), 2010-11-30
|
||||
- bugfix: compile failed on systems without epoll_create1()
|
||||
Version 5.6.1 [V5-STABLE] (rgerhards), 2010-11-24
|
||||
- bugfix(important): problem in TLS handling could cause rsyslog to loop
|
||||
diff --git a/plugins/imuxsock/Makefile.am b/plugins/imuxsock/Makefile.am
|
||||
index a2fe0ba..28f9f9e 100644
|
||||
index a2fe0ba..f39faad 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_CPPFLAGS = -I$(top_srcdir) $(PTHREADS_CFLAGS) $(RSRT_CFLAGS)
|
||||
+imuxsock_la_CPPFLAGS = -DSD_EXPORT_SYMBOLS -I$(top_srcdir) $(PTHREADS_CFLAGS) $(RSRT_CFLAGS)
|
||||
-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 = $(RSRT_LIBS)
|
||||
imuxsock_la_LIBADD =
|
||||
diff --git a/plugins/imuxsock/imuxsock.c b/plugins/imuxsock/imuxsock.c
|
||||
index 046f12f..89bb50b 100644
|
||||
--- a/plugins/imuxsock/imuxsock.c
|
||||
@@ -122,10 +104,10 @@ index 046f12f..89bb50b 100644
|
||||
unlink((char*) funixn[i]);
|
||||
/* free no longer needed string */
|
||||
diff --git a/runtime/Makefile.am b/runtime/Makefile.am
|
||||
index b700eae..27c56a2 100644
|
||||
index f7db3e3..ef11949 100644
|
||||
--- a/runtime/Makefile.am
|
||||
+++ b/runtime/Makefile.am
|
||||
@@ -82,6 +82,8 @@ librsyslog_la_SOURCES = \
|
||||
@@ -81,6 +81,8 @@ librsyslog_la_SOURCES = \
|
||||
prop.h \
|
||||
cfsysline.c \
|
||||
cfsysline.h \
|
||||
@@ -134,32 +116,56 @@ index b700eae..27c56a2 100644
|
||||
\
|
||||
\
|
||||
../action.h \
|
||||
@@ -100,9 +102,9 @@ librsyslog_la_SOURCES = \
|
||||
# runtime or will no longer be needed. -- rgerhards, 2008-06-13
|
||||
|
||||
if WITH_MODDIRS
|
||||
-librsyslog_la_CPPFLAGS = -D_PATH_MODDIR=\"$(pkglibdir)/:$(moddirs)\" $(PTHREADS_CFLAGS)
|
||||
+librsyslog_la_CPPFLAGS = -DSD_EXPORT_SYMBOLS -D_PATH_MODDIR=\"$(pkglibdir)/:$(moddirs)\" $(PTHREADS_CFLAGS)
|
||||
else
|
||||
-librsyslog_la_CPPFLAGS = -D_PATH_MODDIR=\"$(pkglibdir)/\" -I$(top_srcdir) $(PTHREADS_CFLAGS)
|
||||
+librsyslog_la_CPPFLAGS = -DSD_EXPORT_SYMBOLS -D_PATH_MODDIR=\"$(pkglibdir)/\" -I$(top_srcdir) $(PTHREADS_CFLAGS)
|
||||
endif
|
||||
#librsyslog_la_LDFLAGS = -module -avoid-version
|
||||
librsyslog_la_LIBADD = $(DL_LIBS) $(RT_LIBS)
|
||||
@@ -178,3 +180,6 @@ lmnsd_gtls_la_LDFLAGS = -module -avoid-version
|
||||
@@ -177,3 +179,6 @@ lmnsd_gtls_la_LDFLAGS = -module -avoid-version
|
||||
lmnsd_gtls_la_LIBADD = $(GNUTLS_LIBS)
|
||||
endif
|
||||
|
||||
+update-systemd:
|
||||
+ curl http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.c > sd-daemon.c
|
||||
+ curl http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.h > sd-daemon.h
|
||||
diff --git a/tools/syslogd.c b/tools/syslogd.c
|
||||
index 2e4ea5d..245ebe3 100644
|
||||
--- a/tools/syslogd.c
|
||||
+++ b/tools/syslogd.c
|
||||
@@ -135,6 +135,7 @@
|
||||
#include "net.h"
|
||||
#include "vm.h"
|
||||
#include "prop.h"
|
||||
+#include "sd-daemon.h"
|
||||
|
||||
/* definitions for objects we access */
|
||||
DEFobjCurrIf(obj)
|
||||
@@ -2431,6 +2432,8 @@ doGlblProcessInit(void)
|
||||
num_fds = getdtablesize();
|
||||
close(0);
|
||||
/* we keep stdout and stderr open in case we have to emit something */
|
||||
+
|
||||
+ if (sd_listen_fds(0) <= 0)
|
||||
for (i = 3; i < num_fds; i++)
|
||||
(void) close(i);
|
||||
untty();
|
||||
--
|
||||
1.7.1
|
||||
|
||||
From be3d81ee54088180a657ac37899d1def8ef4b36c Mon Sep 17 00:00:00 2001
|
||||
From: Rainer Gerhards <rgerhards@adiscon.com>
|
||||
Date: Tue, 7 Sep 2010 14:19:05 +0200
|
||||
Subject: [PATCH 2/4] added forgotten files
|
||||
|
||||
---
|
||||
runtime/sd-daemon.c | 448 +++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
runtime/sd-daemon.h | 257 +++++++++++++++++++++++++++++
|
||||
2 files changed, 705 insertions(+), 0 deletions(-)
|
||||
create mode 100644 runtime/sd-daemon.c
|
||||
create mode 100644 runtime/sd-daemon.h
|
||||
|
||||
diff --git a/runtime/sd-daemon.c b/runtime/sd-daemon.c
|
||||
new file mode 100644
|
||||
index 0000000..9c23b91
|
||||
index 0000000..5df70e3
|
||||
--- /dev/null
|
||||
+++ b/runtime/sd-daemon.c
|
||||
@@ -0,0 +1,435 @@
|
||||
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||
@@ -0,0 +1,448 @@
|
||||
+/*-*- Mode: C; c-basic-offset: 8 -*-*/
|
||||
+
|
||||
+/***
|
||||
+ Copyright 2010 Lennart Poettering
|
||||
@@ -486,13 +492,18 @@ index 0000000..9c23b91
|
||||
+}
|
||||
+
|
||||
+int sd_notify(int unset_environment, const char *state) {
|
||||
+#if defined(DISABLE_SYSTEMD) || !defined(__linux__) || !defined(SOCK_CLOEXEC)
|
||||
+#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
|
||||
+ return 0;
|
||||
+#else
|
||||
+ int fd = -1, r;
|
||||
+ struct msghdr msghdr;
|
||||
+ struct iovec iovec;
|
||||
+ union sockaddr_union sockaddr;
|
||||
+ struct ucred *ucred;
|
||||
+ union {
|
||||
+ struct cmsghdr cmsghdr;
|
||||
+ uint8_t buf[CMSG_SPACE(sizeof(struct ucred))];
|
||||
+ } control;
|
||||
+ const char *e;
|
||||
+
|
||||
+ if (!state) {
|
||||
@@ -525,15 +536,23 @@ index 0000000..9c23b91
|
||||
+ iovec.iov_base = (char*) state;
|
||||
+ iovec.iov_len = strlen(state);
|
||||
+
|
||||
+ memset(&control, 0, sizeof(control));
|
||||
+ control.cmsghdr.cmsg_level = SOL_SOCKET;
|
||||
+ control.cmsghdr.cmsg_type = SCM_CREDENTIALS;
|
||||
+ control.cmsghdr.cmsg_len = CMSG_LEN(sizeof(struct ucred));
|
||||
+
|
||||
+ ucred = (struct ucred*) CMSG_DATA(&control.cmsghdr);
|
||||
+ ucred->pid = getpid();
|
||||
+ ucred->uid = getuid();
|
||||
+ ucred->gid = getgid();
|
||||
+
|
||||
+ memset(&msghdr, 0, sizeof(msghdr));
|
||||
+ msghdr.msg_name = &sockaddr;
|
||||
+ msghdr.msg_namelen = sizeof(sa_family_t) + strlen(e);
|
||||
+
|
||||
+ if (msghdr.msg_namelen > sizeof(struct sockaddr_un))
|
||||
+ msghdr.msg_namelen = sizeof(struct sockaddr_un);
|
||||
+
|
||||
+ msghdr.msg_namelen = sizeof(struct sockaddr_un);
|
||||
+ msghdr.msg_iov = &iovec;
|
||||
+ msghdr.msg_iovlen = 1;
|
||||
+ msghdr.msg_control = &control;
|
||||
+ msghdr.msg_controllen = control.cmsghdr.cmsg_len;
|
||||
+
|
||||
+ if (sendmsg(fd, &msghdr, MSG_NOSIGNAL) < 0) {
|
||||
+ r = -errno;
|
||||
@@ -585,10 +604,10 @@ index 0000000..9c23b91
|
||||
+ /* We simply test whether the systemd cgroup hierarchy is
|
||||
+ * mounted */
|
||||
+
|
||||
+ if (lstat("/sys/fs/cgroup", &a) < 0)
|
||||
+ if (lstat("/cgroup", &a) < 0)
|
||||
+ return 0;
|
||||
+
|
||||
+ if (lstat("/sys/fs/cgroup/systemd", &b) < 0)
|
||||
+ if (lstat("/cgroup/systemd", &b) < 0)
|
||||
+ return 0;
|
||||
+
|
||||
+ return a.st_dev != b.st_dev;
|
||||
@@ -596,11 +615,11 @@ index 0000000..9c23b91
|
||||
+}
|
||||
diff --git a/runtime/sd-daemon.h b/runtime/sd-daemon.h
|
||||
new file mode 100644
|
||||
index 0000000..45aac8b
|
||||
index 0000000..fd6221f
|
||||
--- /dev/null
|
||||
+++ b/runtime/sd-daemon.h
|
||||
@@ -0,0 +1,261 @@
|
||||
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||
@@ -0,0 +1,257 @@
|
||||
+/*-*- Mode: C; c-basic-offset: 8 -*-*/
|
||||
+
|
||||
+#ifndef foosddaemonhfoo
|
||||
+#define foosddaemonhfoo
|
||||
@@ -669,13 +688,9 @@ index 0000000..45aac8b
|
||||
+ See sd-daemon(7) for more information.
|
||||
+*/
|
||||
+
|
||||
+#if (__GNUC__ >= 4)
|
||||
+#if __GNUC__ >= 4
|
||||
+#define _sd_printf_attr_(a,b) __attribute__ ((format (printf, a, b)))
|
||||
+# if defined(SD_EXPORT_SYMBOLS)
|
||||
+# define _sd_hidden_
|
||||
+# else
|
||||
+# define _sd_hidden_ __attribute__ ((visibility("hidden")))
|
||||
+# endif
|
||||
+#define _sd_hidden_ __attribute__ ((visibility("hidden")))
|
||||
+#else
|
||||
+#define _sd_printf_attr_(a,b)
|
||||
+#define _sd_hidden_
|
||||
@@ -777,7 +792,7 @@ index 0000000..45aac8b
|
||||
+
|
||||
+/*
|
||||
+ Informs systemd about changed daemon state. This takes a number of
|
||||
+ newline separated environment-style variable assignments in a
|
||||
+ newline seperated environment-style variable assignments in a
|
||||
+ string. The following variables are known:
|
||||
+
|
||||
+ READY=1 Tells systemd that daemon startup is finished (only
|
||||
@@ -861,24 +876,332 @@ index 0000000..45aac8b
|
||||
+#endif
|
||||
+
|
||||
+#endif
|
||||
--
|
||||
1.7.1
|
||||
|
||||
From f9a409137bdcd04ebf4851a23f573c436a14e5b2 Mon Sep 17 00:00:00 2001
|
||||
From: Rainer Gerhards <rgerhards@adiscon.com>
|
||||
Date: Wed, 8 Sep 2010 12:46:03 +0200
|
||||
Subject: [PATCH 3/4] moved systemd interface to rsyslog convenience lib
|
||||
|
||||
Mostly a refresh of sd-daemon.[ch] from its source plus some make file changes.
|
||||
We now have systemd interfaces inside rsyslog, so that all plugins interested can
|
||||
call the interfaces. Seems not to be totally necessary right now, but will help
|
||||
in the long term.
|
||||
---
|
||||
plugins/imuxsock/Makefile.am | 6 +++---
|
||||
runtime/Makefile.am | 4 ++--
|
||||
runtime/sd-daemon.c | 31 +++++++++----------------------
|
||||
runtime/sd-daemon.h | 12 ++++++++----
|
||||
4 files changed, 22 insertions(+), 31 deletions(-)
|
||||
|
||||
diff --git a/plugins/imuxsock/Makefile.am b/plugins/imuxsock/Makefile.am
|
||||
index f39faad..28f9f9e 100644
|
||||
--- a/plugins/imuxsock/Makefile.am
|
||||
+++ b/plugins/imuxsock/Makefile.am
|
||||
@@ -1,6 +1,6 @@
|
||||
pkglib_LTLIBRARIES = imuxsock.la
|
||||
|
||||
-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_SOURCES = imuxsock.c
|
||||
+imuxsock_la_CPPFLAGS = -DSD_EXPORT_SYMBOLS -I$(top_srcdir) $(PTHREADS_CFLAGS) $(RSRT_CFLAGS)
|
||||
imuxsock_la_LDFLAGS = -module -avoid-version
|
||||
-imuxsock_la_LIBADD =
|
||||
+imuxsock_la_LIBADD = $(RSRT_LIBS)
|
||||
diff --git a/runtime/Makefile.am b/runtime/Makefile.am
|
||||
index ef11949..5b2598b 100644
|
||||
--- a/runtime/Makefile.am
|
||||
+++ b/runtime/Makefile.am
|
||||
@@ -101,9 +101,9 @@ librsyslog_la_SOURCES = \
|
||||
# runtime or will no longer be needed. -- rgerhards, 2008-06-13
|
||||
|
||||
if WITH_MODDIRS
|
||||
-librsyslog_la_CPPFLAGS = -D_PATH_MODDIR=\"$(pkglibdir)/:$(moddirs)\" $(PTHREADS_CFLAGS)
|
||||
+librsyslog_la_CPPFLAGS = -DSD_EXPORT_SYMBOLS -D_PATH_MODDIR=\"$(pkglibdir)/:$(moddirs)\" $(PTHREADS_CFLAGS)
|
||||
else
|
||||
-librsyslog_la_CPPFLAGS = -D_PATH_MODDIR=\"$(pkglibdir)/\" -I$(top_srcdir) $(PTHREADS_CFLAGS)
|
||||
+librsyslog_la_CPPFLAGS = -DSD_EXPORT_SYMBOLS -D_PATH_MODDIR=\"$(pkglibdir)/\" -I$(top_srcdir) $(PTHREADS_CFLAGS)
|
||||
endif
|
||||
#librsyslog_la_LDFLAGS = -module -avoid-version
|
||||
librsyslog_la_LIBADD = $(DL_LIBS) $(RT_LIBS)
|
||||
diff --git a/runtime/sd-daemon.c b/runtime/sd-daemon.c
|
||||
index 5df70e3..9c23b91 100644
|
||||
--- a/runtime/sd-daemon.c
|
||||
+++ b/runtime/sd-daemon.c
|
||||
@@ -1,4 +1,4 @@
|
||||
-/*-*- Mode: C; c-basic-offset: 8 -*-*/
|
||||
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||
|
||||
/***
|
||||
Copyright 2010 Lennart Poettering
|
||||
@@ -325,18 +325,13 @@ int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t
|
||||
}
|
||||
|
||||
int sd_notify(int unset_environment, const char *state) {
|
||||
-#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
|
||||
+#if defined(DISABLE_SYSTEMD) || !defined(__linux__) || !defined(SOCK_CLOEXEC)
|
||||
return 0;
|
||||
#else
|
||||
int fd = -1, r;
|
||||
struct msghdr msghdr;
|
||||
struct iovec iovec;
|
||||
union sockaddr_union sockaddr;
|
||||
- struct ucred *ucred;
|
||||
- union {
|
||||
- struct cmsghdr cmsghdr;
|
||||
- uint8_t buf[CMSG_SPACE(sizeof(struct ucred))];
|
||||
- } control;
|
||||
const char *e;
|
||||
|
||||
if (!state) {
|
||||
@@ -369,23 +364,15 @@ int sd_notify(int unset_environment, const char *state) {
|
||||
iovec.iov_base = (char*) state;
|
||||
iovec.iov_len = strlen(state);
|
||||
|
||||
- memset(&control, 0, sizeof(control));
|
||||
- control.cmsghdr.cmsg_level = SOL_SOCKET;
|
||||
- control.cmsghdr.cmsg_type = SCM_CREDENTIALS;
|
||||
- control.cmsghdr.cmsg_len = CMSG_LEN(sizeof(struct ucred));
|
||||
-
|
||||
- ucred = (struct ucred*) CMSG_DATA(&control.cmsghdr);
|
||||
- ucred->pid = getpid();
|
||||
- ucred->uid = getuid();
|
||||
- ucred->gid = getgid();
|
||||
-
|
||||
memset(&msghdr, 0, sizeof(msghdr));
|
||||
msghdr.msg_name = &sockaddr;
|
||||
- msghdr.msg_namelen = sizeof(struct sockaddr_un);
|
||||
+ msghdr.msg_namelen = sizeof(sa_family_t) + strlen(e);
|
||||
+
|
||||
+ if (msghdr.msg_namelen > sizeof(struct sockaddr_un))
|
||||
+ msghdr.msg_namelen = sizeof(struct sockaddr_un);
|
||||
+
|
||||
msghdr.msg_iov = &iovec;
|
||||
msghdr.msg_iovlen = 1;
|
||||
- msghdr.msg_control = &control;
|
||||
- msghdr.msg_controllen = control.cmsghdr.cmsg_len;
|
||||
|
||||
if (sendmsg(fd, &msghdr, MSG_NOSIGNAL) < 0) {
|
||||
r = -errno;
|
||||
@@ -437,10 +424,10 @@ int sd_booted(void) {
|
||||
/* We simply test whether the systemd cgroup hierarchy is
|
||||
* mounted */
|
||||
|
||||
- if (lstat("/cgroup", &a) < 0)
|
||||
+ if (lstat("/sys/fs/cgroup", &a) < 0)
|
||||
return 0;
|
||||
|
||||
- if (lstat("/cgroup/systemd", &b) < 0)
|
||||
+ if (lstat("/sys/fs/cgroup/systemd", &b) < 0)
|
||||
return 0;
|
||||
|
||||
return a.st_dev != b.st_dev;
|
||||
diff --git a/runtime/sd-daemon.h b/runtime/sd-daemon.h
|
||||
index fd6221f..45aac8b 100644
|
||||
--- a/runtime/sd-daemon.h
|
||||
+++ b/runtime/sd-daemon.h
|
||||
@@ -1,4 +1,4 @@
|
||||
-/*-*- Mode: C; c-basic-offset: 8 -*-*/
|
||||
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||
|
||||
#ifndef foosddaemonhfoo
|
||||
#define foosddaemonhfoo
|
||||
@@ -67,9 +67,13 @@ extern "C" {
|
||||
See sd-daemon(7) for more information.
|
||||
*/
|
||||
|
||||
-#if __GNUC__ >= 4
|
||||
+#if (__GNUC__ >= 4)
|
||||
#define _sd_printf_attr_(a,b) __attribute__ ((format (printf, a, b)))
|
||||
-#define _sd_hidden_ __attribute__ ((visibility("hidden")))
|
||||
+# if defined(SD_EXPORT_SYMBOLS)
|
||||
+# define _sd_hidden_
|
||||
+# else
|
||||
+# define _sd_hidden_ __attribute__ ((visibility("hidden")))
|
||||
+# endif
|
||||
#else
|
||||
#define _sd_printf_attr_(a,b)
|
||||
#define _sd_hidden_
|
||||
@@ -171,7 +175,7 @@ int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t
|
||||
|
||||
/*
|
||||
Informs systemd about changed daemon state. This takes a number of
|
||||
- newline seperated environment-style variable assignments in a
|
||||
+ newline separated environment-style variable assignments in a
|
||||
string. The following variables are known:
|
||||
|
||||
READY=1 Tells systemd that daemon startup is finished (only
|
||||
--
|
||||
1.7.1
|
||||
|
||||
From 020e414396b9ed4d005b6b0f6fb6567fe954230c Mon Sep 17 00:00:00 2001
|
||||
From: Marius Tomaschewski <mt@suse.de>
|
||||
Date: Thu, 20 Jan 2011 15:08:08 +0100
|
||||
Subject: [PATCH 4/4] Improved systemd socket activation support
|
||||
|
||||
Support for multiple unix sockets and activation in forking mode
|
||||
---
|
||||
plugins/imuxsock/imuxsock.c | 72 ++++++++++++++++++------------------------
|
||||
tools/syslogd.c | 36 ++++++++++++++++++++-
|
||||
2 files changed, 65 insertions(+), 43 deletions(-)
|
||||
|
||||
diff --git a/plugins/imuxsock/imuxsock.c b/plugins/imuxsock/imuxsock.c
|
||||
index 89bb50b..fc6b1e7 100644
|
||||
--- a/plugins/imuxsock/imuxsock.c
|
||||
+++ b/plugins/imuxsock/imuxsock.c
|
||||
@@ -87,6 +87,7 @@ static prop_t *funixHName[MAXFUNIX] = { NULL, }; /* host-name override - if set,
|
||||
static int funixFlowCtl[MAXFUNIX] = { eFLOWCTL_NO_DELAY, }; /* flow control settings for this socket */
|
||||
static int funix[MAXFUNIX] = { -1, }; /* read-only after startup */
|
||||
static int nfunix = 1; /* number of Unix sockets open / read-only after startup */
|
||||
+static int sd_fds = 0; /* number of systemd activated sockers */
|
||||
|
||||
/* config settings */
|
||||
static int bOmitLocalLogging = 0;
|
||||
@@ -191,39 +192,19 @@ 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;
|
||||
- }
|
||||
- }
|
||||
+ if (sd_fds > 0) {
|
||||
+ for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + sd_fds; fd++) {
|
||||
+ if( sd_is_socket_unix(fd, SOCK_DGRAM, -1, path, 0) == 1) {
|
||||
+ /* ok, it matches -- just use as is */
|
||||
+ return fd;
|
||||
+ }
|
||||
+ /*
|
||||
+ * otherwise it either didn't matched *this* socket and
|
||||
+ * we just continue to check the next one or there were
|
||||
+ * an error and we will recreate it bellow.
|
||||
+ */
|
||||
+ }
|
||||
+ }
|
||||
|
||||
unlink(path);
|
||||
|
||||
@@ -406,6 +387,11 @@ CODESTARTwillRun
|
||||
if(pLogSockName != NULL)
|
||||
funixn[0] = pLogSockName;
|
||||
|
||||
+ sd_fds = sd_listen_fds(0);
|
||||
+ if (sd_fds < 0) {
|
||||
+ errmsg.LogError(-sd_fds, NO_ERRCODE, "Failed to acquire systemd sockets");
|
||||
+ }
|
||||
+
|
||||
/* initialize and return if will run or not */
|
||||
for (i = startIndexUxLocalSockets ; i < nfunix ; i++) {
|
||||
if ((funix[i] = create_unix_socket((char*) funixn[i], funixCreateSockPath[i])) != -1)
|
||||
@@ -430,15 +416,19 @@ CODESTARTafterRun
|
||||
if (funix[i] != -1)
|
||||
close(funix[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)
|
||||
+ /* Clean-up files. If systemd passed us a socket it is
|
||||
+ * systemd's job to clean it up.*/
|
||||
+ for(i = startIndexUxLocalSockets; i < nfunix; i++) {
|
||||
+ if (funixn[i] && funix[i] != -1) {
|
||||
+ if (sd_fds > 0 &&
|
||||
+ funix[i] >= SD_LISTEN_FDS_START &&
|
||||
+ funix[i] < SD_LISTEN_FDS_START + sd_fds)
|
||||
+ continue;
|
||||
+
|
||||
unlink((char*) funixn[i]);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
/* free no longer needed string */
|
||||
free(pLogSockName);
|
||||
free(pLogHostName);
|
||||
diff --git a/tools/syslogd.c b/tools/syslogd.c
|
||||
index 2e4ea5d..245ebe3 100644
|
||||
index 245ebe3..701036d 100644
|
||||
--- a/tools/syslogd.c
|
||||
+++ b/tools/syslogd.c
|
||||
@@ -135,6 +135,7 @@
|
||||
#include "net.h"
|
||||
#include "vm.h"
|
||||
#include "prop.h"
|
||||
+#include "sd-daemon.h"
|
||||
|
||||
/* definitions for objects we access */
|
||||
DEFobjCurrIf(obj)
|
||||
@@ -2431,6 +2432,8 @@ doGlblProcessInit(void)
|
||||
@@ -2429,12 +2429,44 @@ doGlblProcessInit(void)
|
||||
*/
|
||||
exit(1); /* "good" exit - after forking, not diasabling anything */
|
||||
}
|
||||
+
|
||||
num_fds = getdtablesize();
|
||||
close(0);
|
||||
/* we keep stdout and stderr open in case we have to emit something */
|
||||
+ i = 3;
|
||||
+
|
||||
+ if (sd_listen_fds(0) <= 0)
|
||||
for (i = 3; i < num_fds; i++)
|
||||
+ /* if (sd_booted()) */ {
|
||||
+ const char *e;
|
||||
+ char buf[24] = { '\0' };
|
||||
+ char *p = NULL;
|
||||
+ unsigned long l;
|
||||
+ int sd_fds;
|
||||
+
|
||||
+ /* fork & systemd socket activation:
|
||||
+ * fetch listen pid and update to ours,
|
||||
+ * when it is set to pid of our parent.
|
||||
+ */
|
||||
+ if ( (e = getenv("LISTEN_PID"))) {
|
||||
+ errno = 0;
|
||||
+ l = strtoul(e, &p, 10);
|
||||
+ if (errno == 0 && l > 0 && (!p || !*p)) {
|
||||
+ if (getppid() == (pid_t)l) {
|
||||
+ snprintf(buf, sizeof(buf), "%d",
|
||||
+ getpid());
|
||||
+ setenv("LISTEN_PID", buf, 1);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
|
||||
- if (sd_listen_fds(0) <= 0)
|
||||
- for (i = 3; i < num_fds; i++)
|
||||
+ /*
|
||||
+ * close only all further fds, except
|
||||
+ * of the fds provided by systemd.
|
||||
+ */
|
||||
+ sd_fds = sd_listen_fds(0);
|
||||
+ if (sd_fds > 0)
|
||||
+ i = SD_LISTEN_FDS_START + sd_fds;
|
||||
+ }
|
||||
+ for ( ; i < num_fds; i++)
|
||||
(void) close(i);
|
||||
untty();
|
||||
}
|
||||
--
|
||||
1.7.1
|
||||
|
||||
|
@@ -1,3 +1,9 @@
|
||||
-------------------------------------------------------------------
|
||||
Thu Jan 20 14:10:59 UTC 2011 - mt@suse.de
|
||||
|
||||
- Improved systemd socket activation support to allow multiple
|
||||
unix sockets and activation in forking mode (bnc#656197).
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Fri Dec 3 16:49:41 UTC 2010 - mt@suse.de
|
||||
|
||||
|
Reference in New Issue
Block a user