aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-05-22 15:14:55 +0300
committerSergey Poznyakoff <gray@gnu.org>2018-05-22 15:14:55 +0300
commita208e623da5bb38078bc514d5dfef640f8b02c4e (patch)
tree86d8979a9757da3e490b837890fb7619ea59065d /src
parent4026d0df3587843f78891dc2492620165b078acd (diff)
downloadgenrc-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.
Diffstat (limited to 'src')
-rw-r--r--src/pidfrom.c41
-rw-r--r--src/sentinel.c2
2 files changed, 28 insertions, 15 deletions
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.
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 }
};
@@ -26,22 +27,34 @@ 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);
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)
genrc_program, WSTOPSIG(status));
} else {
syslog(LOG_INFO, "%s terminated; status %d",
- genrc_program, rc);
+ genrc_program, status);
}
break;
}

Return to:

Send suggestions and report system problems to the System administrator.