unify verbose/quiet handling

This commit is contained in:
Mike Frysinger 2007-09-25 23:17:25 +00:00
parent 7d9acd968f
commit ab0edd43b9
5 changed files with 27 additions and 40 deletions

View File

@ -12,15 +12,24 @@
#define longopts_COMMON \ #define longopts_COMMON \
{ "help", 0, NULL, 'h'}, \ { "help", 0, NULL, 'h'}, \
{ "nocolor", 0, NULL, 'C'}, \ { "nocolor", 0, NULL, 'C'}, \
{ "verbose", 0, NULL, 'v'}, \
{ "quiet", 0, NULL, 'q'}, { "quiet", 0, NULL, 'q'},
#define longopts_help_COMMON \ #define longopts_help_COMMON \
"Display this help output (duh)", \ "Display this help output (duh)", \
"Disable color output", \ "Disable color output", \
"Run verbosely", \
"Run quietly" "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 \ #define case_RC_COMMON_GETOPT \
case 'C': setenv ("RC_NOCOLOR", "yes", 1); break; \ case 'C': case_RC_COMMON_getopt_case_C; break; \
case 'h': usage (EXIT_SUCCESS); \ case 'h': case_RC_COMMON_getopt_case_h; break; \
case 'q': setenv ("RC_QUIET", "yes", 1); break; \ case 'v': case_RC_COMMON_getopt_case_v; break; \
default: usage (EXIT_FAILURE); case 'q': case_RC_COMMON_getopt_case_q; break; \
default: case_RC_COMMON_getopt_default; break;

View File

@ -247,7 +247,7 @@ static regex_t *get_regex (const char *string)
#include "_usage.h" #include "_usage.h"
#define extraopts "[mount1] [mount2] ..." #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[] = { static struct option longopts[] = {
{ "fstype-regex", 1, NULL, 'f'}, { "fstype-regex", 1, NULL, 'f'},
{ "skip-fstype-regex", 1, NULL, 'F'}, { "skip-fstype-regex", 1, NULL, 'F'},

View File

@ -110,12 +110,11 @@ static void show (char **runlevels, bool verbose)
} }
#include "_usage.h" #include "_usage.h"
#define getoptstring "adsv" getoptstring_COMMON #define getoptstring "ads" getoptstring_COMMON
static struct option longopts[] = { static struct option longopts[] = {
{ "add", 0, NULL, 'a'}, { "add", 0, NULL, 'a'},
{ "delete", 0, NULL, 'd'}, { "delete", 0, NULL, 'd'},
{ "show", 0, NULL, 's'}, { "show", 0, NULL, 's'},
{ "verbose", 0, NULL, 'v'},
longopts_COMMON longopts_COMMON
{ NULL, 0, NULL, 0} { NULL, 0, NULL, 0}
}; };
@ -123,7 +122,6 @@ static const char * const longopts_help[] = {
"Add the init.d to runlevels", "Add the init.d to runlevels",
"Delete init.d from runlevels", "Delete init.d from runlevels",
"Show init.d's in runlevels", "Show init.d's in runlevels",
"Be verbose!",
longopts_help_COMMON longopts_help_COMMON
}; };
#include "_usage.c" #include "_usage.c"
@ -158,14 +156,13 @@ int rc_update (int argc, char **argv)
case 's': case 's':
action |= DOSHOW; action |= DOSHOW;
break; 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) || if ((action & DOSHOW && action != DOSHOW) ||
(action & DOADD && action != DOADD) || (action & DOADD && action != DOADD) ||
(action & DODELETE && action != DODELETE)) (action & DODELETE && action != DODELETE))

View File

