From 038b0718b572932754f9e34dbed3bd2fbcc3fb74 Mon Sep 17 00:00:00 2001 From: Ivan Shapovalov Date: Fri, 19 Apr 2024 05:46:11 +0200 Subject: [PATCH] needrestart: hack: recognize services under `systemd --user` as units Ideally, we'd do something more reasonable, like treating them similarly to system services and maybe even offering to restart some of them or at the very least printing them in a format suitable for copy-pasting, but for now just replace the process name with the service name and save them under a separate key to hopefully distinguish them from other processes under `systemd --user`. --- needrestart | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/needrestart b/needrestart index 755ce20..7f6b635 100755 --- a/needrestart +++ b/needrestart @@ -676,9 +676,14 @@ if(defined($opt_l)) { push(@{ $sessions{$1}->{"session #$2"}->{ $ptable->{$pid}->{fname} } }, $pid); next; } + if($cgroup =~ m@/user\@(\d+)\.service(/.+)?/([^/]+\.service)$@) { + print STDERR "$LOGPREF #$pid part of user service: uid=$1 unit=$3\n" if($nrconf{verbosity} > 1); + push(@{ $sessions{$1}->{'user service'}->{ $3 } }, $pid); + next; + } if($cgroup =~ m@/user\@(\d+)\.service@) { - print STDERR "$LOGPREF #$pid part of user manager service: uid=$1\n" if($nrconf{verbosity} > 1); - push(@{ $sessions{$1}->{'user manager service'}->{ $ptable->{$pid}->{fname} } }, $pid); + print STDERR "$LOGPREF #$pid part of user manageruid=$1\n" if($nrconf{verbosity} > 1); + push(@{ $sessions{$1}->{'user manager'}->{ $ptable->{$pid}->{fname} } }, $pid); next; } if($cgroup =~ m@/machine.slice/machine.qemu(.*).scope@) {