* [PATCH] Allow setting the IPC socket via environment variable
@ 2015-05-01 1:29 Ronnie Sahlberg
2015-05-01 1:29 ` [PATCH] Allow overriding the IPC socket path via TGT_IPC_SOCKET Ronnie Sahlberg
0 siblings, 1 reply; 2+ messages in thread
From: Ronnie Sahlberg @ 2015-05-01 1:29 UTC (permalink / raw)
To: stgt; +Cc: fujita.tomonori
List, Tomo
Another small patch. This time to set the IPC socket for TGTD and TGTADM
via the TGT_IPC_SOCKET environment variable.
This is useful for example for my libiscsi tests since it allows
spinning up a local TGT daemon just for 'make test'
regards
ronnie sahlberg
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH] Allow overriding the IPC socket path via TGT_IPC_SOCKET
2015-05-01 1:29 [PATCH] Allow setting the IPC socket via environment variable Ronnie Sahlberg
@ 2015-05-01 1:29 ` Ronnie Sahlberg
0 siblings, 0 replies; 2+ messages in thread
From: Ronnie Sahlberg @ 2015-05-01 1:29 UTC (permalink / raw)
To: stgt; +Cc: fujita.tomonori, Ronnie Sahlberg
Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>
---
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=<path></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
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-05-01 1:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-01 1:29 [PATCH] Allow setting the IPC socket via environment variable Ronnie Sahlberg
2015-05-01 1:29 ` [PATCH] Allow overriding the IPC socket path via TGT_IPC_SOCKET Ronnie Sahlberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).