From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 4C9B31FF0B3 for ; Thu, 26 Nov 2026 14:42:00 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 22BD82173B; Thu, 26 Nov 2026 14:41:52 +0100 (CET) From: Jonas Theisen To: pve-devel@lists.proxmox.com Subject: [PATCH common 02/16] systemd: add helper to query clock synchronization status Date: Thu, 26 Nov 2026 14:39:59 +0100 Message-ID: <20261126134128.316681-3-j.theisen@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261126134128.316681-1-j.theisen@proxmox.com> References: <20261126134128.316681-1-j.theisen@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795700502404 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.071 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: F4SCNKSZE7JTW2X4X4V7GBIQBN76N52D X-Message-ID-Hash: F4SCNKSZE7JTW2X4X4V7GBIQBN76N52D X-MailFrom: j.theisen@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Expose whether the kernel considers the system clock synchronized, the same information timedatectl shows as "System clock synchronized". Querying the kernel state via timedatectl works independently of the time synchronization service in use, so it also covers services whose NTP servers cannot be configured through the Proxmox helpers. Signed-off-by: Jonas Theisen --- src/PVE/Systemd.pm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/PVE/Systemd.pm b/src/PVE/Systemd.pm index abd3c61..35554ce 100644 --- a/src/PVE/Systemd.pm +++ b/src/PVE/Systemd.pm @@ -320,6 +320,17 @@ sub list_timezones { return @timezones; } +sub is_clock_synchronized { + my $synchronized; + + run( + ['timedatectl', 'show', '--property=NTPSynchronized', '--value'], + outfunc => sub { $synchronized //= shift }, + ); + + return defined($synchronized) && $synchronized eq 'yes' ? 1 : 0; +} + my $ntp_lock_file = '/var/lock/proxmox-ntp.lck'; my $chrony_conf = '/etc/chrony/chrony.conf'; my $chrony_sources = '/etc/chrony/sources.d/proxmox.sources'; -- 2.47.3