]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hwclock: use CMOS clock only if available
authorCarlos Santos <unixmania@gmail.com>
Wed, 3 Jul 2019 16:31:34 +0000 (13:31 -0300)
committerKarel Zak <kzak@redhat.com>
Mon, 15 Jul 2019 11:56:13 +0000 (13:56 +0200)
- Add --disable-hwclock-cmos configuration argument
- Add USE_HWCLOCK_CMOS (enabled by default for i386/x86_64)
- Add define(USE_HWCLOCK_CMOS)
- Compile hwclock-cmos.c only if USE_HWCLOCK_CMOS is true
- Remove all unnecessary #ifdefs from hwclock-cmos.c
- Add #ifdef USE_HWCLOCK_CMOS around the determine_clock_access_method()
  call in hwclock.c

Signed-off-by: Carlos Santos <unixmania@gmail.com>
configure.ac
sys-utils/Makemodule.am
sys-utils/hwclock-cmos.c
sys-utils/hwclock.c

index 997b6388cb0538b06163d94ad0fac70b47e406ce..8aa2fed38f215676e14bd4801195d077692f9a31 100644 (file)
@@ -1517,6 +1517,19 @@ UL_REQUIRES_HAVE([hwclock], [io, linuxdummy], [ioperm iopl function or Linux])
 AM_CONDITIONAL([BUILD_HWCLOCK], [test "x$build_hwclock" = xyes])
 
 
+AC_ARG_ENABLE([hwclock-cmos],
+  AS_HELP_STRING([--disable-hwclock-cmos], [do not use CMOS clock]),
+  [], [use_hwclock_cmos="$build_hwclock"]
+)
+
+AS_IF([test "x$use_hwclock_cmos" = xyes], [
+  AM_CONDITIONAL([USE_HWCLOCK_CMOS], [true])
+  AC_DEFINE([USE_HWCLOCK_CMOS], [1], [Define to 1 if want to use CMOS clock.])
+],[
+  AM_CONDITIONAL([USE_HWCLOCK_CMOS], [false])
+])
+
+
 UL_BUILD_INIT([mkfs], [yes])
 AM_CONDITIONAL([BUILD_MKFS], [test "x$build_mkfs" = xyes])
 
index 7c118a6def2bf5f6d9ce66cbbaec48b45b9aac6b..98e2cc29b88346635b8d854f9fc0c0a65b9d2262 100644 (file)
@@ -451,9 +451,12 @@ dist_man_MANS += \
 PATHFILES += sys-utils/hwclock.8
 hwclock_SOURCES = \
        sys-utils/hwclock.c \
-       sys-utils/hwclock.h \
-       sys-utils/hwclock-cmos.c
+       sys-utils/hwclock.h
 hwclock_LDADD = $(LDADD) libcommon.la -lm
+if USE_HWCLOCK_CMOS
+hwclock_SOURCES += \
+       sys-utils/hwclock-cmos.c
+endif
 if LINUX
 hwclock_SOURCES += \
        sys-utils/hwclock-rtc.c \
index a11f676b8c14b9a4af95186673f6c697466f9817..4d3e023d9e84cea7301cdcbaee1ecd33b1c26176 100644 (file)
 #include "pathnames.h"
 
 /* for inb, outb */
-#if defined(__i386__) || defined(__x86_64__)
-# ifdef HAVE_SYS_IO_H
-#  include <sys/io.h>
-# elif defined(HAVE_ASM_IO_H)
-#  include <asm/io.h>
-# else
-#  undef __i386__
-#  undef __x86_64__
-#  warning "disable cmos access - no sys/io.h or asm/io.h"
-static void outb(int a __attribute__((__unused__)),
-                int b __attribute__((__unused__)))
-{
-}
-
-static int inb(int c __attribute__((__unused__)))
-{
-       return 0;
-}
-# endif                                /* __i386__ __x86_64__ */
+#ifdef HAVE_SYS_IO_H
+# include <sys/io.h>
+#elif defined(HAVE_ASM_IO_H)
+# include <asm/io.h>
 #else
-# warning "disable cmos access - not i386 or x86_64"
-static void outb(int a __attribute__((__unused__)),
-                int b __attribute__((__unused__)))
-{
-}
-
-static int inb(int c __attribute__((__unused__)))
-{
-       return 0;
-}
-#endif                         /* for inb, outb */
+# error "no sys/io.h or asm/io.h"
+#endif /* HAVE_SYS_IO_H, HAVE_ASM_IO_H */
 
 #include "hwclock.h"
 
@@ -360,7 +336,6 @@ static int set_hardware_clock_cmos(const struct hwclock_control *ctl
        return 0;
 }
 
-#if defined(__i386__) || defined(__x86_64__)
 # if defined(HAVE_IOPL)
 static int i386_iopl(const int level)
 {
@@ -373,12 +348,6 @@ static int i386_iopl(const int level __attribute__ ((__unused__)))
        return ioperm(clock_ctl_addr, 2, 1);
 }
 # endif
-#else
-static int i386_iopl(const int level __attribute__ ((__unused__)))
-{
-       return IOPL_NOT_IMPLEMENTED;
-}
-#endif
 
 static int get_permissions_cmos(void)
 {
@@ -412,9 +381,5 @@ static struct clock_ops cmos_interface = {
  */
 struct clock_ops *probe_for_cmos_clock(void)
 {
-#if defined(__i386__) || defined(__x86_64__)
        return &cmos_interface;
-#else
-       return NULL;
-#endif
 }
index a2c5cc2a49627924e7d86790f74f0da0d8db0657..c01a868267ab90fd117e723b52ffca40c786d3a7 100644 (file)
@@ -925,8 +925,10 @@ static void determine_clock_access_method(const struct hwclock_control *ctl)
 {
        ur = NULL;
 
+#ifdef USE_HWCLOCK_CMOS
        if (ctl->directisa)
                ur = probe_for_cmos_clock();
+#endif
 #ifdef __linux__
        if (!ur)
                ur = probe_for_rtc_clock(ctl);