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 \
{ "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;

View File

@ -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'},

View File

@ -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))

View File

@ -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

View File

@ -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 <executable> */
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 */