summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Thibault2011-03-03 02:18:32 +0100
committerKarel Zak2011-03-11 12:34:25 +0100
commit465e9973848fc7398722b16d948a0d37cb51126f (patch)
treeaa00788f7e4848230b77405ca142333e6670d8b7
parentcfdisk: add home and end keys movements in partition list (diff)
downloadkernel-qcow2-util-linux-465e9973848fc7398722b16d948a0d37cb51126f.tar.gz
kernel-qcow2-util-linux-465e9973848fc7398722b16d948a0d37cb51126f.tar.xz
kernel-qcow2-util-linux-465e9973848fc7398722b16d948a0d37cb51126f.zip
hwclock: build on non-Linux
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>
-rw-r--r--Makefile.am8
-rw-r--r--configure.ac3
-rw-r--r--hwclock/Makefile.am6
-rw-r--r--hwclock/cmos.c7
-rw-r--r--hwclock/hwclock.c18
5 files changed, 38 insertions, 4 deletions
diff --git a/Makefile.am b/Makefile.am
index f7f27c67a..906322557 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -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
diff --git a/configure.ac b/configure.ac
index 9c3c5ac32..20d60befa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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>
diff --git a/hwclock/Makefile.am b/hwclock/Makefile.am
index 542521c7e..7042d9c3a 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 8b3495b7e..947b21bea 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,9 +559,14 @@ 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
}
diff --git a/hwclock/hwclock.c b/hwclock/hwclock.c
index 88fb8a073..02b404e9d 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();