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;
*/
};
+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.
*/
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);
/* 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. */
{ "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__)
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);
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;
break;
case OPT_TEST:
ctl.testing = 1; /* --test */
- ctl.verbose++;
+ ctl.verbose = 1;
break;
case OPT_DATE:
ctl.date_opt = optarg; /* --date */
#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;
#ifdef __linux__
char *rtc_dev_name;
#endif
- unsigned int verbose;
unsigned int
hwaudit_on:1,
adjust:1,
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 {