about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2024-02-07 17:03:23 +0100
committerLeah Neukirchen <leah@vuxu.org>2024-02-07 17:03:23 +0100
commitd6e27ae923575f0aa59875af6a4f2e7d7b0bb93c (patch)
treee6ace1001d574b033176297080d0bd880cf221b8
parentaa0310ff716ea0ecd20a3c0994be68e4fcf311d0 (diff)
downloadnitro-d6e27ae923575f0aa59875af6a4f2e7d7b0bb93c.tar.gz
nitro-d6e27ae923575f0aa59875af6a4f2e7d7b0bb93c.tar.xz
nitro-d6e27ae923575f0aa59875af6a4f2e7d7b0bb93c.zip
make nitroctl work with / in service names
-rw-r--r--nitro.c18
-rw-r--r--nitroctl.c7
2 files changed, 21 insertions, 4 deletions
diff --git a/nitro.c b/nitro.c
index 7a9abb4..3c48a44 100644
--- a/nitro.c
+++ b/nitro.c
@@ -1043,6 +1043,19 @@ open_control_socket() {
 		fatal("could not bind control socket: errno=%d\n", errno);
 }
 
+int
+notifyprefix(const char *name, const char *file)
+{
+	if (strncmp("ALL,", file, 4) == 0)
+		return 1;
+
+	// slashes are encoded as comma in the notify file name
+	while (*name && (*name == *file || (*name == '/' && *file == ',')))
+		name++, file++;
+
+	return *name == 0 && *file == ',';
+}
+
 void
 notify(int i)
 {
@@ -1058,9 +1071,8 @@ notify(int i)
 		if (name[0] == '.')
 			continue;
 
-		if ((strncmp(name, services[i].name, strlen(services[i].name)) == 0 &&
-		    name[strlen(services[i].name)] == ',') ||
-		    (strncmp("ALL,", name, 4) == 0)) {
+		if (notifyprefix(services[i].name, name)) {
+prn(2, "check %s to file %s passed\n", services[i].name, name);
 
 			struct sockaddr_un addr = { 0 };
 			addr.sun_family = AF_UNIX;
diff --git a/nitroctl.c b/nitroctl.c
index 27d0780..1fa2b0b 100644
--- a/nitroctl.c
+++ b/nitroctl.c
@@ -60,9 +60,14 @@ notifysock(const char *service)
 	char *path = strdup(sockpath);
 	if (!path || !*path)
 		path = default_sock;
+	path = dirname(path);
 
 	snprintf(notifypath, sizeof notifypath,
-	    "%s/notify/%s,%ld", dirname(path), service, (long)getpid());
+	    "%s/notify/%s,%ld", path, service, (long)getpid());
+
+	for (char *s = notifypath + strlen(path) + strlen("/notify/"); *s; s++)
+		if (*s == '/')
+			*s = ',';
 
 	struct sockaddr_un my_addr = { 0 };
 	my_addr.sun_family = AF_UNIX;