- if (n != 0) {
- struct rlimit old, new;
- getrlimit(RLIMIT_NOFILE, &old);
- new = old;
- new.rlim_cur = n;
- if (n > new.rlim_max)
- new.rlim_max = n;
-#if 0
- if (new.rlim_cur != old.rlim_cur)
- printf("%s: changing soft NOFILE from %ld to %ld\n",
- argv[0], (long) old.rlim_cur, (long) new.rlim_cur);
- if (new.rlim_max != old.rlim_max)
- printf("%s: changing soft NOFILE from %ld to %ld\n",
- argv[0], (long) old.rlim_max, (long) new.rlim_max);
-#endif
- if (setrlimit(RLIMIT_NOFILE, &new) < 0) {
- fprintf(stderr, "%s: setrlimit(n=%d): %s\n",
- argv[0], n, strerror(errno));
- exit(2);
+ for (c = 'a'; c <= 'z'; c++) {
+ long n = values[c - 'a'];
+ if (n != 0) {
+ int i, ntypes = sizeof types/sizeof *types;
+ struct rlimit old, new;
+
+ for (i = 0; i < ntypes; i++) {
+ if (types[i].c == c)
+ break;
+ }
+
+ if (i == ntypes) {
+ fprintf(stderr, "%s: no such type '%c'\n", argv[0], c);
+ exit(2);
+ }
+
+ n *= types[i].multiplier;
+ getrlimit(types[i].value, &old);
+ new = old;
+ new.rlim_cur = n;
+ if (n > new.rlim_max)
+ new.rlim_max = n;
+ if (verbose) {
+ if (new.rlim_cur != old.rlim_cur)
+ fprintf(stderr, "%s: changing soft %s from %ld to %ld\n",
+ argv[0], types[i].name,
+ (long) old.rlim_cur, (long) new.rlim_cur);
+ if (new.rlim_max != old.rlim_max)
+ fprintf(stderr, "%s: changing hard %s from %ld to %ld\n",
+ argv[0], types[i].name,
+ (long) old.rlim_max, (long) new.rlim_max);
+ }
+ if (setrlimit(types[i].value, &new) < 0) {
+ fprintf(stderr, "%s: setrlimit(%s=%ld): %s\n",
+ argv[0], types[i].name, n, strerror(errno));
+ exit(3);
+ }