Hardware clock detection
authorJamie Cameron <jcameron@webmin.com>
Wed, 2 Sep 2009 19:38:40 +0000 (12:38 -0700)
committerJamie Cameron <jcameron@webmin.com>
Wed, 2 Sep 2009 19:38:40 +0000 (12:38 -0700)
time/config-*-linux
time/config.info
time/index.cgi
time/time-lib.pl

index c510b44..a797125 100644 (file)
@@ -1,5 +1,5 @@
 lease=5
-hwtime=1
+hwtime=2
 seconds=1
 timeserver_hardware=1
 zone_style=linux
index 44f4b39..859d985 100644 (file)
@@ -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,-&lt;Not supported on this OS&gt;
 hwclock_flags=Command-line flags for hwclock,10,-None,sysconfig-From /etc/sysconfig/clock
index 745c874..f044723 100755 (executable)
@@ -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', "<tt>hwclock</tt>"),"<p>\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'}));
index 1f801c8..7016285 100755 (executable)
@@ -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;