From 907d52c44b34645cf2d251560b35c388a2f13aff Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Wed, 2 Sep 2009 12:38:40 -0700 Subject: [PATCH] Hardware clock detection --- time/config-*-linux | 2 +- time/config.info | 2 +- time/index.cgi | 12 ++++++------ time/time-lib.pl | 16 ++++++++++++++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/time/config-*-linux b/time/config-*-linux index c510b44c1..a79712568 100644 --- a/time/config-*-linux +++ b/time/config-*-linux @@ -1,5 +1,5 @@ lease=5 -hwtime=1 +hwtime=2 seconds=1 timeserver_hardware=1 zone_style=linux diff --git a/time/config.info b/time/config.info index 44f4b39a8..859d98501 100644 --- a/time/config.info +++ b/time/config.info @@ -3,7 +3,7 @@ lease=Acceptable number seconds of delay between system time and hardware time,0 timeserver=Default time server,3,None ntp_only=Only use NTP for time synchronization?,1,1-Yes,0-No line2=System configuration,11 -hwtime=System supports hardware time,1,1-Yes,0-No +hwtime=System supports hardware time,1,1-Yes,0-No,2-Detect automatically seconds=System time setting format,1,1-MMDDHHMMYYYY.SS,0-MMDDHHMMYY,2-YYYYMMDDHHMM.SS zone_style=Timezone configuration method,4,linux-Linux,freebsd-FreeBSD,solaris-Solaris,-<Not supported on this OS> hwclock_flags=Command-line flags for hwclock,10,-None,sysconfig-From /etc/sysconfig/clock diff --git a/time/index.cgi b/time/index.cgi index 745c87459..f044723eb 100755 --- a/time/index.cgi +++ b/time/index.cgi @@ -8,7 +8,7 @@ $txt = ""; &error( $text{ 'acl_error' } ) if( $access{ 'sysdate' } && $access{ 'hwdate' } ); -if (!$access{'sysdate'} && !$access{'hwdate'} && $config{'hwtime'}) { +if (!$access{'sysdate'} && !$access{'hwdate'} && &support_hwtime()) { $arr = "0,1"; } else { @@ -24,7 +24,7 @@ if (!$access{'sysdate'} && !&has_command("date")) { &ui_print_footer("/", $text{'index'}); exit; } -if (!$access{'hwdate'} && $config{'hwtime'} && !&has_command("hwclock")) { +if (!$access{'hwdate'} && $config{'hwtime'} == 1 && !&has_command("hwclock")) { print &text( 'error_cnf', "hwclock"),"

\n"; &ui_print_footer("/", $text{'index'}); exit; @@ -60,7 +60,7 @@ if( !$access{'sysdate'} ) print &ui_form_start("apply.cgi"); print &tabletime(&hlink($text{'sys_title'}, "system_time"), 0, %system_date); print &ui_submit($text{'action_apply'}, "action"); - if ($config{'hwtime'}) { + if (&support_hwtime()) { print &ui_submit($text{'action_sync'}, "action"); } print &ui_form_end(); @@ -72,7 +72,7 @@ else } # Get the hardware time -if ($config{'hwtime'}) { +if (&support_hwtime()) { local @tm = &get_hardware_time(); @tm || &error($get_hardware_time_error || $text{'index_eformat'}); $hw_date{ 'second' } = $tm[0]; @@ -93,7 +93,7 @@ if ($config{'hwtime'}) { print &tabletime(&hlink($text{'hw_title'}, "hardware_time"), 0, %hw_date); print &ui_submit($text{'action_save'}, "action"); - if ($config{'hwtime'}) { + if (support_hwtime()) { print &ui_submit($text{'action_sync_s'}, "action"); } print &ui_form_end(); @@ -154,7 +154,7 @@ if ( ( !$access{ 'sysdate' } && &has_command( "date" ) || !$access{ 'hwdate' } & &ui_textbox("timeserver", $config{'timeserver'}, 60)); # Show hardware time checkbox - if ($config{'hwtime'}) { + if (&support_hwtime()) { print &ui_table_row(" ", &ui_checkbox("hardware", 1, $text{'index_hardware2'}, $config{'timeserver_hardware'})); diff --git a/time/time-lib.pl b/time/time-lib.pl index 1f801c8e8..701628511 100755 --- a/time/time-lib.pl +++ b/time/time-lib.pl @@ -208,5 +208,21 @@ sub number_to_weekday return ucfirst($weekday_names[$_[0]]); } +# Returns 1 if this system supports setting the hardware clock. +sub support_hwtime +{ +if ($config{'hwtime'} == 1) { + return 1; + } +elsif ($config{'hwtime'} == 0) { + return 0; + } +else { + return &has_command("hwclock") && + !&running_in_xen() && !&running_in_vserver() && + !&running_in_zone(); + } +} + 1;