From: Stefan Mayr <stefan@mayr-stefan.de>
To: pve-devel@lists.proxmox.com
Subject: [PATCH common v3 1/2] Fix #7175: replace timezone handling with systemd timedatectl
Date: Sun, 22 Feb 2026 12:02:04 +0100 [thread overview]
Message-ID: <20260222110205.582-2-stefan@mayr-stefan.de> (raw)
In-Reply-To: <20260220124809.076116bb@rosa.proxmox.com>
Usage of /etc/timezone is deprecated. The tzdata maintainers recommend
switching to timedatectl.
This adds timezone handling to the Systemd module and marks the
functions in the INotify module as deprecated.
Suggested-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Suggested-by: Maximiliano Sandroval <m.sandoval@proxmox.com>
Tested-by: Stoiko Ivanov <s.ivanov@proxmox.com>
Reviewed-by: Stoiko Ivanov <s.ivanov@proxmox.com>
Signed-off-by: Stefan Mayr <stefan@mayr-stefan.de>
---
src/PVE/INotify.pm | 2 ++
src/PVE/Systemd.pm | 35 ++++++++++++++++++++++++++++++++++-
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm
index 62b3ca8..fdec8f1 100644
--- a/src/PVE/INotify.pm
+++ b/src/PVE/INotify.pm
@@ -651,6 +651,7 @@ register_file(
\&update_etc_resolv_conf,
);
+# Deprecated: use PVE::Systemd::get_timezone() instead
sub read_etc_timezone {
my ($filename, $fd) = @_;
@@ -661,6 +662,7 @@ sub read_etc_timezone {
return $timezone;
}
+# Deprecated: use PVE::Systemd::set_timezone($timezone) instead
sub write_etc_timezone {
my ($filename, $fh, $timezone) = @_;
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
next prev parent reply other threads:[~2026-02-22 11:02 UTC|newest]
Thread overview: 12+ 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 ` [pve-devel] [PATCH common v2 4/4] " Stefan Mayr
2026-02-18 19:53 ` [pve-devel] [PATCH common, container, manager and pmg-api v2 0/4] " Stefan Mayr
2026-02-19 8:13 ` Fabian Grünbichler
2026-02-20 11:48 ` Stoiko Ivanov
2026-02-22 11:02 ` [PATCH common v3 0/2] " Stefan Mayr
2026-02-23 10:02 ` Stoiko Ivanov
2026-02-22 11:02 ` Stefan Mayr [this message]
2026-02-22 11:02 ` [PATCH common v3 2/2] " Stefan Mayr
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=20260222110205.582-2-stefan@mayr-stefan.de \
--to=stefan@mayr-stefan.de \
--cc=pve-devel@lists.proxmox.com \
--cc=s.ivanov@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.