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