From 8465c3eb9774ac2a07c8d1dd99a75c2bfdd10aa7 Mon Sep 17 00:00:00 2001 From: Trent Lloyd Date: Thu, 10 Mar 2022 15:11:42 +0800 Subject: [PATCH] Fix LXC/LXD and machined detection for cgroups v2 The second field is always blank in cgroups v2 unlike v1, adjust parsing to support both cases for LXC/LXD and machined. This is the same fix as previously made for Docker in #234. Example: 0::/lxc.payload.focal/system.slice/avahi-daemon.service --- perl/lib/NeedRestart/CONT/LXC.pm | 2 +- perl/lib/NeedRestart/CONT/machined.pm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/perl/lib/NeedRestart/CONT/LXC.pm b/perl/lib/NeedRestart/CONT/LXC.pm index 3f522ae..4542f5b 100644 --- a/perl/lib/NeedRestart/CONT/LXC.pm +++ b/perl/lib/NeedRestart/CONT/LXC.pm @@ -81,7 +81,7 @@ sub check { } # look for LXC cgroups - return unless($cg =~ /^\d+:[^:]+:\/lxc(?:.payload)?[.\/]([^\/\n]+)($|\/)/m); + return unless($cg =~ /^\d+:[^:]*:\/lxc(?:.payload)?[.\/]([^\/\n]+)($|\/)/m); my $name = $1; my $type = ($self->{has_lxd} && -d qq($self->{lxd_container_path}/$name) ? 'LXD' : 'LXC'); diff --git a/perl/lib/NeedRestart/CONT/machined.pm b/perl/lib/NeedRestart/CONT/machined.pm index c86ac48..bdeb5ec 100644 --- a/perl/lib/NeedRestart/CONT/machined.pm +++ b/perl/lib/NeedRestart/CONT/machined.pm @@ -68,7 +68,7 @@ sub check { } # look for machined cgroups - return 0 unless($cg =~ /^\d+:[^:]+:\/machine.slice\/machine-(.+)\.scope$/m); + return 0 unless($cg =~ /^\d+:[^:]*:\/machine.slice\/machine-(.+)\.scope$/m); my $name = $1; unless($norestart) {