From 8ed37f5fa0092c82a429aa329ef8c7ac481a548f Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 23 Apr 2020 15:22:29 +0200 Subject: [PATCH] Always append /ID to cond if run/task/service is declared with :ID This patch is a follow-up to the idea introduced in 1d6737e, but this time we make sure to always append the svc ID to conditions if their .conf has been declared with :ID Meaning, the following .conf: service :0 /sbin/teamd --config-file /etc/teamd-lag0.conf service :1 /sbin/teamd --config-file /etc/teamd-lag0.conf results in the following two conditions: svc/sbin/teamd/0 svc/sbin/teamd/1 With a custom 'name:foo': service name:lag :0 /sbin/teamd service name:lag :1 /sbin/teamd the resulting conditions look even prettier: svc/lag/0 svc/lag/1 Signed-off-by: Joachim Nilsson --- src/cond-w.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cond-w.c b/src/cond-w.c index 1df83676..3239caa2 100644 --- a/src/cond-w.c +++ b/src/cond-w.c @@ -83,7 +83,7 @@ char *mkcond(svc_t *svc, char *buf, size_t len) /* Custom name:foo declaration found => svc/foo instead of /svc/bin/path/pidfile-.pid */ if (strcmp(nm, svc->name)) { - snprintf(buf, len, "svc/%s/%s", svc->name, svc->id); + snprintf(buf, len, "svc/%s", svc->name); _d("Composed condition from svc->name %s => %s", svc->name, buf); } else { snprintf(buf, len, "svc%s%s%s", path[0] != 0 && path[0] != '/' ? "/" : "", path, ptr); @@ -100,6 +100,12 @@ char *mkcond(svc_t *svc, char *buf, size_t len) if (ptr && !strcmp(ptr, ".pid")) *ptr = 0; + /* Always append /ID if service is declared with :ID */ + if (svc->id[0]) { + strlcat(buf, "/", len); + strlcat(buf, svc->id, len); + } + _d("Creating condition => %s", buf); return buf;