[PATCH] mgmt: Create ipc socket parent dir if does not exists

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

 



If the parent dir doesn't exists then tgtd will fail to create the
socket and exit.
This commit will check if the folder doesn't exists and create it.

Signed-off-by: Roi Dayan <roid@xxxxxxxxxxxx>
---
 usr/mgmt.c   | 5 +++++
 usr/tgtadm.h | 3 ++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/usr/mgmt.c b/usr/mgmt.c
index c2bd176..18fbfc1 100644
--- a/usr/mgmt.c
+++ b/usr/mgmt.c
@@ -765,6 +765,11 @@ int ipc_init(void)
 	extern short control_port;
 	int fd = 0, err;
 	struct sockaddr_un addr;
+	struct stat st = {0};
+
+	if (stat(TGT_IPC_DIR, &st) == -1) {
+		mkdir(TGT_IPC_DIR, 0755);
+	}
 
 	sprintf(mgmt_lock_path, "%s.%d.lock", TGT_IPC_NAMESPACE, control_port);
 	ipc_lock_fd = open(mgmt_lock_path, O_WRONLY | O_CREAT,
diff --git a/usr/tgtadm.h b/usr/tgtadm.h
index 866aac9..e3fda6a 100644
--- a/usr/tgtadm.h
+++ b/usr/tgtadm.h
@@ -1,7 +1,8 @@
 #ifndef TGTADM_H
 #define TGTADM_H
 
-#define TGT_IPC_NAMESPACE	"/var/run/tgtd/socket"
+#define TGT_IPC_DIR		"/var/run/tgtd"
+#define TGT_IPC_NAMESPACE	TGT_IPC_DIR"/socket"
 #define TGT_LLD_NAME_LEN	64
 
 #define GLOBAL_TID (~0U)
-- 
1.8.4.3

--
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