[stgt] [PATCH 09/15] tgt: os.h - bind() is picky about names
Boaz Harrosh
bharrosh at panasas.com
Sun Mar 1 17:51:53 CET 2009
The BSD's bind does not like the Linux IPC names with zero
as first char and zeros padding at end. Separate implementations
in os.c.
Note: On BSD, after exit a file is left in current directory
with the pipe's name. The "up" script was modified to
delete this file before and after the tgtd load.
(File name is: TGT_IPC_ABSTRACT_NAMESPACE)
Signed-off-by: Boaz Harrosh <bharrosh at panasas.com>
---
usr/bsd/os.c | 14 ++++++++++++++
usr/linux/os.c | 10 ++++++++++
usr/mgmt.c | 6 ++----
usr/os.h | 3 +++
4 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/usr/bsd/os.c b/usr/bsd/os.c
index 28a5926..d2dfdab 100644
--- a/usr/bsd/os.c
+++ b/usr/bsd/os.c
@@ -11,7 +11,13 @@
*/
#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
#include <unistd.h>
+#include <netdb.h>
+#include <sys/socket.h>
+#include <sys/un.h>
#include <linux/fs.h>
@@ -39,3 +45,11 @@ int os_blockdev_size(int fd, uint64_t *size)
*size = ~0ULL;
return 0;
}
+
+int os_bind_ipc(int fd, struct sockaddr_un *addr, const char *ipc_name_space)
+{
+ strcpy(addr->sun_path, ipc_name_space);
+ addr->sun_len = SUN_LEN(addr) + 1;
+
+ return bind(fd, (struct sockaddr *)addr, addr->sun_len);
+}
diff --git a/usr/linux/os.c b/usr/linux/os.c
index aeb7b21..5b50aff 100644
--- a/usr/linux/os.c
+++ b/usr/linux/os.c
@@ -12,12 +12,14 @@
#include <errno.h>
#include <stdio.h>
+#include <string.h>
#include <inttypes.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/syscall.h>
+#include <sys/un.h>
#include <linux/fs.h>
@@ -95,3 +97,11 @@ int os_blockdev_size(int fd, uint64_t *size)
{
return ioctl(fd, BLKGETSIZE64, size);
}
+
+int os_bind_ipc(int fd, struct sockaddr_un *addr, const char *ipc_name_space)
+{
+ memcpy((char *) addr->sun_path + 1, ipc_name_space,
+ strlen(ipc_name_space));
+
+ return bind(fd, (struct sockaddr *)addr, sizeof(*addr));
+}
diff --git a/usr/mgmt.c b/usr/mgmt.c
index b7b1a97..2cd8cf8 100644
--- a/usr/mgmt.c
+++ b/usr/mgmt.c
@@ -537,12 +537,10 @@ int ipc_init(void)
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_LOCAL;
- memcpy((char *) &addr.sun_path + 1, TGT_IPC_NAMESPACE,
- strlen(TGT_IPC_NAMESPACE));
- err = bind(fd, (struct sockaddr *) &addr, sizeof(addr));
+ err = os_bind_ipc(fd, &addr, TGT_IPC_NAMESPACE);
if (err) {
- eprintf("can't bind a socket, %m\n");
+ eprintf("can't bind a socket, %d, %s\n", err, strerror(errno));
goto out;
}
diff --git a/usr/os.h b/usr/os.h
index c8e65a1..7c0c538 100644
--- a/usr/os.h
+++ b/usr/os.h
@@ -15,4 +15,7 @@ int os_oom_adjust(void);
int os_blockdev_size(int fd, uint64_t *size);
+struct sockaddr_un;
+int os_bind_ipc(int fd, struct sockaddr_un *addr, const char *ipc_name_space);
+
#endif /* ndef __TGT_OS_H__*/
--
1.6.0.6
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
More information about the stgt
mailing list