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 doesn't exit so as not to cause failures but will allow trouble-shooting to be faster. --- src/haproxy.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/src/haproxy.c b/src/haproxy.c index eb5e65b..3185a2e 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -1412,13 +1412,24 @@ static void init(int argc, char **argv) else oldpids_sig = SIGTERM; /* terminate immediately */ while (argc > 1 && argv[1][0] != '-') { + char * endptr = NULL; oldpids = realloc(oldpids, (nb_oldpids + 1) * sizeof(int)); if (!oldpids) { ha_alert("Cannot allocate old pid : out of memory.\n"); exit(1); } 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", + (char *)*argv, strerror(errno)); + } 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); + } if (oldpids[nb_oldpids] <= 0) usage(progname); nb_oldpids++; -- 2.1.1