summaryrefslogtreecommitdiffstats
path: root/hwclock/hwclock.c
diff options
context:
space:
mode:
authorSami Kerola2012-06-14 20:58:12 +0200
committerSami Kerola2012-06-17 17:59:58 +0200
commite1f4706db820019aef0fa49424d92a5ca785f88c (patch)
tree4ce31a87391fa85562ad5659342674882fef9579 /hwclock/hwclock.c
parentpartx: use exclusive_option() (diff)
downloadkernel-qcow2-util-linux-e1f4706db820019aef0fa49424d92a5ca785f88c.tar.gz
kernel-qcow2-util-linux-e1f4706db820019aef0fa49424d92a5ca785f88c.tar.xz
kernel-qcow2-util-linux-e1f4706db820019aef0fa49424d92a5ca785f88c.zip
hwclock: use exclusive_option()
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'hwclock/hwclock.c')
-rw-r--r--hwclock/hwclock.c66
1 files changed, 41 insertions, 25 deletions
diff --git a/hwclock/hwclock.c b/hwclock/hwclock.c
index bf1b4beda..10ef8da42 100644
--- a/hwclock/hwclock.c
+++ b/hwclock/hwclock.c
@@ -70,13 +70,17 @@
#include <time.h>
#include <unistd.h>
+#define OPTUTILS_EXIT_CODE EX_USAGE
+
#include "c.h"
#include "clock.h"
#include "closestream.h"
#include "nls.h"
+#include "optutils.h"
#include "pathnames.h"
#include "strutils.h"
+#define EXCL_ERROR "--{adjust,getepoch,hctosys,predict,set,setepoch,show,systohc,systz}"
#ifdef HAVE_LIBAUDIT
#include <libaudit.h>
static int hwaudit_fd = -1;
@@ -1448,6 +1452,29 @@ int main(int argc, char **argv)
bool permitted; /* User is permitted to do the function */
int rc, c;
+ enum {
+ EXCL_NONE,
+
+ EXCL_ADJFILE,
+ EXCL_NO_AJDFILE,
+
+ EXCL_LOCALTIME,
+ EXCL_UTC,
+
+ EXCL_ADJUST,
+ EXCL_GETEPOCH,
+ EXCL_HCTOSYS,
+ EXCL_PREDICT,
+ EXCL_SET,
+ EXCL_SETEPOCH,
+ EXCL_SHOW,
+ EXCL_SYSTOHC,
+ EXCL_SYSTZ
+ };
+ int excl_adj = EXCL_NONE;
+ int excl_utc_local = EXCL_NONE;
+ int excl_action = EXCL_NONE;
+
/* Variables set by various options; show may also be set later */
/* The options debug, badyear and epoch_option are global */
bool show, set, systohc, hctosys, systz, adjust, getepoch, setepoch,
@@ -1542,18 +1569,23 @@ int main(int argc, char **argv)
break;
case 'a':
adjust = TRUE;
+ exclusive_option(&excl_action, EXCL_ADJUST, EXCL_ERROR);
break;
case 'r':
show = TRUE;
+ exclusive_option(&excl_action, EXCL_SHOW, EXCL_ERROR);
break;
case 's':
hctosys = TRUE;
+ exclusive_option(&excl_action, EXCL_HCTOSYS, EXCL_ERROR);
break;
case 'u':
utc = TRUE;
+ exclusive_option(&excl_utc_local, EXCL_UTC, "--{utc,localtime}");
break;
case 'w':
systohc = TRUE;
+ exclusive_option(&excl_action, EXCL_SYSTOHC, EXCL_ERROR);
break;
#ifdef __alpha__
case 'A':
@@ -1571,20 +1603,25 @@ int main(int argc, char **argv)
#endif
case OPT_SET:
set = TRUE;
+ exclusive_option(&excl_action, EXCL_SET, EXCL_ERROR);
break;
#ifdef __linux__
case OPT_GETEPOCH:
getepoch = TRUE;
+ exclusive_option(&excl_action, EXCL_GETEPOCH, EXCL_ERROR);
break;
case OPT_SETEPOCH:
setepoch = TRUE;
+ exclusive_option(&excl_action, EXCL_SETEPOCH, EXCL_ERROR);
break;
#endif
case OPT_NOADJFILE:
noadjfile = TRUE;
+ exclusive_option(&excl_adj, EXCL_NO_AJDFILE, "--{adjfile,noadjfile}");
break;
case OPT_LOCALTIME:
local_opt = TRUE; /* --localtime */
+ exclusive_option(&excl_utc_local, EXCL_LOCALTIME, "--{utc,localtime}");
break;
case OPT_BADYEAR:
badyear = TRUE;
@@ -1604,12 +1641,15 @@ int main(int argc, char **argv)
break;
case OPT_ADJFILE:
adj_file_name = optarg; /* --adjfile */
+ exclusive_option(&excl_adj, EXCL_ADJFILE, "--{adjfile,noadjfile}");
break;
case OPT_SYSTZ:
systz = TRUE; /* --systz */
+ exclusive_option(&excl_action, EXCL_SYSTZ, EXCL_ERROR);
break;
case OPT_PREDICT_HC:
predict = TRUE; /* --predict-hc */
+ exclusive_option(&excl_action, EXCL_PREDICT, EXCL_ERROR);
break;
#ifdef __linux__
case 'f':
@@ -1644,34 +1684,10 @@ int main(int argc, char **argv)
argc);
}
- if (show + set + systohc + hctosys + systz + adjust + getepoch
- + setepoch + predict > 1) {
- warnx(_("You have specified multiple functions.\n"
- "You can only perform one function at a time."));
- hwclock_exit(EX_USAGE);
- }
-
- if (utc && local_opt) {
- warnx(_("The --utc and --localtime options "
- "are mutually exclusive. You specified both."));
- hwclock_exit(EX_USAGE);
- }
-
- if (adjust && noadjfile) {
- warnx(_("The --adjust and --noadjfile options "
- "are mutually exclusive. You specified both."));
- hwclock_exit(EX_USAGE);
- }
-
- if (adj_file_name && noadjfile) {
- warnx(_("The --adjfile and --noadjfile options "
- "are mutually exclusive. You specified both."));
- hwclock_exit(EX_USAGE);
- }
if (!adj_file_name)
adj_file_name = _PATH_ADJPATH;
- if (noadjfile && !(utc || local_opt)) {
+ if (noadjfile && !excl_utc_local) {
warnx(_("With --noadjfile, you must specify "
"either --utc or --localtime"));
hwclock_exit(EX_USAGE);