Karel Zak, le Wed 02 Mar 2011 12:56:44 +0100, a écrit : > On Wed, Mar 02, 2011 at 12:12:17PM +0100, Samuel Thibault wrote: > > Fabian Groffen, le Wed 02 Mar 2011 08:45:21 +0100, a écrit : > > > On 02-03-2011 03:07:35 +0100, Samuel Thibault wrote: > > > > 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. > > > > > > "It works on GNU/Hurd" is something different from "works fine on > > > non-Linux". > > > > It would also work on cygwin, kfreebsd/gnu, etc. That is, a lot of > > projects which usually make use of the util-linux package to benefit > > from its various tools. > > > > > Both calls are unavailable to me, being on "non-Linux". > > > Not that I intend to build this tool. > > > > We could make it depending on the presence of iopl or ioperm then. > > Yes, please. Here it is: Build hwclock 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@xxxxxxxxxxxx> diff --git a/Makefile.am b/Makefile.am index d298849..a1de4c9 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 8421d50..4802535 100644 --- a/configure.ac +++ b/configure.ac @@ -214,6 +214,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 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..947b21b 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 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