mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-08 08:07:10 +02:00
MINOR: init: emit warning when -sf/-sd cannot parse argument
Previously, -sf and -sd command line parsing used atol which cannot detect errors. I had a problem where I was doing -sf "$pid1 $pid2 $pid" and it was sending the gracefully terminate signal only to the first pid. The change uses strtol and checks endptr and errno to see if the parsing worked. It will exit when the pid list is not parsed. [wt: this should be backported to 1.8]
This commit is contained in:
parent
7d58b4d156
commit
236062f7ce
@ -1445,13 +1445,27 @@ static void init(int argc, char **argv)
|
|||||||
else
|
else
|
||||||
oldpids_sig = SIGTERM; /* terminate immediately */
|
oldpids_sig = SIGTERM; /* terminate immediately */
|
||||||
while (argc > 1 && argv[1][0] != '-') {
|
while (argc > 1 && argv[1][0] != '-') {
|
||||||
|
char * endptr = NULL;
|
||||||
oldpids = realloc(oldpids, (nb_oldpids + 1) * sizeof(int));
|
oldpids = realloc(oldpids, (nb_oldpids + 1) * sizeof(int));
|
||||||
if (!oldpids) {
|
if (!oldpids) {
|
||||||
ha_alert("Cannot allocate old pid : out of memory.\n");
|
ha_alert("Cannot allocate old pid : out of memory.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
argc--; argv++;
|
argc--; argv++;
|
||||||
oldpids[nb_oldpids] = atol(*argv);
|
errno = 0;
|
||||||
|
oldpids[nb_oldpids] = strtol(*argv, &endptr, 10);
|
||||||
|
if (errno) {
|
||||||
|
ha_alert("-%2s option: failed to parse {%s}: %s\n",
|
||||||
|
flag,
|
||||||
|
*argv, strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
} else if (endptr && strlen(endptr)) {
|
||||||
|
while (isspace(*endptr)) endptr++;
|
||||||
|
if (*endptr != 0)
|
||||||
|
ha_alert("-%2s option: some bytes unconsumed in PID list {%s}\n",
|
||||||
|
flag, endptr);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
if (oldpids[nb_oldpids] <= 0)
|
if (oldpids[nb_oldpids] <= 0)
|
||||||
usage(progname);
|
usage(progname);
|
||||||
nb_oldpids++;
|
nb_oldpids++;
|
||||||
|
Loading…
Reference in New Issue
Block a user