@ -972,24 +972,24 @@ static void svc_restart (bool deps)
} }
#include "_usage.h" #include "_usage.h"
#define getoptstring "dDqsv" getoptstring_COMMON #define getoptstring "dDsv" getoptstring_COMMON
static struct option longopts[] = { static struct option longopts[] = {
{ "debug", 0, NULL, 'd'}, { "debug", 0, NULL, 'd'},
{ "ifstarted", 0, NULL, 's'}, { "ifstarted", 0, NULL, 's'},
{ "nodeps", 0, NULL, 'D'}, { "nodeps", 0, NULL, 'D'},
{ "quiet", 0, NULL, 'q'},
{ "verbose", 0, NULL, 'v'},
longopts_COMMON longopts_COMMON
{ NULL, 0, NULL, 0} { NULL, 0, NULL, 0}
}; };
static const char * const longopts_help[] = { static const char * const longopts_help[] = {
"",
"",
"", "",
"", "",
"", "",
longopts_help_COMMON 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" #include "_usage.c"
int runscript (int argc, char **argv) int runscript (int argc, char **argv)
@ -1125,28 +1125,14 @@ int runscript (int argc, char **argv)
case 'd': case 'd':
setenv ("RC_DEBUG", "yes", 1); setenv ("RC_DEBUG", "yes", 1);
break; break;
case 'h':
execl (RCSCRIPT_HELP, RCSCRIPT_HELP, service, (char *) NULL);
eerrorx ("%s: failed to exec `" RCSCRIPT_HELP "': %s",
applet, strerror (errno));
case 's': case 's':
if (! rc_service_state (service, rc_service_started)) if (! rc_service_state (service, rc_service_started))
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
break; break;
case 'C':
setenv ("RC_NOCOLOR", "yes", 1);
break;
case 'D': case 'D':
deps = false; deps = false;
break; break;
case 'q': case_RC_COMMON_GETOPT
setenv ("RC_QUIET", "yes", 1);
break;
case 'v':
setenv ("RC_VERBOSE", "yes", 1);
break;
default:
usage (EXIT_FAILURE);
} }
/* Save the IN_BACKGROUND env flag so it's ONLY passed to the service /* Save the IN_BACKGROUND env flag so it's ONLY passed to the service

View File

@ -461,7 +461,7 @@ static void handle_signal (int sig)
#include "_usage.h" #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[] = { static struct option longopts[] = {
{ "stop", 0, NULL, 'K'}, { "stop", 0, NULL, 'K'},
{ "nicelevel", 1, NULL, 'N'}, { "nicelevel", 1, NULL, 'N'},
@ -480,7 +480,6 @@ static struct option longopts[] = {
{ "test", 0, NULL, 't'}, { "test", 0, NULL, 't'},
{ "user", 1, NULL, 'u'}, { "user", 1, NULL, 'u'},
{ "chroot", 1, NULL, 'r'}, { "chroot", 1, NULL, 'r'},
{ "verbose", 0, NULL, 'v'},
{ "exec", 1, NULL, 'x'}, { "exec", 1, NULL, 'x'},
{ "stdout", 1, NULL, '1'}, { "stdout", 1, NULL, '1'},
{ "stderr", 1, NULL, '2'}, { "stderr", 1, NULL, '2'},
@ -508,7 +507,6 @@ static const char * const longopts_help[] = {
"", "",
"", "",
"", "",
"",
longopts_help_COMMON longopts_help_COMMON
}; };
#include "_usage.c" #include "_usage.c"
@ -670,10 +668,6 @@ int start_stop_daemon (int argc, char **argv)
ch_root = optarg; ch_root = optarg;
break; break;
case 'v': /* --verbose */
verbose = true;
break;
case 'a': case 'a':
case 'x': /* --exec <executable> */ case 'x': /* --exec <executable> */
exec = optarg; exec = optarg;
@ -691,6 +685,7 @@ int start_stop_daemon (int argc, char **argv)
} }
quiet = rc_is_env ("RC_QUIET", "yes"); quiet = rc_is_env ("RC_QUIET", "yes");
verbose = rc_is_env ("RC_VERBOSE", "yes");
/* Allow start-stop-daemon --signal HUP --exec /usr/sbin/dnsmasq /* Allow start-stop-daemon --signal HUP --exec /usr/sbin/dnsmasq
* instead of forcing --stop --oknodo as well */ * instead of forcing --stop --oknodo as well */