mirror of
https://github.com/troglobit/finit.git
synced 2026-10-31 13:00:32 +00:00
Refactor service name: parser slightly
This change makes it possible to see the new service's resulting name and id before we create it with svc_new(). We extend the debug output slightly to see what's going on and why we sometimes lose modules from the modules-load plugin ... Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
30e68658ae
commit
7e37ac348e
1 file changed
+21
-8
+21
-8
@@ -1026,20 +1026,33 @@ static void parse_script(char *type, char *script, char *buf, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* name:<name>
|
* 'name:<name>' or derived from '/path/to/cmd args'
|
||||||
*/
|
*/
|
||||||
static void parse_name(svc_t *svc, char *arg)
|
static char *parse_name(char *cmd, char *arg)
|
||||||
{
|
{
|
||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
|
|
||||||
if (arg && !strncasecmp(arg, "name:", 5)) {
|
if (arg && !strncasecmp(arg, "name:", 5)) {
|
||||||
name = arg + 5;
|
name = arg + 5;
|
||||||
} else {
|
} else {
|
||||||
name = strrchr(svc->cmd, '/');
|
char *ptr;
|
||||||
name = name ? name + 1 : svc->cmd;
|
|
||||||
|
ptr = strchr(cmd, ' ');
|
||||||
|
if (!ptr)
|
||||||
|
ptr = cmd + strlen(cmd);
|
||||||
|
|
||||||
|
while (ptr > cmd) {
|
||||||
|
if (*ptr == '/') {
|
||||||
|
ptr++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ptr--;
|
||||||
|
}
|
||||||
|
|
||||||
|
name = ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
strlcpy(svc->name, name, sizeof(svc->name));
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1297,6 +1310,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
name = parse_name(cmd, name);
|
||||||
if (!id)
|
if (!id)
|
||||||
id = "";
|
id = "";
|
||||||
|
|
||||||
@@ -1341,7 +1355,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
svc = svc_find(cmd, id);
|
svc = svc_find(cmd, id);
|
||||||
|
|
||||||
if (!svc) {
|
if (!svc) {
|
||||||
_d("Creating new svc for %s id #%s type %d", cmd, id, type);
|
_d("Creating new svc for %s name %s id %s type %d", cmd, name, id, type);
|
||||||
svc = svc_new(cmd, id, type);
|
svc = svc_new(cmd, id, type);
|
||||||
if (!svc) {
|
if (!svc) {
|
||||||
_e("Out of memory, cannot register service %s", cmd);
|
_e("Out of memory, cannot register service %s", cmd);
|
||||||
@@ -1413,8 +1427,7 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
|
|||||||
id = ptr;
|
id = ptr;
|
||||||
strlcpy(svc->name, "tty", sizeof(svc->name));
|
strlcpy(svc->name, "tty", sizeof(svc->name));
|
||||||
strlcpy(svc->id, id, sizeof(svc->id));
|
strlcpy(svc->id, id, sizeof(svc->id));
|
||||||
} else
|
}
|
||||||
parse_name(svc, name);
|
|
||||||
|
|
||||||
parse_cmdline_args(svc, cmd);
|
parse_cmdline_args(svc, cmd);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user