[PATCH] Allow overriding the IPC socket path via TGT_IPC_SOCKET

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Ronnie Sahlberg <ronniesahlberg@xxxxxxxxx>
---
 doc/tgtd.8.xml |  9 +++++++++
 usr/mgmt.c     | 11 +++++++----
 usr/tgtadm.c   |  8 ++++++--
 3 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/doc/tgtd.8.xml b/doc/tgtd.8.xml
index a0020c6..57ac805 100644
--- a/doc/tgtd.8.xml
+++ b/doc/tgtd.8.xml
@@ -162,6 +162,15 @@
   </refsect1>
 
 
+  <refsect1><title>ENVIRONMENT VARIABLES</title>
+    <refsect2><title>TGT_IPC_SOCKET=&lt;path&gt;</title>
+      <para>
+	When set tgtd and tgtadm will use the specified path as the
+	IPC socket instead of the default '/var/run/tgtd/socket.0'
+      </para>
+    </refsect2>
+  </refsect1>
+
   <refsect1><title>SEE ALSO</title>
     <para>
       tgtadm(8), tgt-admin(8), tgtimg(8), tgt-setup-lun(8).
diff --git a/usr/mgmt.c b/usr/mgmt.c
index 18fbfc1..de23f14 100644
--- a/usr/mgmt.c
+++ b/usr/mgmt.c
@@ -766,12 +766,15 @@ int ipc_init(void)
 	int fd = 0, err;
 	struct sockaddr_un addr;
 	struct stat st = {0};
+	char *path;
 
-	if (stat(TGT_IPC_DIR, &st) == -1) {
-		mkdir(TGT_IPC_DIR, 0755);
+	if ((path = getenv("TGT_IPC_SOCKET")) == NULL) {
+		path = TGT_IPC_NAMESPACE;
+		if (stat(TGT_IPC_DIR, &st) == -1)
+			mkdir(TGT_IPC_DIR, 0755);
 	}
 
-	sprintf(mgmt_lock_path, "%s.%d.lock", TGT_IPC_NAMESPACE, control_port);
+	sprintf(mgmt_lock_path, "%s.%d.lock", path, control_port);
 	ipc_lock_fd = open(mgmt_lock_path, O_WRONLY | O_CREAT,
 			   S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
 	if (ipc_lock_fd < 0) {
@@ -794,7 +797,7 @@ int ipc_init(void)
 		goto close_lock_fd;
 	}
 
-	sprintf(mgmt_path, "%s.%d", TGT_IPC_NAMESPACE, control_port);
+	snprintf(mgmt_path, sizeof(mgmt_path), "%s.%d", path, control_port);
 	unlink(mgmt_path);
 	memset(&addr, 0, sizeof(addr));
 	addr.sun_family = AF_LOCAL;
diff --git a/usr/tgtadm.c b/usr/tgtadm.c
index 7a2dc35..b8df58d 100644
--- a/usr/tgtadm.c
+++ b/usr/tgtadm.c
@@ -211,7 +211,7 @@ static int ipc_mgmt_connect(int *fd)
 {
 	int err;
 	struct sockaddr_un addr;
-	char mgmt_path[256];
+	char mgmt_path[256], *path;
 
 	*fd = socket(AF_LOCAL, SOCK_STREAM, 0);
 	if (*fd < 0) {
@@ -221,7 +221,11 @@ static int ipc_mgmt_connect(int *fd)
 
 	memset(&addr, 0, sizeof(addr));
 	addr.sun_family = AF_LOCAL;
-	sprintf(mgmt_path, "%s.%d", TGT_IPC_NAMESPACE, control_port);
+	if ((path = getenv("TGT_IPC_SOCKET")) == NULL)
+		path = TGT_IPC_NAMESPACE;
+	snprintf(mgmt_path, sizeof(mgmt_path), "%s.%d",
+			 path, control_port);
+
 	strncpy(addr.sun_path, mgmt_path, sizeof(addr.sun_path));
 
 	err = connect(*fd, (struct sockaddr *) &addr, sizeof(addr));
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux