Package: needrestart / 3.4-5~bpo9+1

04-restore-cwd.diff Patch series | download
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
From 82a05944d7f77055539117da9e970ca515b14cd6 Mon Sep 17 00:00:00 2001
From: Thomas Liske <thomas@fiasko-nw.net>
Date: Sat, 13 Apr 2019 13:22:49 +0200
Subject: [PATCH] [Interp] Restore cwd when skipping processes with unavailable
 cwd (closes #147 by Stavros Ntentos @stdedos).

---
 perl/lib/NeedRestart/Interp/Perl.pm   | 10 +++++++++-
 perl/lib/NeedRestart/Interp/Python.pm | 10 +++++++++-
 perl/lib/NeedRestart/Interp/Ruby.pm   | 10 +++++++++-
 3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/perl/lib/NeedRestart/Interp/Perl.pm b/perl/lib/NeedRestart/Interp/Perl.pm
index ed43c1a..aebf8e5 100644
--- a/perl/lib/NeedRestart/Interp/Perl.pm
+++ b/perl/lib/NeedRestart/Interp/Perl.pm
@@ -54,11 +54,18 @@ sub source {
     my $ptable = nr_ptable_pid($pid);
     unless($ptable->{cwd}) {
 	print STDERR "$LOGPREF #$pid: could not get current working directory, skipping\n" if($self->{debug});
-	return ();
+	return undef;
     }
     my $cwd = getcwd();
     chdir("/proc/$pid/root/$ptable->{cwd}");
 
+    # skip the process if the cwd is unreachable (i.e. due to mnt ns)
+    unless(getcwd()) {
+	chdir($cwd);
+	print STDERR "$LOGPREF #$pid: process cwd is unreachable\n" if($self->{debug});
+	return undef;
+    }
+
     # get original ARGV
     (my $bin, local @ARGV) = nr_parse_cmd($pid);
 
@@ -108,6 +115,7 @@ sub files {
 
     # skip the process if the cwd is unreachable (i.e. due to mnt ns)
     unless(getcwd()) {
+	chdir($cwd);
 	print STDERR "$LOGPREF #$pid: process cwd is unreachable\n" if($self->{debug});
 	return ();
     }
diff --git a/perl/lib/NeedRestart/Interp/Python.pm b/perl/lib/NeedRestart/Interp/Python.pm
index 4b8719c..c2b94da 100644
--- a/perl/lib/NeedRestart/Interp/Python.pm
+++ b/perl/lib/NeedRestart/Interp/Python.pm
@@ -85,11 +85,18 @@ sub source {
     my $ptable = nr_ptable_pid($pid);
     unless($ptable->{cwd}) {
 	print STDERR "$LOGPREF #$pid: could not get current working directory, skipping\n" if($self->{debug});
-	return ();
+	return undef;
     }
     my $cwd = getcwd();
     chdir("/proc/$pid/root/$ptable->{cwd}");
 
+    # skip the process if the cwd is unreachable (i.e. due to mnt ns)
+    unless(getcwd()) {
+	chdir($cwd);
+	print STDERR "$LOGPREF #$pid: process cwd is unreachable\n" if($self->{debug});
+	return undef;
+    }
+
     # get original ARGV
     (my $bin, local @ARGV) = nr_parse_cmd($pid);
 
@@ -139,6 +146,7 @@ sub files {
 
     # skip the process if the cwd is unreachable (i.e. due to mnt ns)
     unless(getcwd()) {
+	chdir($cwd);
 	print STDERR "$LOGPREF #$pid: process cwd is unreachable\n" if($self->{debug});
 	return ();
     }
diff --git a/perl/lib/NeedRestart/Interp/Ruby.pm b/perl/lib/NeedRestart/Interp/Ruby.pm
index 31cddee..ba48552 100644
--- a/perl/lib/NeedRestart/Interp/Ruby.pm
+++ b/perl/lib/NeedRestart/Interp/Ruby.pm
@@ -82,11 +82,18 @@ sub source {
     my $ptable = nr_ptable_pid($pid);
     unless($ptable->{cwd}) {
 	print STDERR "$LOGPREF #$pid: could not get current working directory, skipping\n" if($self->{debug});
-	return ();
+	return undef;
     }
     my $cwd = getcwd();
     chdir("/proc/$pid/root/$ptable->{cwd}");
 
+    # skip the process if the cwd is unreachable (i.e. due to mnt ns)
+    unless(getcwd()) {
+	chdir($cwd);
+	print STDERR "$LOGPREF #$pid: process cwd is unreachable\n" if($self->{debug});
+	return undef;
+    }
+
     # get original ARGV
     (my $bin, local @ARGV) = nr_parse_cmd($pid);
 
@@ -136,6 +143,7 @@ sub files {
 
     # skip the process if the cwd is unreachable (i.e. due to mnt ns)
     unless(getcwd()) {
+	chdir($cwd);
 	print STDERR "$LOGPREF #$pid: process cwd is unreachable\n" if($self->{debug});
 	return ();
     }