6bbb92
From b923362bb847eab5856fa3593f053e670d90e0fd Mon Sep 17 00:00:00 2001
6bbb92
From: Chris Leech <cleech@redhat.com>
6bbb92
Date: Wed, 19 Dec 2012 21:39:06 -0800
6bbb92
Subject: iscsiuio systemd socket activation support
6bbb92
6bbb92
---
6bbb92
 src/unix/iscsid_ipc.c | 28 ++++++++++++++++++++++++++++
6bbb92
 1 file changed, 28 insertions(+)
6bbb92
6bbb92
diff --git a/src/unix/iscsid_ipc.c b/src/unix/iscsid_ipc.c
6bbb92
index d7372fc..1c28822 100644
6bbb92
--- a/src/unix/iscsid_ipc.c
6bbb92
+++ b/src/unix/iscsid_ipc.c
6bbb92
@@ -948,6 +948,30 @@ static void *iscsid_loop(void *arg)
6bbb92
 	pthread_exit(NULL);
6bbb92
 }
6bbb92
 
6bbb92
+#define SD_SOCKET_FDS_START 3
6bbb92
+
6bbb92
+static int ipc_systemd(void)
6bbb92
+{
6bbb92
+	char *env;
6bbb92
+
6bbb92
+	env = getenv("LISTEN_PID");
6bbb92
+
6bbb92
+	if (!env || (strtoul(env, NULL, 10) != getpid()))
6bbb92
+		return -EINVAL;
6bbb92
+
6bbb92
+	env = getenv("LISTEN_FDS");
6bbb92
+
6bbb92
+	if (!env)
6bbb92
+		return -EINVAL;
6bbb92
+
6bbb92
+	if (strtoul(env, NULL, 10) != 1) {
6bbb92
+		LOG_ERR("Did not receive exactly one IPC socket from systemd");
6bbb92
+		return -EINVAL;
6bbb92
+	}
6bbb92
+
6bbb92
+	return SD_SOCKET_FDS_START;
6bbb92
+}
6bbb92
+
6bbb92
 /******************************************************************************
6bbb92
  *  Initialize/Cleanup routines
6bbb92
  ******************************************************************************/
6bbb92
@@ -961,6 +985,10 @@ int iscsid_init()
6bbb92
 	int rc;
6bbb92
 	struct sockaddr_un addr;
6bbb92
 
6bbb92
+	iscsid_opts.fd = ipc_systemd();
6bbb92
+	if (iscsid_opts.fd >= 0)
6bbb92
+		return 0;
6bbb92
+
6bbb92
 	iscsid_opts.fd = socket(AF_LOCAL, SOCK_STREAM, 0);
6bbb92
 	if (iscsid_opts.fd < 0) {
6bbb92
 		LOG_ERR(PFX "Can not create IPC socket");
6bbb92
-- 
6bbb92
1.7.11.7
6bbb92