summaryrefslogtreecommitdiff
path: root/parallel.c
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2009-07-10 10:37:28 -0400
committerJoey Hess <joey@gnu.kitenet.net>2009-07-10 10:37:28 -0400
commit47e9ec293264fac1e1af989cd85bd1cbda71c39b (patch)
treecd58c262b292128d5def45036d7ad5e20d026a44 /parallel.c
parentac6ea9a555dc33d0f9978b92acbb5963e68f81ae (diff)
parent2a323e50cf8b4b75b9cf1e258908819e6f59daa6 (diff)
downloadmoreutils-47e9ec293264fac1e1af989cd85bd1cbda71c39b.tar.gz
Merge commit 'remotes/tollef/master'
Diffstat (limited to 'parallel.c')
-rw-r--r--parallel.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/parallel.c b/parallel.c
index 67b723d..0895c13 100644
--- a/parallel.c
+++ b/parallel.c
@@ -26,6 +26,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>
@@ -86,6 +87,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) {
@@ -96,10 +98,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();
@@ -108,7 +122,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) {