diff options
author | Tollef Fog Heen <tfheen@err.no> | 2009-07-10 14:09:48 +0200 |
---|---|---|
committer | Tollef Fog Heen <tfheen@err.no> | 2009-07-10 14:09:48 +0200 |
commit | 4c46b498f7c42a037f4f00e54f8a6a0197a80c93 (patch) | |
tree | 773f0c7ead8d1f27233aa1bae7066fe7815695b7 | |
parent | 4154bdcaadc1fb1ad2e7cd0f8f887dac5346a0d7 (diff) | |
download | moreutils-4c46b498f7c42a037f4f00e54f8a6a0197a80c93.tar.gz |
parallel: Argument validation
Make sure the arguments passed to -j and -l are numbers and error out
if they are not.
-rw-r--r-- | parallel.c | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -27,6 +27,7 @@ #include <sys/time.h> #include <time.h> #include <stdlib.h> +#include <errno.h> #include <sys/select.h> #include <sys/types.h> #include <sys/wait.h> @@ -91,6 +92,7 @@ int main(int argc, char **argv) int cidx = 0; int returncode = 0; int replace_cb = 0; + char *t; while ((opt = getopt(argc, argv, "+hij:l:")) != -1) { switch (opt) { @@ -101,10 +103,22 @@ int main(int argc, char **argv) replace_cb = 1; break; case 'j': - maxjobs = atoi(optarg); + errno = 0; + maxjobs = strtoul(optarg, &t, 0); + if (errno != 0 || (t-optarg) != strlen(optarg)) { + fprintf(stderr, "option '%s' is not a number\n", + optarg); + exit(2); + } break; case 'l': - maxload = atoi(optarg); + errno = 0; + maxload = strtoul(optarg, &t, 0); + if (errno != 0 || (t-optarg) != strlen(optarg)) { + fprintf(stderr, "option '%s' is not a number\n", + optarg); + exit(2); + } break; default: /* ’?’ */ usage(); |