mirror of
https://github.com/troglobit/finit.git
synced 2026-10-07 16:14:21 +07:00
Warn if a new service asserts the same condition as an existing one
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+5
-3
@@ -403,7 +403,7 @@ static int service_start(svc_t *svc)
|
||||
if (strlen(arg) < (sizeof(buf) - strlen(buf)))
|
||||
strlcat(buf, arg, sizeof(buf));
|
||||
}
|
||||
_d("Starting %s: %s", svc->cmd, buf);
|
||||
_d("Starting %s %s", svc->cmd, buf);
|
||||
}
|
||||
|
||||
logit(LOG_CONSOLE | LOG_NOTICE, "Starting %s[%d]", svc_ident(svc, NULL, 0), pid);
|
||||
@@ -704,6 +704,9 @@ static void parse_name(svc_t *svc, char *arg)
|
||||
}
|
||||
|
||||
strlcpy(svc->name, name, sizeof(svc->name));
|
||||
|
||||
/* Warn if svc generates same condition as an existing service */
|
||||
svc_validate(svc);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -888,9 +891,8 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
||||
return errno = ENOMEM;
|
||||
}
|
||||
|
||||
if (type == SVC_TYPE_SERVICE && manual) {
|
||||
if (type == SVC_TYPE_SERVICE && manual)
|
||||
svc_stop(svc);
|
||||
}
|
||||
}
|
||||
|
||||
/* Always clear svc PID file, for now. See TODO */
|
||||
|
||||
@@ -141,6 +141,37 @@ int svc_del(svc_t *svc)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* svc_validate - Check if service asserts same condition as another service
|
||||
* @svc: Pointer to an &svc_t object
|
||||
*
|
||||
* Logs to syslog if there is a name clash with existing services.
|
||||
*/
|
||||
void svc_validate(svc_t *svc)
|
||||
{
|
||||
char ident[MAX_IDENT_LEN];
|
||||
char cond[MAX_COND_LEN];
|
||||
svc_t *iter = NULL;
|
||||
svc_t *s;
|
||||
|
||||
mkcond(svc, cond, sizeof(cond));
|
||||
svc_ident(svc, ident, sizeof(ident));
|
||||
|
||||
for (s = svc_iterator(&iter, 1); s; s = svc_iterator(&iter, 0)) {
|
||||
char c[MAX_COND_LEN];
|
||||
|
||||
if (s == svc)
|
||||
continue;
|
||||
|
||||
mkcond(s, c, sizeof(c));
|
||||
if (!string_compare(cond, c))
|
||||
continue;
|
||||
|
||||
logit(LOG_WARNING, "%s (%s) asserts the same condition as %s (%s) => %s",
|
||||
svc->cmd, ident, s->cmd, svc_ident(s, NULL, 0), c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* svc_iterator - Naive iterator over all registered services.
|
||||
* @iter: Iterator, must be a valid pointer
|
||||
|
||||
Reference in New Issue
Block a user