From 4154bdcaadc1fb1ad2e7cd0f8f887dac5346a0d7 Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Fri, 10 Jul 2009 13:54:21 +0200 Subject: parallel: Assume -j 1 if no -j or -l is given --- parallel.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'parallel.c') diff --git a/parallel.c b/parallel.c index 438bc93..597cda2 100644 --- a/parallel.c +++ b/parallel.c @@ -113,7 +113,8 @@ int main(int argc, char **argv) } if (maxjobs < 0 && maxload < 0) { - usage(); + maxjobs = 1; /* XXX: Maybe we should try to autodetect + number of CPUs? */ } while (optind < argc) { -- cgit v1.2.3 From 4c46b498f7c42a037f4f00e54f8a6a0197a80c93 Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Fri, 10 Jul 2009 14:09:48 +0200 Subject: parallel: Argument validation Make sure the arguments passed to -j and -l are numbers and error out if they are not. --- parallel.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'parallel.c') diff --git a/parallel.c b/parallel.c index 597cda2..418dc34 100644 --- a/parallel.c +++ b/parallel.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -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(); -- cgit v1.2.3 From 2a323e50cf8b4b75b9cf1e258908819e6f59daa6 Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Fri, 10 Jul 2009 14:11:17 +0200 Subject: Fix indentation --- parallel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'parallel.c') diff --git a/parallel.c b/parallel.c index 418dc34..5b05af6 100644 --- a/parallel.c +++ b/parallel.c @@ -127,8 +127,8 @@ int main(int argc, char **argv) } if (maxjobs < 0 && maxload < 0) { - maxjobs = 1; /* XXX: Maybe we should try to autodetect - number of CPUs? */ + maxjobs = 1; /* XXX: Maybe we should try to autodetect + number of CPUs? */ } while (optind < argc) { -- cgit v1.2.3