From ab0edd43b9c6df2946e8a514b12e04db23f13c65 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 25 Sep 2007 23:17:25 +0000 Subject: unify verbose/quiet handling --- src/_usage.h | 17 +++++++++++++---- src/mountinfo.c | 2 +- src/rc-update.c | 11 ++++------- src/runscript.c | 26 ++++++-------------------- src/start-stop-daemon.c | 11 +++-------- 5 files changed, 27 insertions(+), 40 deletions(-) diff --git a/src/_usage.h b/src/_usage.h index 83b4f999..cff60df5 100644 --- a/src/_usage.h +++ b/src/_usage.h @@ -12,15 +12,24 @@ #define longopts_COMMON \ { "help", 0, NULL, 'h'}, \ { "nocolor", 0, NULL, 'C'}, \ + { "verbose", 0, NULL, 'v'}, \ { "quiet", 0, NULL, 'q'}, #define longopts_help_COMMON \ "Display this help output (duh)", \ "Disable color output", \ + "Run verbosely", \ "Run quietly" +#define case_RC_COMMON_getopt_case_C setenv ("RC_NOCOLOR", "yes", 1); +#define case_RC_COMMON_getopt_case_h usage (EXIT_SUCCESS); +#define case_RC_COMMON_getopt_case_v setenv ("RC_VERBOSE", "yes", 1); +#define case_RC_COMMON_getopt_case_q setenv ("RC_QUIET", "yes", 1); +#define case_RC_COMMON_getopt_default usage (EXIT_FAILURE); + #define case_RC_COMMON_GETOPT \ - case 'C': setenv ("RC_NOCOLOR", "yes", 1); break; \ - case 'h': usage (EXIT_SUCCESS); \ - case 'q': setenv ("RC_QUIET", "yes", 1); break; \ - default: usage (EXIT_FAILURE); + case 'C': case_RC_COMMON_getopt_case_C; break; \ + case 'h': case_RC_COMMON_getopt_case_h; break; \ + case 'v': case_RC_COMMON_getopt_case_v; break; \ + case 'q': case_RC_COMMON_getopt_case_q; break; \ + default: case_RC_COMMON_getopt_default; break; diff --git a/src/mountinfo.c b/src/mountinfo.c index fbc9da88..b57e7d55 100644 --- a/src/mountinfo.c +++ b/src/mountinfo.c @@ -247,7 +247,7 @@ static regex_t *get_regex (const char *string) #include "_usage.h" #define extraopts "[mount1] [mount2] ..." -#define getoptstring "f:F:n:N:o:O:p:P:iqst" getoptstring_COMMON +#define getoptstring "f:F:n:N:o:O:p:P:ist" getoptstring_COMMON static struct option longopts[] = { { "fstype-regex", 1, NULL, 'f'}, { "skip-fstype-regex", 1, NULL, 'F'}, diff --git a/src/rc-update.c b/src/rc-update.c index e0dc0867..b6c992f6 100644 --- a/src/rc-update.c +++ b/src/rc-update.c @@ -110,12 +110,11 @@ static void show (char **runlevels, bool verbose) } #include "_usage.h" -#define getoptstring "adsv" getoptstring_COMMON +#define getoptstring "ads" getoptstring_COMMON static struct option longopts[] = { { "add", 0, NULL, 'a'}, { "delete", 0, NULL, 'd'}, { "show", 0, NULL, 's'}, - { "verbose", 0, NULL, 'v'}, longopts_COMMON { NULL, 0, NULL, 0} }; @@ -123,7 +122,6 @@ static const char * const longopts_help[] = { "Add the init.d to runlevels", "Delete init.d from runlevels", "Show init.d's in runlevels", - "Be verbose!", longopts_help_COMMON }; #include "_usage.c" @@ -158,14 +156,13 @@ int rc_update (int argc, char **argv) case 's': action |= DOSHOW; break; - case 'v': - verbose = true; - break; - case_RC_COMMON_GETOPT + case_RC_COMMON_GETOPT } } + verbose = rc_is_env ("RC_VERBOSE", "yes"); + if ((action & DOSHOW && action != DOSHOW) || (action & DOADD && action != DOADD) || (action & DODELETE && action != DODELETE)) diff --git a/src/runscript.c b/src/runscript.c index 4bbc0dab..0d839b3f 100644 --- a/src/runscript.c +++ b/src/runscript.c @@ -972,24 +972,24 @@ static void svc_restart (bool deps) } #include "_usage.h" -#define getoptstring "dDqsv" getoptstring_COMMON +#define getoptstring "dDsv" getoptstring_COMMON static struct option longopts[] = { { "debug", 0, NULL, 'd'}, { "ifstarted", 0, NULL, 's'}, { "nodeps", 0, NULL, 'D'}, - { "quiet", 0, NULL, 'q'}, - { "verbose", 0, NULL, 'v'}, longopts_COMMON { NULL, 0, NULL, 0} }; static const char * const longopts_help[] = { - "", - "", "", "", "", longopts_help_COMMON }; +#undef case_RC_COMMON_getopt_case_h +#define case_RC_COMMON_getopt_case_h \ + execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, (char *) NULL); \ + eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s", applet, strerror (errno)); #include "_usage.c" int runscript (int argc, char **argv) @@ -1125,28 +1125,14 @@ int runscript (int argc, char **argv) case 'd': setenv ("RC_DEBUG", "yes", 1); break; - case 'h': - execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, (char *) NULL); - eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s", - applet, strerror (errno)); case 's': if (! rc_service_state (service, rc_service_started)) exit (EXIT_FAILURE); break; - case 'C': - setenv ("RC_NOCOLOR", "yes", 1); - break; case 'D': deps = false; break; - case 'q': - setenv ("RC_QUIET", "yes", 1); - break; - case 'v': - setenv ("RC_VERBOSE", "yes", 1); - break; - default: - usage (EXIT_FAILURE); + case_RC_COMMON_GETOPT } /* Save the IN_BACKGROUND env flag so it's ONLY passed to the service diff --git a/src/start-stop-daemon.c b/src/start-stop-daemon.c index 1b4c7f28..20d2cec8 100644 --- a/src/start-stop-daemon.c +++ b/src/start-stop-daemon.c @@ -461,7 +461,7 @@ static void handle_signal (int sig) #include "_usage.h" -#define getoptstring "KN:R:Sbc:d:g:mn:op:s:tu:r:vx:1:2:" getoptstring_COMMON +#define getoptstring "KN:R:Sbc:d:g:mn:op:s:tu:r:x:1:2:" getoptstring_COMMON static struct option longopts[] = { { "stop", 0, NULL, 'K'}, { "nicelevel", 1, NULL, 'N'}, @@ -480,7 +480,6 @@ static struct option longopts[] = { { "test", 0, NULL, 't'}, { "user", 1, NULL, 'u'}, { "chroot", 1, NULL, 'r'}, - { "verbose", 0, NULL, 'v'}, { "exec", 1, NULL, 'x'}, { "stdout", 1, NULL, '1'}, { "stderr", 1, NULL, '2'}, @@ -508,7 +507,6 @@ static const char * const longopts_help[] = { "", "", "", - "", longopts_help_COMMON }; #include "_usage.c" @@ -670,10 +668,6 @@ int start_stop_daemon (int argc, char **argv) ch_root = optarg; break; - case 'v': /* --verbose */ - verbose = true; - break; - case 'a': case 'x': /* --exec */ exec = optarg; @@ -687,10 +681,11 @@ int start_stop_daemon (int argc, char **argv) redirect_stderr = optarg; break; - case_RC_COMMON_GETOPT + case_RC_COMMON_GETOPT } quiet = rc_is_env ("RC_QUIET", "yes"); + verbose = rc_is_env ("RC_VERBOSE", "yes"); /* Allow start-stop-daemon --signal HUP --exec /usr/sbin/dnsmasq * instead of forcing --stop --oknodo as well */ -- cgit v1.2.3