Blame SOURCES/0047-iscsiuio-systemd-socket-activation-support.patch

6c64be
From 8003178db245b43d04b27b559d5541ced24ec13f Mon Sep 17 00:00:00 2001
6c64be
From: Chris Leech <cleech@redhat.com>
6c64be
Date: Wed, 19 Dec 2012 21:39:06 -0800
6c64be
Subject: [PATCH] iscsiuio systemd socket activation support
6c64be
6c64be
---
6c64be
 iscsiuio/src/unix/iscsid_ipc.c | 28 ++++++++++++++++++++++++++++
6c64be
 1 file changed, 28 insertions(+)
6c64be
6c64be
diff --git a/iscsiuio/src/unix/iscsid_ipc.c b/iscsiuio/src/unix/iscsid_ipc.c
6c64be
index e22de0d..4908cb7 100644
6c64be
--- a/iscsiuio/src/unix/iscsid_ipc.c
6c64be
+++ b/iscsiuio/src/unix/iscsid_ipc.c
6c64be
@@ -948,6 +948,30 @@ static void *iscsid_loop(void *arg)
6c64be
 	pthread_exit(NULL);
6c64be
 }
6c64be
 
6c64be
+#define SD_SOCKET_FDS_START 3
6c64be
+
6c64be
+static int ipc_systemd(void)
6c64be
+{
6c64be
+	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_ERR("Did not receive exactly one IPC socket from systemd");
6c64be
+		return -EINVAL;
6c64be
+	}
6c64be
+
6c64be
+	return SD_SOCKET_FDS_START;
6c64be
+}
6c64be
+
6c64be
 /******************************************************************************
6c64be
  *  Initialize/Cleanup routines
6c64be
  ******************************************************************************/
6c64be
@@ -961,6 +985,10 @@ int iscsid_init()
6c64be
 	int rc, addr_len;
6c64be
 	struct sockaddr_un addr;
6c64be
 
6c64be
+	iscsid_opts.fd = ipc_systemd();
6c64be
+	if (iscsid_opts.fd >= 0)
6c64be
+		return 0;
6c64be
+
6c64be
 	iscsid_opts.fd = socket(AF_LOCAL, SOCK_STREAM, 0);
6c64be
 	if (iscsid_opts.fd < 0) {
6c64be
 		LOG_ERR(PFX "Can not create IPC socket");
6c64be
-- 
6c64be
1.8.3.1
6c64be