|
|
6c64be |
From 5d0e19fcc1cea77a72647cf96c5d3d773e8ee277 Mon Sep 17 00:00:00 2001
|
|
|
6c64be |
From: Tomasz Torcz <tomek@pipebreaker.pl>
|
|
|
6c64be |
Date: Wed, 28 Nov 2012 13:37:07 +0100
|
|
|
6c64be |
Subject: iscsid: implement systemd-compatible socket activation
|
|
|
6c64be |
|
|
|
6c64be |
---
|
|
|
6c64be |
usr/mgmt_ipc.c | 29 +++++++++++++++++++++++++++++
|
|
|
6c64be |
usr/mgmt_ipc.h | 1 +
|
|
|
6c64be |
2 files changed, 30 insertions(+)
|
|
|
6c64be |
|
|
|
6c64be |
diff --git a/usr/mgmt_ipc.c b/usr/mgmt_ipc.c
|
|
|
6c64be |
index a1dafc9..87bd346 100644
|
|
|
6c64be |
--- a/usr/mgmt_ipc.c
|
|
|
6c64be |
+++ b/usr/mgmt_ipc.c
|
|
|
6c64be |
@@ -39,6 +39,7 @@
|
|
|
6c64be |
|
|
|
6c64be |
#define PEERUSER_MAX 64
|
|
|
6c64be |
#define EXTMSG_MAX (64 * 1024)
|
|
|
6c64be |
+#define SD_SOCKET_FDS_START 3
|
|
|
6c64be |
|
|
|
6c64be |
int
|
|
|
6c64be |
mgmt_ipc_listen(void)
|
|
|
6c64be |
@@ -46,6 +47,12 @@ mgmt_ipc_listen(void)
|
|
|
6c64be |
int fd, err, addr_len;
|
|
|
6c64be |
struct sockaddr_un addr;
|
|
|
6c64be |
|
|
|
6c64be |
+ /* first check if we have fd handled by systemd */
|
|
|
6c64be |
+ fd = mgmt_ipc_systemd();
|
|
|
6c64be |
+ if (fd >= 0)
|
|
|
6c64be |
+ return fd;
|
|
|
6c64be |
+
|
|
|
6c64be |
+ /* manually establish a socket */
|
|
|
6c64be |
fd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
|
|
6c64be |
if (fd < 0) {
|
|
|
6c64be |
log_error("Can not create IPC socket");
|
|
|
6c64be |
@@ -73,6 +80,28 @@ mgmt_ipc_listen(void)
|
|
|
6c64be |
return fd;
|
|
|
6c64be |
}
|
|
|
6c64be |
|
|
|
6c64be |
+int mgmt_ipc_systemd(void)
|
|
|
6c64be |
+{
|
|
|
6c64be |
+ const char *env;
|
|
|
6c64be |
+
|
|
|
6c64be |
+ env = getenv("LISTEN_PID");
|
|
|
6c64be |
+
|
|
|
6c64be |
+ if (!env || (strtoul(env, NULL, 10) != getpid()))
|
|
|
6c64be |
+ return -EINVAL;
|
|
|
6c64be |
+
|
|
|
6c64be |
+ env = getenv("LISTEN_FDS");
|
|
|
6c64be |
+
|
|
|
6c64be |
+ if (!env)
|
|
|
6c64be |
+ return -EINVAL;
|
|
|
6c64be |
+
|
|
|
6c64be |
+ if (strtoul(env, NULL, 10) != 1) {
|
|
|
6c64be |
+ log_error("Did not receive exactly one IPC socket from systemd");
|
|
|
6c64be |
+ return -EINVAL;
|
|
|
6c64be |
+ }
|
|
|
6c64be |
+
|
|
|
6c64be |
+ return SD_SOCKET_FDS_START;
|
|
|
6c64be |
+}
|
|
|
6c64be |
+
|
|
|
6c64be |
void
|
|
|
6c64be |
mgmt_ipc_close(int fd)
|
|
|
6c64be |
{
|
|
|
6c64be |
diff --git a/usr/mgmt_ipc.h b/usr/mgmt_ipc.h
|
|
|
6c64be |
index 7d8ce72..55972ed 100644
|
|
|
6c64be |
--- a/usr/mgmt_ipc.h
|
|
|
6c64be |
+++ b/usr/mgmt_ipc.h
|
|
|
6c64be |
@@ -112,6 +112,7 @@ typedef int mgmt_ipc_fn_t(struct queue_task *);
|
|
|
6c64be |
struct queue_task;
|
|
|
6c64be |
void mgmt_ipc_write_rsp(struct queue_task *qtask, int err);
|
|
|
6c64be |
int mgmt_ipc_listen(void);
|
|
|
6c64be |
+int mgmt_ipc_systemd(void);
|
|
|
6c64be |
void mgmt_ipc_close(int fd);
|
|
|
6c64be |
void mgmt_ipc_handle(int accept_fd);
|
|
|
6c64be |
|
|
|
6c64be |
--
|
|
|
6c64be |
1.7.11.7
|
|
|
6c64be |
|