diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2018-05-22 15:14:55 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2018-05-22 15:14:55 +0300 |
commit | a208e623da5bb38078bc514d5dfef640f8b02c4e (patch) | |
tree | 86d8979a9757da3e490b837890fb7619ea59065d | |
parent | 4026d0df3587843f78891dc2492620165b078acd (diff) | |
download | genrc-a208e623da5bb38078bc514d5dfef640f8b02c4e.tar.gz genrc-a208e623da5bb38078bc514d5dfef640f8b02c4e.tar.bz2 |
Improve parsing of the --pid-from argument.
* grecs: Update to a531c7d1.
* src/pidfrom.c (get_pid_closure): Use the new WRDSO_FEATURE of
wordsplit to limit the number of expected words in the expansion.
* src/sentinel.c: Minor fix.
m--------- | grecs | 0 | ||||
-rw-r--r-- | src/pidfrom.c | 41 | ||||
-rw-r--r-- | src/sentinel.c | 2 |
3 files changed, 28 insertions, 15 deletions
diff --git a/grecs b/grecs -Subproject 27ca9f5819d0e44173a5f61a241cd066ad15713 +Subproject a531c7d1de4780ee53ffbd383329dfff55d425b diff --git a/src/pidfrom.c b/src/pidfrom.c index d1fa627..371e692 100644 --- a/src/pidfrom.c +++ b/src/pidfrom.c @@ -5,46 +5,59 @@ This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. */ #include "genrc.h" struct genrc_pid_source { char *name; + size_t maxwords; GENRC_PID_CLOSURE *(*init)(int argc, char **argv); }; struct genrc_pid_source sourcetab[] = { - { "FILE", genrc_pid_file_init }, - { "CONFIG", genrc_pid_config_init }, - { "GREP", genrc_pid_grep_init }, - { "PROC", genrc_pid_proc_init }, - { "PS", genrc_pid_ps_init }, + { "FILE", 2, genrc_pid_file_init }, + { "CONFIG", 4, genrc_pid_config_init }, + { "GREP", 3, genrc_pid_grep_init }, + { "PROC", 3, genrc_pid_proc_init }, + { "PS", 3, genrc_pid_ps_init }, { NULL } }; GENRC_PID_CLOSURE * get_pid_closure(char const *str) { struct genrc_pid_source *s; struct wordsplit ws; GENRC_PID_CLOSURE *pc; + size_t len = strcspn(str, ":"); + int wsflags; - ws.ws_error = genrc_error; - ws.ws_delim = ":"; - if (wordsplit(str, &ws, - WRDSF_NOCMD|WRDSF_NOVAR|WRDSF_QUOTE| - WRDSF_DELIM|WRDSF_ENOMEMABRT|WRDSF_SHOWERR|WRDSF_ERROR)) - exit(1); - - if (ws.ws_wordc == 0) + if (len == 0) usage_error("GENRC_PID_FROM argument is empty"); for (s = sourcetab; ; s++) { if (!s->name) usage_error("%s: unsupported PID source", str); - if (strcmp(s->name, ws.ws_wordv[0]) == 0) + if (strlen(s->name) == len && memcmp(s->name, str, len) == 0) break; } + + ws.ws_error = genrc_error; + ws.ws_delim = ":"; + wsflags = WRDSF_NOCMD + | WRDSF_NOVAR + | WRDSF_QUOTE + | WRDSF_DELIM + | WRDSF_ENOMEMABRT + | WRDSF_SHOWERR + | WRDSF_ERROR; + if (s->maxwords) { + ws.ws_maxwords = s->maxwords; + ws.ws_options = WRDSO_MAXWORDS; + wsflags |= WRDSF_OPTIONS; + } + if (wordsplit(str, &ws, wsflags)) + exit(1); pc = s->init(ws.ws_wordc, ws.ws_wordv); if (!pc) exit(1); pc->name = xstrdup(str); return pc; } diff --git a/src/sentinel.c b/src/sentinel.c index 33d3e06..4f269b8 100644 --- a/src/sentinel.c +++ b/src/sentinel.c @@ -197,13 +197,13 @@ wait_loop(pid_t child, int out, int err) return; } else if (WIFSTOPPED(status)) { syslog(LOG_INFO, "%s stopped on signal %d", genrc_program, WSTOPSIG(status)); } else { syslog(LOG_INFO, "%s terminated; status %d", - genrc_program, rc); + genrc_program, status); } break; } FD_ZERO(&rdset); FD_SET(out, &rdset); |