summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sys-utils/hwclock.c49
-rw-r--r--sys-utils/hwclock.h14
2 files changed, 45 insertions, 18 deletions
diff --git a/sys-utils/hwclock.c b/sys-utils/hwclock.c
index 0dc1d2369..b83e71004 100644
--- a/sys-utils/hwclock.c
+++ b/sys-utils/hwclock.c
@@ -84,6 +84,9 @@
static int hwaudit_fd = -1;
#endif
+UL_DEBUG_DEFINE_MASK(hwclock);
+UL_DEBUG_DEFINE_MASKNAMES(hwclock) = UL_DEBUG_EMPTY_MASKNAMES;
+
/* The struct that holds our hardware access routines */
static struct clock_ops *ur;
@@ -120,6 +123,23 @@ struct adjtime {
*/
};
+static void hwclock_init_debug(const char *str)
+{
+ __UL_INIT_DEBUG_FROM_STRING(hwclock, HWCLOCK_DEBUG_, 0, str);
+
+ DBG(INIT, ul_debug("hwclock debug mask: 0x%04x", hwclock_debug_mask));
+ DBG(INIT, ul_debug("hwclock version: %s", PACKAGE_STRING));
+}
+
+/* FOR TESTING ONLY: inject random delays of up to 1000ms */
+static void up_to_1000ms_sleep(void)
+{
+ int usec = random() % 1000000;
+
+ DBG(RANDOM_SLEEP, ul_debug("sleeping ~%d usec", usec));
+ xusleep(usec);
+}
+
/*
* time_t to timeval conversion.
*/
@@ -473,12 +493,7 @@ set_hardware_clock_exact(const struct hwclock_control *ctl,
while (1) {
double ticksize;
- /* FOR TESTING ONLY: inject random delays of up to 1000ms */
- if (ctl->verbose >= 10) {
- int usec = random() % 1000000;
- printf(_("sleeping ~%d usec\n"), usec);
- xusleep(usec);
- }
+ ON_DBG(RANDOM_SLEEP, up_to_1000ms_sleep());
gettimeofday(&nowsystime, NULL);
deltavstarget = time_diff(nowsystime, targetsystime);
@@ -494,13 +509,11 @@ set_hardware_clock_exact(const struct hwclock_control *ctl,
/* The retarget is handled at the end of the loop. */
} else if (deltavstarget < 0) {
/* deltavstarget < 0 if current time < target time */
- if (ctl->verbose >= 9)
- printf(_("%ld.%06ld < %ld.%06ld (%.6f)\n"),
- nowsystime.tv_sec,
- nowsystime.tv_usec,
- targetsystime.tv_sec,
- targetsystime.tv_usec,
- deltavstarget);
+ DBG(DELTA_VS_TARGET,
+ ul_debug("%ld.%06ld < %ld.%06ld (%.6f)",
+ nowsystime.tv_sec, nowsystime.tv_usec,
+ targetsystime.tv_sec,
+ targetsystime.tv_usec, deltavstarget));
continue; /* not there yet - keep spinning */
} else if (deltavstarget <= target_time_tolerance_secs) {
/* Close enough to the target time; done waiting. */
@@ -1125,6 +1138,7 @@ int main(int argc, char **argv)
{ "version", no_argument, NULL, 'V' },
{ "systohc", no_argument, NULL, 'w' },
{ "debug", no_argument, NULL, 'D' },
+ { "ul-debug", required_argument, NULL, 'd' },
{ "verbose", no_argument, NULL, 'v' },
{ "set", no_argument, NULL, OPT_SET },
#if defined(__linux__) && defined(__alpha__)
@@ -1187,7 +1201,7 @@ int main(int argc, char **argv)
atexit(close_stdout);
while ((c = getopt_long(argc, argv,
- "hvVDalrsuwf:", longopts, NULL)) != -1) {
+ "hvVDd:alrsuwf:", longopts, NULL)) != -1) {
err_exclusive_options(c, longopts, excl, excl_st);
@@ -1196,7 +1210,10 @@ int main(int argc, char **argv)
warnx(_("use --verbose, --debug has been deprecated."));
break;
case 'v':
- ctl.verbose++;
+ ctl.verbose = 1;
+ break;
+ case 'd':
+ hwclock_init_debug(optarg);
break;
case 'a':
ctl.adjust = 1;
@@ -1249,7 +1266,7 @@ int main(int argc, char **argv)
break;
case OPT_TEST:
ctl.testing = 1; /* --test */
- ctl.verbose++;
+ ctl.verbose = 1;
break;
case OPT_DATE:
ctl.date_opt = optarg; /* --date */
diff --git a/sys-utils/hwclock.h b/sys-utils/hwclock.h
index 570bfe439..7bb6ec8bd 100644
--- a/sys-utils/hwclock.h
+++ b/sys-utils/hwclock.h
@@ -8,6 +8,16 @@
#include <time.h>
#include "c.h"
+#include "debug.h"
+
+#define HWCLOCK_DEBUG_INIT (1 << 0)
+#define HWCLOCK_DEBUG_RANDOM_SLEEP (1 << 1)
+#define HWCLOCK_DEBUG_DELTA_VS_TARGET (1 << 2)
+#define HWCLOCK_DEBUG_ALL 0xFFFF
+
+UL_DEBUG_DECLARE_MASK(hwclock);
+#define DBG(m, x) __UL_DBG(hwclock, HWCLOCK_DEBUG_, m, x)
+#define ON_DBG(m, x) __UL_DBG_CALL(hwclock, HWCLOCK_DEBUG_, m, x)
struct hwclock_control {
char *date_opt;
@@ -18,7 +28,6 @@ struct hwclock_control {
#ifdef __linux__
char *rtc_dev_name;
#endif
- unsigned int verbose;
unsigned int
hwaudit_on:1,
adjust:1,
@@ -39,7 +48,8 @@ struct hwclock_control {
get:1,
set:1,
update:1,
- universal:1; /* will store hw_clock_is_utc() return value */
+ universal:1, /* will store hw_clock_is_utc() return value */
+ verbose:1;
};
struct clock_ops {