aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2007-09-25 23:17:25 +0000
committerMike Frysinger <vapier@gentoo.org>2007-09-25 23:17:25 +0000
commitab0edd43b9c6df2946e8a514b12e04db23f13c65 (patch)
tree8a8d9658c9d0671fb55df28f9f00f323473b8417
parent7d9acd968f7a0537b258f23edaca2c85a0774b47 (diff)
unify verbose/quiet handling
-rw-r--r--src/_usage.h17
-rw-r--r--src/mountinfo.c2
-rw-r--r--src/rc-update.c11
-rw-r--r--src/runscript.c26
-rw-r--r--src/start-stop-daemon.c11
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,13 +972,11 @@ 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}
};
@@ -986,10 +984,12 @@ 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 <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 */