From: Stefan Mayr <stefan@mayr-stefan.de>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH common v2 4/4] Fix #7175: replace timezone handling with systemd timedatectl
Date: Sun, 25 Jan 2026 22:01:51 +0100 [thread overview]
Message-ID: <20260125210151.1151-5-stefan@mayr-stefan.de> (raw)
In-Reply-To: <20260125210151.1151-1-stefan@mayr-stefan.de>
Usage of /etc/timezone is deprecated. The tzdata maintainers recommend
switching to timedatectl.
This removes handling the timezone file from the INotify module and adds
functions to the Systemd module as a replacement
Suggested-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Suggested-by: Maximiliano Sandroval <m.sandoval@proxmox.com>
Signed-off-by: Stefan Mayr <stefan@mayr-stefan.de>
---
src/PVE/INotify.pm | 29 -----------------------------
src/PVE/Systemd.pm | 35 ++++++++++++++++++++++++++++++++++-
2 files changed, 34 insertions(+), 30 deletions(-)
diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index 62b3ca8..03c871c 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -651,35 +651,6 @@ register_file(
\&update_etc_resolv_conf,
);
-sub read_etc_timezone {
- my ($filename, $fd) = @_;
-
- my $timezone = <$fd>;
-
- chomp $timezone;
-
- return $timezone;
-}
-
-sub write_etc_timezone {
- my ($filename, $fh, $timezone) = @_;
-
- my $tzinfo = "/usr/share/zoneinfo/$timezone";
-
- raise_param_exc({ 'timezone' => "No such timezone" })
- if (!-f $tzinfo);
-
- ($timezone) = $timezone =~ m/^(.*)$/; # untaint
-
- print $fh "$timezone\n";
-
- unlink("/etc/localtime");
- symlink("/usr/share/zoneinfo/$timezone", "/etc/localtime");
-
-}
-
-register_file('timezone', "/etc/timezone", \&read_etc_timezone, \&write_etc_timezone);
-
sub read_active_workers {
my ($filename, $fh) = @_;
diff --git a/src/PVE/Systemd.pm b/src/PVE/Systemd.pm
index 6ff0dc8..aabb774 100644
--- a/src/PVE/Systemd.pm
+++ b/src/PVE/Systemd.pm
@@ -10,7 +10,8 @@ use Net::DBus::Reactor;
use POSIX qw(EINTR);
use Socket qw(SOCK_DGRAM);
-use PVE::Tools qw(file_set_contents file_get_contents trim);
+use PVE::Exception qw(raise_param_exc);
+use PVE::Tools qw(file_set_contents file_get_contents run_command trim);
sub escape_unit {
my ($val, $is_path) = @_;
@@ -285,6 +286,38 @@ sub write_ini {
file_set_contents($filename, $content);
}
+# Use systemds timedatectl for managing timezone settings
+sub get_timezone {
+ my $timezone;
+
+ PVE::Tools::run_command(
+ ['timedatectl', 'show', '--property=Timezone', '--value'],
+ outfunc => sub { $timezone //= shift },
+ );
+
+ return $timezone;
+}
+
+sub set_timezone {
+ my ($timezone) = @_;
+
+ raise_param_exc({ 'timezone' => "No such timezone" })
+ if (!grep { $_ eq $timezone } list_timezones());
+
+ PVE::Tools::run_command(['timedatectl', 'set-timezone', $timezone]);
+}
+
+sub list_timezones {
+ my @timezones = ();
+
+ PVE::Tools::run_command(
+ ['timedatectl', 'list-timezones'],
+ outfunc => sub { push(@timezones, shift); },
+ );
+
+ return @timezones;
+}
+
=head3 notify()
This is a pure Perl reimplementation of systemd's C<sd_notify()> mechanism as defined in
--
2.34.1
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
prev parent reply other threads:[~2026-01-25 21:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-25 21:01 [pve-devel] [PATCH common, container, manager and pmg-api v2 0/4] " Stefan Mayr
2026-01-25 21:01 ` [pve-devel] [PATCH manager v2 1/4] " Stefan Mayr
2026-01-25 21:01 ` [pve-devel] [PATCH container v2 2/4] " Stefan Mayr
2026-01-25 21:01 ` [pve-devel] [PATCH pmg-api v2 3/4] " Stefan Mayr
2026-01-25 21:01 ` Stefan Mayr [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260125210151.1151-5-stefan@mayr-stefan.de \
--to=stefan@mayr-stefan.de \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox