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 | |||
@@ -8,15 +8,16 @@ There is NO WARRANTY, to the extent permitted by law. | |||
8 | 8 | ||
9 | struct genrc_pid_source { | 9 | struct genrc_pid_source { |
10 | char *name; | 10 | char *name; |
11 | size_t maxwords; | ||
11 | GENRC_PID_CLOSURE *(*init)(int argc, char **argv); | 12 | GENRC_PID_CLOSURE *(*init)(int argc, char **argv); |
12 | }; | 13 | }; |
13 | 14 | ||
14 | struct genrc_pid_source sourcetab[] = { | 15 | struct genrc_pid_source sourcetab[] = { |
15 | { "FILE", genrc_pid_file_init }, | 16 | { "FILE", 2, genrc_pid_file_init }, |
16 | { "CONFIG", genrc_pid_config_init }, | 17 | { "CONFIG", 4, genrc_pid_config_init }, |
17 | { "GREP", genrc_pid_grep_init }, | 18 | { "GREP", 3, genrc_pid_grep_init }, |
18 | { "PROC", genrc_pid_proc_init }, | 19 | { "PROC", 3, genrc_pid_proc_init }, |
19 | { "PS", genrc_pid_ps_init }, | 20 | { "PS", 3, genrc_pid_ps_init }, |
20 | { NULL } | 21 | { NULL } |
21 | }; | 22 | }; |
22 | 23 | ||
@@ -26,22 +27,34 @@ get_pid_closure(char const *str) | |||
26 | struct genrc_pid_source *s; | 27 | struct genrc_pid_source *s; |
27 | struct wordsplit ws; | 28 | struct wordsplit ws; |
28 | GENRC_PID_CLOSURE *pc; | 29 | GENRC_PID_CLOSURE *pc; |
30 | size_t len = strcspn(str, ":"); | ||
31 | int wsflags; | ||
29 | 32 | ||
30 | ws.ws_error = genrc_error; | 33 | if (len == 0) |
31 | ws.ws_delim = ":"; | ||
32 | if (wordsplit(str, &ws, | ||
33 | WRDSF_NOCMD|WRDSF_NOVAR|WRDSF_QUOTE| | ||
34 | WRDSF_DELIM|WRDSF_ENOMEMABRT|WRDSF_SHOWERR|WRDSF_ERROR)) | ||
35 | exit(1); | ||
36 | |||
37 | if (ws.ws_wordc == 0) | ||
38 | usage_error("GENRC_PID_FROM argument is empty"); | 34 | usage_error("GENRC_PID_FROM argument is empty"); |
39 | for (s = sourcetab; ; s++) { | 35 | for (s = sourcetab; ; s++) { |
40 | if (!s->name) | 36 | if (!s->name) |
41 | usage_error("%s: unsupported PID source", str); | 37 | usage_error("%s: unsupported PID source", str); |
42 | if (strcmp(s->name, ws.ws_wordv[0]) == 0) | 38 | if (strlen(s->name) == len && memcmp(s->name, str, len) == 0) |
43 | break; | 39 | break; |
44 | } | 40 | } |
41 | |||
42 | ws.ws_error = genrc_error; | ||
43 | ws.ws_delim = ":"; | ||
44 | wsflags = WRDSF_NOCMD | ||
45 | | WRDSF_NOVAR | ||
46 | | WRDSF_QUOTE | ||
47 | | WRDSF_DELIM | ||
48 | | WRDSF_ENOMEMABRT | ||
49 | | WRDSF_SHOWERR | ||
50 | | WRDSF_ERROR; | ||
51 | if (s->maxwords) { | ||
52 | ws.ws_maxwords = s->maxwords; | ||
53 | ws.ws_options = WRDSO_MAXWORDS; | ||
54 | wsflags |= WRDSF_OPTIONS; | ||
55 | } | ||
56 | if (wordsplit(str, &ws, wsflags)) | ||
57 | exit(1); | ||
45 | pc = s->init(ws.ws_wordc, ws.ws_wordv); | 58 | pc = s->init(ws.ws_wordc, ws.ws_wordv); |
46 | if (!pc) | 59 | if (!pc) |
47 | exit(1); | 60 | exit(1); |
diff --git a/src/sentinel.c b/src/sentinel.c index 33d3e06..4f269b8 100644 --- a/src/sentinel.c +++ b/src/sentinel.c | |||
@@ -200,7 +200,7 @@ wait_loop(pid_t child, int out, int err) | |||
200 | genrc_program, WSTOPSIG(status)); | 200 | genrc_program, WSTOPSIG(status)); |
201 | } else { | 201 | } else { |
202 | syslog(LOG_INFO, "%s terminated; status %d", | 202 | syslog(LOG_INFO, "%s terminated; status %d", |
203 | genrc_program, rc); | 203 | genrc_program, status); |
204 | } | 204 | } |
205 | break; | 205 | break; |
206 | } | 206 | } |