From 0c1b36c0ab346aeffe98f144df089f493b1d2ec1 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Tue, 27 Feb 2007 14:54:52 +0000 Subject: [PATCH] New -v option requests verbose commentary. --- bin/setrlimit.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/bin/setrlimit.c b/bin/setrlimit.c index 17c579d..5a12aae 100644 --- a/bin/setrlimit.c +++ b/bin/setrlimit.c @@ -1,4 +1,4 @@ -/* $Id: setrlimit.c,v 1.1 2007-02-27 14:52:55 mike Exp $ */ +/* $Id: setrlimit.c,v 1.2 2007-02-27 14:54:52 mike Exp $ */ /* * A simple wrapper program for the setrlimit(2) system call, which @@ -28,17 +28,20 @@ #include int main(int argc, char **argv) { + int verbose = 0; int n = 0; char *user = 0; int c; - while ((c = getopt(argc, argv, "n:u:")) != -1) { + while ((c = getopt(argc, argv, "vn:u:")) != -1) { switch (c) { + case 'v': verbose++; break; case 'n': n = atoi(optarg); break; case 'u': user = optarg; break; default: USAGE: fprintf(stderr, "Usage: %s [options] \n\ + -v Verbose mode\n\ -n Set maximum open files to \n\ -u Run subcommand as \n", argv[0]); @@ -56,14 +59,14 @@ int main(int argc, char **argv) { 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 (verbose) { + 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); + } if (setrlimit(RLIMIT_NOFILE, &new) < 0) { fprintf(stderr, "%s: setrlimit(n=%d): %s\n", argv[0], n, strerror(errno)); @@ -85,10 +88,10 @@ int main(int argc, char **argv) { } } -#if 0 - printf("%s: n=%d, user='%s', optind=%d, new argc=%d, new argv[0]='%s'\n", - argv[0], n, user, optind, argc-optind, argv[optind]); -#endif + if (verbose) + printf("%s: n=%d, user='%s', optind=%d, new argc=%d, argv[0]='%s'\n", + argv[0], n, user, optind, argc-optind, argv[optind]); + execvp(argv[optind], argv+optind); fprintf(stderr, "%s: execvp('%s'): %s\n", argv[0], argv[optind], strerror(errno)); -- 1.7.10.4