Skip to content

Commit

Permalink
[Interp] Restore cwd when skipping processes with unavailable cwd (cl…
Browse files Browse the repository at this point in the history
…oses #147 by Stavros Ntentos @stdedos).
  • Loading branch information
liske committed Apr 13, 2019
1 parent 6504853 commit 82a0594
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
10 changes: 9 additions & 1 deletion perl/lib/NeedRestart/Interp/Perl.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 ();
}
Expand Down
10 changes: 9 additions & 1 deletion perl/lib/NeedRestart/Interp/Python.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 ();
}
Expand Down
10 changes: 9 additions & 1 deletion perl/lib/NeedRestart/Interp/Ruby.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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 ();
}
Expand Down

0 comments on commit 82a0594

Please sign in to comment.