From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id CAE3E1FF0DF for ; Fri, 28 Aug 2026 15:31:02 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 80D49215E5; Fri, 28 Aug 2026 15:30:40 +0200 (CEST) From: Shannon Sterz To: pve-devel@lists.proxmox.com Subject: [PATCH common 05/21] systemd: move parse_os_release() helper to PVE::Systemd Date: Fri, 28 Aug 2026 15:30:14 +0200 Message-ID: <20260828133030.351140-6-s.sterz@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260828133030.351140-1-s.sterz@proxmox.com> References: <20260828133030.351140-1-s.sterz@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1787923824335 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.935 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: 57GOFPFL2P4LB4BE5Z3J7KWKG3CZU3LI X-Message-ID-Hash: 57GOFPFL2P4LB4BE5Z3J7KWKG3CZU3LI X-MailFrom: s.sterz@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: to avoid implementing such a parser multiple times. Signed-off-by: Shannon Sterz --- src/PVE/Systemd.pm | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/PVE/Systemd.pm b/src/PVE/Systemd.pm index 1ed5271..8a75ad3 100644 --- a/src/PVE/Systemd.pm +++ b/src/PVE/Systemd.pm @@ -365,4 +365,42 @@ sub notify { return; } +=head3 parse_os_release() + +Allows parsing an C file as defined by C. + +=cut + +# os-release(5): +# (...) a newline-separated list of environment-like shell-compatible +# variable assignments. (...) beyond mere variable assignments, no shell +# features are supported (this means variable expansion is explicitly not +# supported) (...). Variable assignment values must be enclosed in double or +# single quotes *if* they include spaces, semicolons or other special +# characters outside of A-Z, a-z, 0-9. Shell special characters ("$", quotes, +# backslash, backtick) must be escaped with backslashes (...). All strings +# should be in UTF-8 format, and non-printable characters should not be used. +# It is not supported to concatenate multiple individually quoted strings. +# Lines beginning with "#" shall be ignored as comments. +sub parse_os_release { + my ($data) = @_; + my $variables = {}; + while (defined($data) && $data =~ /^(.+)$/gm) { + next if $1 !~ /^\s*([a-zA-Z_][a-zA-Z0-9_]*)=(.*)$/; + my ($var, $content) = ($1, $2); + chomp $content; + + if ($content =~ /^'([^']*)'/) { + $variables->{$var} = $1; + } elsif ($content =~ /^"((?:[^"\\]|\\.)*)"/) { + my $s = $1; + $s =~ s/(\\["'`nt\$\\])/"\"$1\""/eeg; + $variables->{$var} = $s; + } elsif ($content =~ /^([A-Za-z0-9]*)/) { + $variables->{$var} = $1; + } + } + return $variables; +} + 1; -- 2.47.3