File: core-fix-regression-of-false-positives-for-processes.patch

package info (click to toggle)
needrestart 3.6-4%2Bdeb12u3
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 936 kB
  • sloc: perl: 3,371; sh: 277; makefile: 82
file content (49 lines) | stat: -rw-r--r-- 1,852 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
From: Thomas Liske <thomas@fiasko-nw.net>
Date: Wed, 27 Nov 2024 21:54:20 +0100
Subject: core: fix regression of false positives for processes running in
 chroot or mountns (#317)
Origin: https://github.com/liske/needrestart/commit/e17b5644aff0f9eaeb422af7013b9c88ffc44423
Bug-Debian: https://bugs.debian.org/1087918
Bug-Debian: https://bugs.debian.org/1088047
Bug-Debian: https://bugs.debian.org/1088012
Bug-Debian: https://bugs.debian.org/1087917
Bug-Debian: https://bugs.debian.org/1087958
Bug-Debian: https://bugs.debian.org/1087957
Bug: https://github.com/liske/needrestart/issues/317

---
 needrestart | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/needrestart b/needrestart
index 6b4fcf7ae0fe..d38f5456fa94 100755
--- a/needrestart
+++ b/needrestart
@@ -530,15 +530,21 @@ if(defined($opt_l)) {
 	# orphaned binary
 	$restart++ if (defined($exe) && $exe =~ s/ \(deleted\)$//);  # Linux
 	$restart++ if (defined($exe) && $exe =~ s/^\(deleted\)//);   # Linux VServer
-	$restart++ unless(defined($ptable->{$pid}->{exec}));
 	print STDERR "$LOGPREF #$pid uses obsolete binary $exe\n" if($restart && $nrconf{verbosity} > 1);
 
 	# ignore blacklisted binaries
 	next if(grep { $exe =~ /$_/; } @{$nrconf{blacklist}});
 
-	# Sync $exe with the initial value from Proc:ProcessTable to prevent race
+	# Sync $exe with the initial value from Proc::ProcessTable to prevent race
 	# conditions in later checks.
-	$exe = $ptable->{$pid}->{exec} if(defined($ptable->{$pid}->{exec}));
+	if(defined($ptable->{$pid}->{exec})) {
+	    $exe = $ptable->{$pid}->{exec};
+	}
+	# Proc::ProcessTable's exec field is undef if the file is not accessible in
+	# the root mountns, so the value of $exe is used instead.
+	else {
+	    $ptable->{$pid}->{exec} = $exe;
+	}
 
 	# read file mappings (Linux 2.0+)
 	unless($restart) {
-- 
2.45.2