]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hwclock: build on non-Linux
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Thu, 3 Mar 2011 01:18:32 +0000 (02:18 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 11 Mar 2011 11:34:25 +0000 (12:34 +0100)
Thanks to the direct ISA method and by disabling the RTC get/set epoch
functionality, hwclock can work fine on non-Linux systems which provide
ioperm or iopl.

Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Makefile.am
configure.ac
hwclock/Makefile.am
hwclock/cmos.c
hwclock/hwclock.c

index f7f27c67a79294aec5554cfd1fda1d7f1855ed74..906322557c8da9940a0766a1706f880853faaadf 100644 (file)
@@ -37,10 +37,12 @@ SUBDIRS = \
 RCS_FIND_IGNORE = \( -name SCCS -o -name BitKeeper -o -name .svn -o \
                -name CVS -o -name .pc -o -name .hg -o -name .git \) -prune -o
 
+if BUILD_HWCLOCK
+SUBDIRS += hwclock
+endif
+
 if LINUX
-SUBDIRS += \
-       hwclock \
-       partx
+SUBDIRS += partx
 endif
 
 if BUILD_INIT
index 9c3c5ac329386cc508d96a0af55d7b5d04c913f2..20d60befa25c5aaca3a613d068c42cca1aa3471a 100644 (file)
@@ -220,6 +220,9 @@ AC_FUNC_FSEEKO
 
 AC_CHECK_FUNCS([openat fstatat unlinkat], [have_openat=yes], [have_openat=no])
 
+AC_CHECK_FUNCS([ioperm iopl], [have_io=yes])
+AM_CONDITIONAL([BUILD_HWCLOCK], test "x$have_io" = xyes -o "x$linux_os" = xyes)
+
 AC_CHECK_MEMBER(struct sockaddr.sa_len,
                AC_DEFINE_UNQUOTED(HAVE_SA_LEN,1,[Define if struct sockaddr contains sa_len]),,
        [#include <sys/types.h>
index 542521c7eff7f64def80af427f76e6aa707f0e13..7042d9c3aa0df03cfb686072f3fd4a26a5c48dfa 100644 (file)
@@ -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
index 8b3495b7e56d037670715e63854d60925889e3de..947b21bea2bb2dcf4696b86f3c46521c728fa658 100644 (file)
@@ -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(HAVE_IOPL)
   extern int iopl(const int lvl);
   return iopl(level);
+#else
+  extern int ioperm(unsigned long from, unsigned long num, int turn_on);
+  return ioperm(clock_ctl_addr, 2, 1);
+#endif
 #else
   return -2;
 #endif
index 88fb8a073279ce7c94211d05d77cc18e42165f81..02b404e9d65af4c7dae8867d2da1c64443f159e6 100644 (file)
@@ -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();