Mageia Bugzilla – Attachment 4107 Details for
Bug 6056
drakclock has a confusing message asking about hardware clock in GMT
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
New Account
|
Forgot Password
[patch]
patch to change GTM/UTC string; systemd integration, and better default for NTP severs
drakclock-utc-systemd-integration-and-better-ntp-server-default.patch (text/plain), 7.96 KB, created by
Pablo Saratxaga
on 2013-06-06 14:15:39 CEST
(
hide
)
Description:
patch to change GTM/UTC string; systemd integration, and better default for NTP severs
Filename:
MIME Type:
Creator:
Pablo Saratxaga
Created:
2013-06-06 14:15:39 CEST
Size:
7.96 KB
patch
obsolete
>--- /usr/sbin/drakclock_bak 2013-06-05 22:18:11.377154883 +0200 >+++ /usr/sbin/drakclock 2013-06-06 14:03:45.655286696 +0200 >@@ -11,6 +11,7 @@ > use interactive; > use standalone; > use timezone; >+use lang; # to get the user country > > my $in = interactive->vnew('su'); > my $pixmap; >@@ -25,7 +26,8 @@ > > my $ntpfile = '/etc/ntp.conf'; > my $ntpdlock = '/var/lock/subsys/ntpd'; >-my $ntpdsystemdlock = '/sys/fs/cgroup/systemd/system/ntpd.service'; >+my $ntpdsystemdcgroup = '/sys/fs/cgroup/systemd/system/ntpd.service'; >+my $timedatectl = "/usr/bin/timedatectl"; > > my $my_win = ugtk2->new(N("Date, Clock & Time Zone Settings")); > >@@ -44,7 +46,7 @@ > $button_time->signal_connect(clicked => sub { > local $::isEmbedded = 0; # to prevent sub window embedding > if ($timezone->{timezone} = $in->ask_from_treelist(N("Timezone - DrakClock"), N("Which is your timezone?"), '/', \@timezones, $timezone->{timezone})) { >- $timezone->{UTC} = $in->ask_yesorno(N("GMT - DrakClock"), N("Is your hardware clock set to GMT?"), $timezone->{UTC}); >+ $timezone->{UTC} = $in->ask_yesorno(N("UTC - DrakClock"), N("Is your hardware clock set to UTC (universal time)?"), $timezone->{UTC}); > timezone::write($timezone); > } > $label_timezone->set_text($timezone->{timezone}); >@@ -116,15 +118,21 @@ > return; > } > timezone::set_ntp_server($choosed_serv); >- system(qw(/sbin/chkconfig --level 35 ntpd on)); >- # FIXME: Change to use systemctl when will not support old iniscript anymore >+ if (-x $timedatectl) { # systemd dbus based service >+ system(qw(timedatectl set-ntp 0)); >+ } else { > system(qw(service ntpd stop)); >+ system(qw(/sbin/chkconfig --level 35 ntpd on)); >+ } > #verify that we have a valid hostname (thx sam) > $choosed_serv =~ s/[^-a-zA-Z0-9.]//g; > if (!system("/usr/sbin/ntpdate", $choosed_serv)) { > update_time(); #- get the new time before updating the hwclock >- # FIXME: Change to use systemctl when will not support old iniscript anymore >+ if (-x $timedatectl) { # systemd dbus based service >+ system(qw(timedatectl set-ntp 1)); >+ } else { > system(qw(service ntpd start)); >+ } > $need_date = 0; > } else { > $in->ask_from_no_check({ >@@ -135,14 +143,13 @@ > }, []) or return; > } > } else { >- if (-e $ntpdlock) { >+ if (-x $timedatectl) { # systemd dbus based service >+ system(qw(timedatectl set-ntp 0)); >+ } >+ elsif (-e $ntpdlock) { > system(qw(service ntpd stop)); > system(qw(/sbin/chkconfig --level 35 ntpd off)); > } >- elsif (-e $ntpdsystemdlock) { >- system(qw(systemctl stop ntpd.service)); >- system(qw(systemctl disable ntpd.service)); >- } > } > if ($need_date) { > my ($year, $month, $day) = $calendar->get_date; >@@ -174,9 +181,12 @@ > > my $servers = get_server(); > $combo_ntpserver->set_popdown_strings(@$servers); >-if (-e $ntpfile && (-e $ntpdsystemdlock || -e $ntpdlock)) { >+if (-e $ntpfile && (-e $ntpdsystemdcgroup || -e $ntpdlock)) { >+ # if NTP is already configured, preset the NTP server value >+ # note: existence of $ntpdsystemdcgroup means ntpd has already been active, >+ # not that it is currently active; use ntpd_state() for that > $ntp = timezone::ntp_server(); >- $ntp and ntp_widget_state(1); >+ $ntp and ntp_widget_state(ntpd_state()); > my $fullntp = $ntp; > my $short_ntp = $ntp; > #- strip digits from \d+.foo.pool.ntp.org >@@ -185,7 +195,22 @@ > /^[^:]+: \Q$short_ntp\E$/ and $fullntp = $_, last; > } > $combo_ntpserver->entry->set_text($fullntp); >-} else { ntp_widget_state(0) } >+} else { >+ # if NTP is not configured, preset the NTP server to match user country if possible >+ # if not, to match the continent from the timezone >+ ntp_widget_state(ntpd_state()); >+ my $country = lang::read()->{country}; >+ my $continent = $timezone->{timezone}; >+ $continent =~ s/^(.*)\/.*/$1/ ; >+ # "|" must be escaped as the sring will be used in a regexp match >+ my $continent_all_servers = N($continent) . "\\|" . N("All servers"); >+ my $fullntp; >+ foreach (@$servers) { >+ /^[^:]+: $country\.pool.ntp.org\E$/i and $fullntp = $_, last; >+ /^$continent_all_servers: [0-9a-z\._-]+$/ and $fullntp = $_; >+ } >+ $fullntp and $combo_ntpserver->entry->set_text($fullntp); >+} > > my $pressed; > $drawing_area->set_events([ 'button_press_mask', 'button_release_mask', "pointer_motion_mask" ]); >@@ -230,6 +255,19 @@ > $my_win->main; > ugtk2->exit(0); > >+sub ntpd_state { >+ # tries to get the current active state of ntpd >+ local $ENV{LANGUAGE} = 'C'; >+ my $state = 0; >+ if (-x $timedatectl) { # systemd dbus based service >+ foreach (run_program::rooted_get_stdout($::prefix, $timedatectl)) { >+ /^ *NTP enabled: yes$/ and $state = 1; >+ } >+ } else { >+ if (-e $ntpfile && -e $ntpdlock) { $state = 1 }; >+ } >+ $state; >+} > sub ntp_widget_state { > my ($state) = @_; > $check_ntp->set_active($state); >--- /usr/lib/libDrakX/timezone.pm_bak 2013-06-05 22:59:45.613025449 +0200 >+++ /usr/lib/libDrakX/timezone.pm 2013-06-06 14:09:20.692815272 +0200 >@@ -1,10 +1,11 @@ > package timezone; # $Id: timezone.pm 269985 2010-06-09 22:02:57Z herton $ > > >- >- > use common; > use log; >+use run_program; >+ >+my $timedatectl = "/usr/bin/timedatectl"; > > sub get_timezone_prefix() { > my $prefix = $::testing ? '' : $::prefix; >@@ -20,7 +21,20 @@ > } > > sub read() { >- my %t = getVarsFromSh("$::prefix/etc/sysconfig/clock") or return {}; >+ local $ENV{LANGUAGE} = 'C'; >+ my %t; >+ if (-x $timedatectl) { # systemd dbus based service >+ foreach (run_program::rooted_get_stdout($::prefix, $timedatectl)) { >+ /^ *Timezone: (.*) +\(.*\)$/ and $t{ZONE} = $1; >+ /^ *RTC in local TZ: yes$/ and $t{UTC} = 'no'; >+ /^ *RTC in local TZ: no$/ and $t{UTC} = 'yes'; >+ } >+ # if timezone not defined, it's probably because timedatectl has never been used yey >+ # so we fallback to reading old config >+ if ($t{ZONE} =~ m/n\/a /) { %t = getVarsFromSh("$::prefix/etc/sysconfig/clock") or return {}; } >+ } else { >+ %t = getVarsFromSh("$::prefix/etc/sysconfig/clock") or return {}; >+ } > { timezone => $t{ZONE}, UTC => text2bool($t{UTC}) }; > } > >@@ -59,6 +72,11 @@ > my $tz_prefix = get_timezone_prefix(); > eval { cp_af($tz_prefix . '/' . $t->{timezone}, "$::prefix/etc/localtime") }; > $@ and log::l("installing /etc/localtime failed"); >+ if (-x $timedatectl) { # systemd dbus based service >+ run_program::run($timedatectl, 'set-timezone', "$t->{timezone}"); >+ run_program::run($timedatectl, 'set-local-rtc', ($t->{UTC}) ? '0' : '1'); >+ run_program::run($timedatectl, 'set-ntp', ($t->{ntp}) ? '1' : '0' ); >+ } else { > setVarsInSh("$::prefix/etc/sysconfig/clock", { > ZONE => $t->{timezone}, > UTC => bool2text($t->{UTC}), >@@ -70,6 +88,7 @@ > @adjtime or @adjtime = ("0.0 0 0.0\n", "0\n"); > $adjtime[2] = $t->{UTC} ? "UTC\n" : "LOCAL\n"; > output_p($adjtime_file, @adjtime); >+ } > } > > sub reload_sys_clock {
--- /usr/sbin/drakclock_bak 2013-06-05 22:18:11.377154883 +0200 +++ /usr/sbin/drakclock 2013-06-06 14:03:45.655286696 +0200 @@ -11,6 +11,7 @@ use interactive; use standalone; use timezone; +use lang; # to get the user country my $in = interactive->vnew('su'); my $pixmap; @@ -25,7 +26,8 @@ my $ntpfile = '/etc/ntp.conf'; my $ntpdlock = '/var/lock/subsys/ntpd'; -my $ntpdsystemdlock = '/sys/fs/cgroup/systemd/system/ntpd.service'; +my $ntpdsystemdcgroup = '/sys/fs/cgroup/systemd/system/ntpd.service'; +my $timedatectl = "/usr/bin/timedatectl"; my $my_win = ugtk2->new(N("Date, Clock & Time Zone Settings")); @@ -44,7 +46,7 @@ $button_time->signal_connect(clicked => sub { local $::isEmbedded = 0; # to prevent sub window embedding if ($timezone->{timezone} = $in->ask_from_treelist(N("Timezone - DrakClock"), N("Which is your timezone?"), '/', \@timezones, $timezone->{timezone})) { - $timezone->{UTC} = $in->ask_yesorno(N("GMT - DrakClock"), N("Is your hardware clock set to GMT?"), $timezone->{UTC}); + $timezone->{UTC} = $in->ask_yesorno(N("UTC - DrakClock"), N("Is your hardware clock set to UTC (universal time)?"), $timezone->{UTC}); timezone::write($timezone); } $label_timezone->set_text($timezone->{timezone}); @@ -116,15 +118,21 @@ return; } timezone::set_ntp_server($choosed_serv); - system(qw(/sbin/chkconfig --level 35 ntpd on)); - # FIXME: Change to use systemctl when will not support old iniscript anymore + if (-x $timedatectl) { # systemd dbus based service + system(qw(timedatectl set-ntp 0)); + } else { system(qw(service ntpd stop)); + system(qw(/sbin/chkconfig --level 35 ntpd on)); + } #verify that we have a valid hostname (thx sam) $choosed_serv =~ s/[^-a-zA-Z0-9.]//g; if (!system("/usr/sbin/ntpdate", $choosed_serv)) { update_time(); #- get the new time before updating the hwclock - # FIXME: Change to use systemctl when will not support old iniscript anymore + if (-x $timedatectl) { # systemd dbus based service + system(qw(timedatectl set-ntp 1)); + } else { system(qw(service ntpd start)); + } $need_date = 0; } else { $in->ask_from_no_check({ @@ -135,14 +143,13 @@ }, []) or return; } } else { - if (-e $ntpdlock) { + if (-x $timedatectl) { # systemd dbus based service + system(qw(timedatectl set-ntp 0)); + } + elsif (-e $ntpdlock) { system(qw(service ntpd stop)); system(qw(/sbin/chkconfig --level 35 ntpd off)); } - elsif (-e $ntpdsystemdlock) { - system(qw(systemctl stop ntpd.service)); - system(qw(systemctl disable ntpd.service)); - } } if ($need_date) { my ($year, $month, $day) = $calendar->get_date; @@ -174,9 +181,12 @@ my $servers = get_server(); $combo_ntpserver->set_popdown_strings(@$servers); -if (-e $ntpfile && (-e $ntpdsystemdlock || -e $ntpdlock)) { +if (-e $ntpfile && (-e $ntpdsystemdcgroup || -e $ntpdlock)) { + # if NTP is already configured, preset the NTP server value + # note: existence of $ntpdsystemdcgroup means ntpd has already been active, + # not that it is currently active; use ntpd_state() for that $ntp = timezone::ntp_server(); - $ntp and ntp_widget_state(1); + $ntp and ntp_widget_state(ntpd_state()); my $fullntp = $ntp; my $short_ntp = $ntp; #- strip digits from \d+.foo.pool.ntp.org @@ -185,7 +195,22 @@ /^[^:]+: \Q$short_ntp\E$/ and $fullntp = $_, last; } $combo_ntpserver->entry->set_text($fullntp); -} else { ntp_widget_state(0) } +} else { + # if NTP is not configured, preset the NTP server to match user country if possible + # if not, to match the continent from the timezone + ntp_widget_state(ntpd_state()); + my $country = lang::read()->{country}; + my $continent = $timezone->{timezone}; + $continent =~ s/^(.*)\/.*/$1/ ; + # "|" must be escaped as the sring will be used in a regexp match + my $continent_all_servers = N($continent) . "\\|" . N("All servers"); + my $fullntp; + foreach (@$servers) { + /^[^:]+: $country\.pool.ntp.org\E$/i and $fullntp = $_, last; + /^$continent_all_servers: [0-9a-z\._-]+$/ and $fullntp = $_; + } + $fullntp and $combo_ntpserver->entry->set_text($fullntp); +} my $pressed; $drawing_area->set_events([ 'button_press_mask', 'button_release_mask', "pointer_motion_mask" ]); @@ -230,6 +255,19 @@ $my_win->main; ugtk2->exit(0); +sub ntpd_state { + # tries to get the current active state of ntpd + local $ENV{LANGUAGE} = 'C'; + my $state = 0; + if (-x $timedatectl) { # systemd dbus based service + foreach (run_program::rooted_get_stdout($::prefix, $timedatectl)) { + /^ *NTP enabled: yes$/ and $state = 1; + } + } else { + if (-e $ntpfile && -e $ntpdlock) { $state = 1 }; + } + $state; +} sub ntp_widget_state { my ($state) = @_; $check_ntp->set_active($state); --- /usr/lib/libDrakX/timezone.pm_bak 2013-06-05 22:59:45.613025449 +0200 +++ /usr/lib/libDrakX/timezone.pm 2013-06-06 14:09:20.692815272 +0200 @@ -1,10 +1,11 @@ package timezone; # $Id: timezone.pm 269985 2010-06-09 22:02:57Z herton $ - - use common; use log; +use run_program; + +my $timedatectl = "/usr/bin/timedatectl"; sub get_timezone_prefix() { my $prefix = $::testing ? '' : $::prefix; @@ -20,7 +21,20 @@ } sub read() { - my %t = getVarsFromSh("$::prefix/etc/sysconfig/clock") or return {}; + local $ENV{LANGUAGE} = 'C'; + my %t; + if (-x $timedatectl) { # systemd dbus based service + foreach (run_program::rooted_get_stdout($::prefix, $timedatectl)) { + /^ *Timezone: (.*) +\(.*\)$/ and $t{ZONE} = $1; + /^ *RTC in local TZ: yes$/ and $t{UTC} = 'no'; + /^ *RTC in local TZ: no$/ and $t{UTC} = 'yes'; + } + # if timezone not defined, it's probably because timedatectl has never been used yey + # so we fallback to reading old config + if ($t{ZONE} =~ m/n\/a /) { %t = getVarsFromSh("$::prefix/etc/sysconfig/clock") or return {}; } + } else { + %t = getVarsFromSh("$::prefix/etc/sysconfig/clock") or return {}; + } { timezone => $t{ZONE}, UTC => text2bool($t{UTC}) }; } @@ -59,6 +72,11 @@ my $tz_prefix = get_timezone_prefix(); eval { cp_af($tz_prefix . '/' . $t->{timezone}, "$::prefix/etc/localtime") }; $@ and log::l("installing /etc/localtime failed"); + if (-x $timedatectl) { # systemd dbus based service + run_program::run($timedatectl, 'set-timezone', "$t->{timezone}"); + run_program::run($timedatectl, 'set-local-rtc', ($t->{UTC}) ? '0' : '1'); + run_program::run($timedatectl, 'set-ntp', ($t->{ntp}) ? '1' : '0' ); + } else { setVarsInSh("$::prefix/etc/sysconfig/clock", { ZONE => $t->{timezone}, UTC => bool2text($t->{UTC}), @@ -70,6 +88,7 @@ @adjtime or @adjtime = ("0.0 0 0.0\n", "0\n"); $adjtime[2] = $t->{UTC} ? "UTC\n" : "LOCAL\n"; output_p($adjtime_file, @adjtime); + } } sub reload_sys_clock {
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 6056
:
4106
| 4107