[PATCH] Build hwclock on non-Linux

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks to the direct ISA method, hwclock can work fine on non-Linux
without the /dev/rtc device and the associated get/set epoch
functionality.

GNU/Hurd however needs to use ioperm instead of iopl, which it doesn't
implement.

Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxx>

diff --git a/hwclock/Makefile.am b/hwclock/Makefile.am
index 542521c..7042d9c 100644
--- a/hwclock/Makefile.am
+++ b/hwclock/Makefile.am
@@ -4,9 +4,13 @@ dist_man_MANS = hwclock.8
 
 sbin_PROGRAMS = hwclock
 
-hwclock_SOURCES = hwclock.c cmos.c rtc.c kd.c clock.h
+hwclock_SOURCES = hwclock.c cmos.c kd.c clock.h
 hwclock_LDADD =
 
+if LINUX
+hwclock_SOURCES += rtc.c
+endif
+
 if HAVE_AUDIT
 hwclock_LDADD += -laudit
 endif
diff --git a/hwclock/cmos.c b/hwclock/cmos.c
index 8b3495b..ad5feb0 100644
--- a/hwclock/cmos.c
+++ b/hwclock/cmos.c
@@ -155,11 +155,13 @@ set_cmos_epoch(int ARCconsole, int SRM) {
     return;
 
 
+#ifdef __linux__
   /* If we can ask the kernel, we don't need guessing from /proc/cpuinfo */
   if (get_epoch_rtc(&epoch, 1) == 0) {
      cmos_epoch = epoch;
      return;
   }
+#endif
 
   /* The kernel source today says: read the year.
      If it is in 0-19 then the epoch is 2000.
@@ -557,8 +559,13 @@ set_hardware_clock_cmos(const struct tm *new_broken_time) {
 static int
 i386_iopl(const int level) {
 #if defined(__i386__) || defined(__alpha__)
+#if defined(__GNU__)
+  extern int ioperm(unsigned long from, unsigned long num, int turn_on);
+  return ioperm(clock_ctl_addr, 2, 1);
+#else
   extern int iopl(const int lvl);
   return iopl(level);
+#endif
 #else
   return -2;
 #endif
diff --git a/hwclock/hwclock.c b/hwclock/hwclock.c
index 88fb8a0..02b404e 100644
--- a/hwclock/hwclock.c
+++ b/hwclock/hwclock.c
@@ -1101,8 +1101,10 @@ determine_clock_access_method(const bool user_requests_ISA) {
   if (user_requests_ISA)
 	  ur = probe_for_cmos_clock();
 
+#ifdef __linux__
   if (!ur)
 	  ur = probe_for_rtc_clock();
+#endif
 
   if (!ur)
 	  ur = probe_for_kd_clock();
@@ -1262,6 +1264,7 @@ manipulate_clock(const bool show, const bool adjust, const bool noadjfile,
 }
 
 
+#ifdef __linux__
 static void
 manipulate_epoch(const bool getepoch, const bool setepoch,
                  const int epoch_opt, const bool testing) {
@@ -1304,6 +1307,7 @@ manipulate_epoch(const bool getepoch, const bool setepoch,
     }
 #endif
 }
+#endif
 
 #ifdef __ia64__
 #define RTC_DEV "/dev/efirtc"
@@ -1345,15 +1349,19 @@ usage( const char *fmt, ... ) {
 	"       --systz        set the system time based on the current timezone\n"
 	"       --adjust       adjust the rtc to account for systematic drift since\n"
 	"                      the clock was last set or adjusted\n"
+#ifdef __linux__
 	"       --getepoch     print out the kernel's hardware clock epoch value\n"
 	"       --setepoch     set the kernel's hardware clock epoch value to the \n"
 	"                      value given with --epoch\n"
+#endif
 	"       --predict      predict rtc reading at time given with --date\n"
 	"  -v | --version      print out the version of hwclock to stdout\n"
 	"\nOptions: \n"
 	"  -u | --utc          the hardware clock is kept in UTC\n"
 	"       --localtime    the hardware clock is kept in local time\n"
+#ifdef __linux__
 	"  -f | --rtc=path     special /dev/... file to use instead of default\n"
+#endif
 	"       --directisa    access the ISA bus directly instead of %s\n"
 	"       --badyear      ignore rtc's year because the bios is broken\n"
 	"       --date         specifies the time to which to set the hardware clock\n"
@@ -1406,8 +1414,10 @@ static const struct option longopts[] = {
 	{ "funky-toy", 0, 0, 'F'},
 #endif
 	{ "set", 0, 0, 128 },
+#ifdef __linux__
 	{ "getepoch", 0, 0, 129 },
 	{ "setepoch", 0, 0, 130 },
+#endif
 	{ "noadjfile", 0, 0, 131 },
 	{ "localtime", 0, 0, 132 },
 	{ "badyear", 0, 0, 133 },
@@ -1415,7 +1425,9 @@ static const struct option longopts[] = {
 	{ "test", 0, 0, 135 },
 	{ "date", 1, 0, 136 },
 	{ "epoch", 1, 0, 137 },
+#ifdef __linux__
 	{ "rtc", 1, 0, 'f' },
+#endif
 	{ "adjfile", 1, 0, 138 },
 	{ "systz", 0, 0, 139 },
 	{ "predict-hc", 0, 0, 140 },
@@ -1517,12 +1529,14 @@ main(int argc, char **argv) {
 		case 128:
 			set = TRUE;
 			break;
+#ifdef __linux__
 		case 129:
 			getepoch = TRUE;
 			break;
 		case 130:
 			setepoch = TRUE;
 			break;
+#endif
 		case 131:
 			noadjfile = TRUE;
 			break;
@@ -1553,9 +1567,11 @@ main(int argc, char **argv) {
 		case 140:
 			predict = TRUE;			/* --predict-hc */
 			break;
+#ifdef __linux__
 		case 'f':
 			rtc_dev_name = optarg;		/* --rtc */
 			break;
+#endif
 		case 'v':				/* --version */
 		case 'V':
 			out_version();
@@ -1667,10 +1683,12 @@ main(int argc, char **argv) {
 	if (!permitted)
 		hwclock_exit(EX_NOPERM);
 
+#ifdef __linux__
 	if (getepoch || setepoch) {
 		manipulate_epoch(getepoch, setepoch, epoch_option, testing);
 		hwclock_exit(0);
 	}
+#endif
 
 	if (debug)
 		out_version();
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux