mirror of
https://github.com/troglobit/finit.git
synced 2026-10-02 22:13:01 +07:00
Custom name:foo will now create condition svc/foo w/o path
When registering a service there is the option to set a custom PID file, and even tell Finit to maintain that PID file in case the daemon doesn't Until now there hasn't been a way to create custom conditions though ... This patch leverages the new 'name:foo' argument to tas/run/services to trigger condition 'svc/foo' (notice lack of path!) when a custom name is set and either the default, or the custom, PID file is created. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
+16
-4
@@ -59,15 +59,21 @@ char *mkcond(svc_t *svc, char *buf, size_t len)
|
||||
{
|
||||
char path[256];
|
||||
char *pidfile;
|
||||
char *ptr;
|
||||
char *ptr, *nm;
|
||||
|
||||
strlcpy(path, svc->cmd, sizeof(path));
|
||||
ptr = rindex(path, '/');
|
||||
if (ptr)
|
||||
*ptr = 0;
|
||||
*ptr++ = 0;
|
||||
else
|
||||
path[0] = 0;
|
||||
|
||||
/* Figure out default name used when registering service */
|
||||
if (ptr)
|
||||
nm = ptr;
|
||||
else
|
||||
nm = svc->cmd;
|
||||
|
||||
pidfile = pid_file(svc);
|
||||
ptr = strstr(pidfile, "run");
|
||||
if (ptr)
|
||||
@@ -75,8 +81,14 @@ char *mkcond(svc_t *svc, char *buf, size_t len)
|
||||
else
|
||||
ptr = rindex(pidfile, '/');
|
||||
|
||||
snprintf(buf, len, "svc%s%s%s", path[0] != 0 && path[0] != '/' ? "/" : "", path, ptr);
|
||||
_d("Composed condition from cmd %s (path %s) and pidfile %s => %s", svc->cmd, path, ptr, buf);
|
||||
/* Custom name:foo declaration found => svc/foo instead of /svc/bin/path/pidfile-.pid */
|
||||
if (strcmp(nm, svc->name)) {
|
||||
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);
|
||||
_d("Composed condition from cmd %s (path %s) and pidfile %s => %s", svc->cmd, path, ptr, buf);
|
||||
}
|
||||
|
||||
/* Case: /var/run/dbus/pid */
|
||||
ptr = strstr(buf, "/pid");
|
||||
|
||||
Reference in New Issue
Block a user