mirror of
https://github.com/troglobit/finit.git
synced 2026-10-16 10:39:35 +00:00
api.c: Factor out SVC|JOB:ID string parser
This patch breaks out the JOB:ID parser from api.c, placing it in a new function called svc_parse_jobstr(). Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
1999956d91
commit
47b4850aa8
3 files changed
+75
-44
No files matched your search
@@ -45,50 +45,7 @@ uev_t api_watcher;
|
||||
|
||||
static int call(int (*action)(svc_t *), char *buf, size_t len)
|
||||
{
|
||||
int result = 0;
|
||||
char *input, *token, *pos;
|
||||
|
||||
input = sanitize(buf, len);
|
||||
if (!input)
|
||||
return -1;
|
||||
|
||||
token = strtok_r(input, " ", &pos);
|
||||
while (token) {
|
||||
svc_t *svc;
|
||||
char *ptr = strchr(token, ':');
|
||||
|
||||
if (isdigit(token[0])) {
|
||||
int job = atonum(token);
|
||||
|
||||
if (!ptr) {
|
||||
svc = svc_job_iterator(1, job);
|
||||
while (svc) {
|
||||
result += action(svc);
|
||||
svc = svc_job_iterator(0, job);
|
||||
}
|
||||
} else {
|
||||
*ptr++ = 0;
|
||||
job = atonum(token);
|
||||
result += action(svc_find_by_jobid(job, atonum(ptr)));
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!ptr) {
|
||||
svc = svc_named_iterator(1, token);
|
||||
while (svc) {
|
||||
result += action(svc);
|
||||
svc = svc_named_iterator(0, token);
|
||||
}
|
||||
} else {
|
||||
*ptr++ = 0;
|
||||
result += action(svc_find_by_nameid(token, atonum(ptr)));
|
||||
}
|
||||
}
|
||||
|
||||
token = strtok_r(NULL, " ", &pos);
|
||||
}
|
||||
|
||||
return result;
|
||||
return svc_parse_jobstr(buf, len, action, NULL);
|
||||
}
|
||||
|
||||
static int service_block(svc_t *svc)
|
||||
|
||||
Reference in new issue
Block a user