public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Leo Nunner <l.nunner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v2 container] fix #4192: revamp check for systemd version
Date: Mon, 12 Sep 2022 14:25:39 +0200	[thread overview]
Message-ID: <20220912122539.85794-1-l.nunner@proxmox.com> (raw)

Instead of iterating through several folders, it might just be easier to
check the ldd output of /sbin/init and getting the version from there.
Furthermore, the regex for checking the version has been adapted so that
it's more precise.

Signed-off-by: Leo Nunner <l.nunner@proxmox.com>
---
This solution does actually feel cleaner than manually checking all the folders
every time.

 src/PVE/LXC/Setup/Base.pm | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/src/PVE/LXC/Setup/Base.pm b/src/PVE/LXC/Setup/Base.pm
index cc12914..44b88d9 100644
--- a/src/PVE/LXC/Setup/Base.pm
+++ b/src/PVE/LXC/Setup/Base.pm
@@ -514,19 +514,26 @@ sub clear_machine_id {
     }
 }
 
-# tries to guess the systemd (major) version based on the existence of
-# (/usr)?/lib/systemd/libsystemd-shared<version>.so. It was introduced in v231.
+# tries to guess the systemd (major) version based on the
+# libsystemd-shared<version>.so linked with /sbin/init
 sub get_systemd_version {
     my ($self) = @_;
 
-    my $sd_lib_dir = $self->ct_is_directory("/lib/systemd") ?
-	"/lib/systemd" : "/usr/lib/systemd";
-    my $libsd = PVE::Tools::dir_glob_regex($sd_lib_dir, "libsystemd-shared-.+\.so");
-    if (defined($libsd) && $libsd =~ /libsystemd-shared-(\d+)(?:\..*)?\.so/) {
-	return $1;
-    }
-
-    return undef;
+    my $version = undef;
+    PVE::Tools::run_command(
+	[
+	    'ldd',
+	    '/sbin/init'
+	],
+	outfunc => sub {
+	    my $line = shift;
+	    if ($line =~ /^\s*libsystemd-shared-(\d+)(?:\.[a-zA-Z0-9]*)?\.so/) {
+		$version = $1;
+	    }},
+	errmsg => "ldd on /sbin/init failed"
+    );
+
+    return $version;
 }
 
 sub unified_cgroupv2_support {
-- 
2.30.2





             reply	other threads:[~2022-09-12 12:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-12 12:25 Leo Nunner [this message]
2022-09-12 12:41 ` Fabian Grünbichler
2022-09-12 14:01   ` Thomas Lamprecht
2022-09-13  7:37     ` Fabian Grünbichler

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=20220912122539.85794-1-l.nunner@proxmox.com \
    --to=l.nunner@proxmox.com \
    --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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal