aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavide Cavalca <davide@geexbox.org>2011-01-25 02:26:03 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-01-25 02:26:03 +0100
commit9b3b9790b32d440eb89af5edda70a66b1829e861 (patch)
treef0e6d7d088262813025df1f0393cbd2ded8c1c78
parent444ff284c4097081108e0eded4711247aacda740 (diff)
downloadbusybox-w32-9b3b9790b32d440eb89af5edda70a66b1829e861.tar.gz
busybox-w32-9b3b9790b32d440eb89af5edda70a66b1829e861.tar.bz2
busybox-w32-9b3b9790b32d440eb89af5edda70a66b1829e861.zip
add ENABLE_FEATURE_SYSTEMD and use it in syslogd
Signed-off-by: Davide Cavalca <davide@geexbox.org> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--include/libbb.h6
-rw-r--r--libbb/systemd_support.c62
-rw-r--r--sysklogd/syslogd.c5
3 files changed, 73 insertions, 0 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 968bdcf5a..32e25a8d4 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1217,6 +1217,12 @@ extern void selinux_preserve_fcontext(int fdesc) FAST_FUNC;
1217#endif 1217#endif
1218extern void selinux_or_die(void) FAST_FUNC; 1218extern void selinux_or_die(void) FAST_FUNC;
1219 1219
1220
1221/* systemd support */
1222#define SD_LISTEN_FDS_START 3
1223int sd_listen_fds(void);
1224
1225
1220/* setup_environment: 1226/* setup_environment:
1221 * if chdir pw->pw_dir: ok: else if to_tmp == 1: goto /tmp else: goto / or die 1227 * if chdir pw->pw_dir: ok: else if to_tmp == 1: goto /tmp else: goto / or die
1222 * if clear_env = 1: cd(pw->pw_dir), clear environment, then set 1228 * if clear_env = 1: cd(pw->pw_dir), clear environment, then set
diff --git a/libbb/systemd_support.c b/libbb/systemd_support.c
new file mode 100644
index 000000000..981296dbb
--- /dev/null
+++ b/libbb/systemd_support.c
@@ -0,0 +1,62 @@
1/*
2 * Copyright (C) 2011 Davide Cavalca <davide@geexbox.org>
3 *
4 * Based on http://cgit.freedesktop.org/systemd/tree/src/sd-daemon.c
5 * Copyright 2010 Lennart Poettering
6 *
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation files
9 * (the "Software"), to deal in the Software without restriction,
10 * including without limitation the rights to use, copy, modify, merge,
11 * publish, distribute, sublicense, and/or sell copies of the Software,
12 * and to permit persons to whom the Software is furnished to do so,
13 * subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27#include "libbb.h"
28
29//config:config FEATURE_SYSTEMD
30//config: bool "Enable systemd support"
31//config: default y
32//config: help
33//config: If you plan to use busybox daemons on a system where daemons
34//config: are controlled by systemd, enable this option.
35//config: If you don't use systemd, it is still safe to enable it,
36//config: but yhe downside is increased code size.
37
38//kbuild:lib-$(CONFIG_FEATURE_SYSTEMD) += systemd_support.o
39
40int sd_listen_fds(void)
41{
42 const char *e;
43 int n;
44 int fd;
45
46 e = getenv("LISTEN_PID");
47 if (!e)
48 return 0;
49 n = xatoi_positive(e);
50 /* Is this for us? */
51 if (getpid() != (pid_t) n)
52 return 0;
53
54 e = getenv("LISTEN_FDS");
55 if (!e)
56 return 0;
57 n = xatoi_positive(e);
58 for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++)
59 close_on_exec_on(fd);
60
61 return n;
62}
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index fb7309538..24cab3b6c 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -512,6 +512,11 @@ static NOINLINE int create_socket(void)
512 int sock_fd; 512 int sock_fd;
513 char *dev_log_name; 513 char *dev_log_name;
514 514
515#if ENABLE_FEATURE_SYSTEMD
516 if (sd_listen_fds() == 1)
517 return SD_LISTEN_FDS_START;
518#endif
519
515 memset(&sunx, 0, sizeof(sunx)); 520 memset(&sunx, 0, sizeof(sunx));
516 sunx.sun_family = AF_UNIX; 521 sunx.sun_family = AF_UNIX;
517 522