]> git.ipfire.org Git - people/amarx/ipfire-3.x.git/blame - iscsi-initiator-utils/patches/0008-iscsid-implement-systemd-compatible-socket-activatio.patch
iscsi-initiator-utils: Various improvements.
[people/amarx/ipfire-3.x.git] / iscsi-initiator-utils / patches / 0008-iscsid-implement-systemd-compatible-socket-activatio.patch
CommitLineData
092b90ae
SS
1From 5d0e19fcc1cea77a72647cf96c5d3d773e8ee277 Mon Sep 17 00:00:00 2001
2From: Tomasz Torcz <tomek@pipebreaker.pl>
3Date: Wed, 28 Nov 2012 13:37:07 +0100
4Subject: iscsid: implement systemd-compatible socket activation
5
6---
7 usr/mgmt_ipc.c | 29 +++++++++++++++++++++++++++++
8 usr/mgmt_ipc.h | 1 +
9 2 files changed, 30 insertions(+)
10
11diff --git a/usr/mgmt_ipc.c b/usr/mgmt_ipc.c
12index a1dafc9..87bd346 100644
13--- a/usr/mgmt_ipc.c
14+++ b/usr/mgmt_ipc.c
15@@ -39,6 +39,7 @@
16
17 #define PEERUSER_MAX 64
18 #define EXTMSG_MAX (64 * 1024)
19+#define SD_SOCKET_FDS_START 3
20
21 int
22 mgmt_ipc_listen(void)
23@@ -46,6 +47,12 @@ mgmt_ipc_listen(void)
24 int fd, err, addr_len;
25 struct sockaddr_un addr;
26
27+ /* first check if we have fd handled by systemd */
28+ fd = mgmt_ipc_systemd();
29+ if (fd >= 0)
30+ return fd;
31+
32+ /* manually establish a socket */
33 fd = socket(AF_LOCAL, SOCK_STREAM, 0);
34 if (fd < 0) {
35 log_error("Can not create IPC socket");
36@@ -73,6 +80,28 @@ mgmt_ipc_listen(void)
37 return fd;
38 }
39
40+int mgmt_ipc_systemd(void)
41+{
42+ const char *env;
43+
44+ env = getenv("LISTEN_PID");
45+
46+ if (!env || (strtoul(env, NULL, 10) != getpid()))
47+ return -EINVAL;
48+
49+ env = getenv("LISTEN_FDS");
50+
51+ if (!env)
52+ return -EINVAL;
53+
54+ if (strtoul(env, NULL, 10) != 1) {
55+ log_error("Did not receive exactly one IPC socket from systemd");
56+ return -EINVAL;
57+ }
58+
59+ return SD_SOCKET_FDS_START;
60+}
61+
62 void
63 mgmt_ipc_close(int fd)
64 {
65diff --git a/usr/mgmt_ipc.h b/usr/mgmt_ipc.h
66index 7d8ce72..55972ed 100644
67--- a/usr/mgmt_ipc.h
68+++ b/usr/mgmt_ipc.h
69@@ -112,6 +112,7 @@ typedef int mgmt_ipc_fn_t(struct queue_task *);
70 struct queue_task;
71 void mgmt_ipc_write_rsp(struct queue_task *qtask, int err);
72 int mgmt_ipc_listen(void);
73+int mgmt_ipc_systemd(void);
74 void mgmt_ipc_close(int fd);
75 void mgmt_ipc_handle(int accept_fd);
76
77--
781.7.11.7
79