Fix skip hwclock when unavailable #2693
This commit is contained in:
+4
-10
@@ -1,8 +1,5 @@
|
|||||||
#!/usr/local/bin/perl
|
#!/usr/local/bin/perl
|
||||||
|
|
||||||
local $format;
|
|
||||||
local $out;
|
|
||||||
|
|
||||||
require "./time-lib.pl";
|
require "./time-lib.pl";
|
||||||
use Time::Local;
|
use Time::Local;
|
||||||
|
|
||||||
@@ -17,17 +14,15 @@ $mode = "time";
|
|||||||
if ($in{'action'} eq $text{'action_sync'}) {
|
if ($in{'action'} eq $text{'action_sync'}) {
|
||||||
# Set system time to hardware time
|
# Set system time to hardware time
|
||||||
&error( $text{ 'acl_nosys' } ) if( $access{ 'sysdate' } );
|
&error( $text{ 'acl_nosys' } ) if( $access{ 'sysdate' } );
|
||||||
local $flags = &get_hwclock_flags();
|
$err = &set_system_time_to_hardware_time();
|
||||||
$out = &backquote_logged("hwclock $flags --hctosys");
|
&error( &text( 'error_sync', &html_escape($err) ) ) if ($err);
|
||||||
&error( &text( 'error_sync', $out ) ) if( $out ne "" );
|
|
||||||
&webmin_log("sync");
|
&webmin_log("sync");
|
||||||
|
|
||||||
} elsif ($in{'action'} eq $text{'action_sync_s'}) {
|
} elsif ($in{'action'} eq $text{'action_sync_s'}) {
|
||||||
# Set hardware time to system time
|
# Set hardware time to system time
|
||||||
&error( $text{ 'acl_nohw' } ) if( $access{ 'hwdate' } && $access{'sysdate'} );
|
&error( $text{ 'acl_nohw' } ) if( $access{ 'hwdate' } && $access{'sysdate'} );
|
||||||
local $flags = &get_hwclock_flags();
|
$err = &set_hardware_time_to_system_time();
|
||||||
$out = &backquote_logged("hwclock $flags --systohc");
|
&error( &text( 'error_sync', &html_escape($err) ) ) if ($err);
|
||||||
&error( &text( 'error_sync', $out ) ) if( $out ne "" );
|
|
||||||
&webmin_log("sync_s");
|
&webmin_log("sync_s");
|
||||||
|
|
||||||
} elsif($in{'action'} eq $text{'action_apply'} || $in{'mode'} eq 'sysdate' ) {
|
} elsif($in{'action'} eq $text{'action_apply'} || $in{'mode'} eq 'sysdate' ) {
|
||||||
@@ -111,4 +106,3 @@ if ($in{'action'} eq $text{'action_sync'}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
&redirect("index.cgi?mode=$mode");
|
&redirect("index.cgi?mode=$mode");
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -104,7 +104,7 @@ if ($support_hwtime) {
|
|||||||
print &tabletime(&hlink($text{'hw_title'}, "hardware_time"),
|
print &tabletime(&hlink($text{'hw_title'}, "hardware_time"),
|
||||||
0, %hw_date);
|
0, %hw_date);
|
||||||
print &ui_submit($text{'action_save'}, "action");
|
print &ui_submit($text{'action_save'}, "action");
|
||||||
if (support_hwtime()) {
|
if ($support_hwtime) {
|
||||||
print &ui_submit($text{'action_sync_s'}, "action");
|
print &ui_submit($text{'action_sync_s'}, "action");
|
||||||
}
|
}
|
||||||
print &ui_form_end();
|
print &ui_form_end();
|
||||||
@@ -153,7 +153,8 @@ if ($access{'timezone'} && &has_timezone()) {
|
|||||||
print &ui_tabs_end_tab();
|
print &ui_tabs_end_tab();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ( !$access{ 'sysdate' } && &has_command( "date" ) || !$access{ 'hwdate' } && &has_command( "hwclock" ) ) && $access{'ntp'} )
|
if (((!$access{'sysdate'} && &has_command("date")) ||
|
||||||
|
(!$access{'hwdate'} && $support_hwtime)) && $access{'ntp'})
|
||||||
{
|
{
|
||||||
# Show time server input
|
# Show time server input
|
||||||
print &ui_tabs_start_tab("mode", "sync");
|
print &ui_tabs_start_tab("mode", "sync");
|
||||||
|
|||||||
+55
-10
@@ -102,9 +102,10 @@ elsif ($?) {
|
|||||||
|
|
||||||
if ($hwtoo) {
|
if ($hwtoo) {
|
||||||
# Set hardware clock time to match system time (which is now correct)
|
# Set hardware clock time to match system time (which is now correct)
|
||||||
my $flags = &get_hwclock_flags();
|
if (&support_hwtime()) {
|
||||||
my $out = &backquote_logged("hwclock $flags --systohc");
|
my $err = &set_hardware_time_to_system_time();
|
||||||
return $? ? $out : undef;
|
return $err if ($err);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return undef;
|
return undef;
|
||||||
@@ -163,16 +164,34 @@ else {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# hwclock_command()
|
||||||
|
# Returns the path to the hwclock command, if available
|
||||||
|
sub hwclock_command
|
||||||
|
{
|
||||||
|
return &has_command("hwclock");
|
||||||
|
}
|
||||||
|
|
||||||
|
# hwclock_missing_error()
|
||||||
|
sub hwclock_missing_error
|
||||||
|
{
|
||||||
|
return &text('error_cnf', "hwclock");
|
||||||
|
}
|
||||||
|
|
||||||
# get_hardware_time()
|
# get_hardware_time()
|
||||||
# Returns the current hardware time, in localtime format. On failure returns
|
# Returns the current hardware time, in localtime format. On failure returns
|
||||||
# an empty array, and sets the global $get_hardware_time_error
|
# an empty array, and sets the global $get_hardware_time_error
|
||||||
sub get_hardware_time
|
sub get_hardware_time
|
||||||
{
|
{
|
||||||
|
my $hwclock = &hwclock_command();
|
||||||
|
$get_hardware_time_error = undef;
|
||||||
|
if (!$hwclock) {
|
||||||
|
$get_hardware_time_error = &hwclock_missing_error();
|
||||||
|
return ( );
|
||||||
|
}
|
||||||
my $flags = &get_hwclock_flags();
|
my $flags = &get_hwclock_flags();
|
||||||
$flags ||= "";
|
$flags ||= "";
|
||||||
$get_hardware_time_error = undef;
|
|
||||||
&clean_language();
|
&clean_language();
|
||||||
my $out = &backquote_command("hwclock $flags 2>/dev/null");
|
my $out = &backquote_command("$hwclock $flags 2>/dev/null");
|
||||||
&reset_environment();
|
&reset_environment();
|
||||||
if ($out =~ /^(\S+)\s+(\S+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+)\s+/) {
|
if ($out =~ /^(\S+)\s+(\S+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+)\s+/) {
|
||||||
return ($6, $5, $4, $3, &month_to_number($2), $7-1900, &weekday_to_number($1));
|
return ($6, $5, $4, $3, &month_to_number($2), $7-1900, &weekday_to_number($1));
|
||||||
@@ -186,7 +205,7 @@ elsif ($out =~ /^(\d+)\-(\d+)\-(\d+)\s+(\d+):(\d+):(\d+)/) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$get_hardware_time_error = &text('index_ehwclock',
|
$get_hardware_time_error = &text('index_ehwclock',
|
||||||
"<tt>".&html_escape("hwclock $flags")."</tt>",
|
"<tt>".&html_escape("$hwclock $flags")."</tt>",
|
||||||
"<pre>".&html_escape($out)."</pre>");
|
"<pre>".&html_escape($out)."</pre>");
|
||||||
return ( );
|
return ( );
|
||||||
}
|
}
|
||||||
@@ -203,15 +222,41 @@ return localtime(time());
|
|||||||
sub set_hardware_time
|
sub set_hardware_time
|
||||||
{
|
{
|
||||||
my ($second, $minute, $hour, $date, $month, $year) = @_;
|
my ($second, $minute, $hour, $date, $month, $year) = @_;
|
||||||
|
my $hwclock = &hwclock_command();
|
||||||
|
return &hwclock_missing_error() if (!$hwclock);
|
||||||
$month++;
|
$month++;
|
||||||
$year += 1900;
|
$year += 1900;
|
||||||
my $format = "--set --date=".
|
my $format = "--set --date=".
|
||||||
quotemeta("$year-$month-$date $hour:$minute:$second");
|
quotemeta("$year-$month-$date $hour:$minute:$second");
|
||||||
my $flags = &get_hwclock_flags();
|
my $flags = &get_hwclock_flags();
|
||||||
my $out = &backquote_logged("hwclock $flags $format 2>&1");
|
my $out = &backquote_logged("$hwclock $flags $format 2>&1");
|
||||||
return $? ? $out : undef;
|
return $? ? $out : undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# set_hardware_time_to_system_time()
|
||||||
|
# Sets the hardware time to the current system time
|
||||||
|
sub set_hardware_time_to_system_time
|
||||||
|
{
|
||||||
|
my $hwclock = &hwclock_command();
|
||||||
|
return &hwclock_missing_error() if (!$hwclock);
|
||||||
|
my $flags = &get_hwclock_flags();
|
||||||
|
$flags ||= "";
|
||||||
|
my $out = &backquote_logged("$hwclock $flags --systohc 2>&1");
|
||||||
|
return $? ? $out : undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
# set_system_time_to_hardware_time()
|
||||||
|
# Sets the system time to the current hardware time
|
||||||
|
sub set_system_time_to_hardware_time
|
||||||
|
{
|
||||||
|
my $hwclock = &hwclock_command();
|
||||||
|
return &hwclock_missing_error() if (!$hwclock);
|
||||||
|
my $flags = &get_hwclock_flags();
|
||||||
|
$flags ||= "";
|
||||||
|
my $out = &backquote_logged("$hwclock $flags --hctosys 2>&1");
|
||||||
|
return $? || $out ne "" ? $out : undef;
|
||||||
|
}
|
||||||
|
|
||||||
# set_system_time(secs, mins, hours, day, month, year)
|
# set_system_time(secs, mins, hours, day, month, year)
|
||||||
sub set_system_time
|
sub set_system_time
|
||||||
{
|
{
|
||||||
@@ -278,8 +323,9 @@ return defined($_[0]) ? ucfirst($weekday_names[$_[0]]) : undef;
|
|||||||
# Returns 1 if this system supports setting the hardware clock.
|
# Returns 1 if this system supports setting the hardware clock.
|
||||||
sub support_hwtime
|
sub support_hwtime
|
||||||
{
|
{
|
||||||
return &has_command("hwclock") &&
|
my $hwclock = &hwclock_command();
|
||||||
&execute_command("hwclock") == 0 &&
|
return $hwclock &&
|
||||||
|
&execute_command($hwclock) == 0 &&
|
||||||
!&running_in_xen() && !&running_in_vserver() &&
|
!&running_in_xen() && !&running_in_vserver() &&
|
||||||
!&running_in_openvz() && !&running_in_zone();
|
!&running_in_openvz() && !&running_in_zone();
|
||||||
}
|
}
|
||||||
@@ -307,4 +353,3 @@ if ($modconf_info) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user