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 1a9f11c commit 8eca39d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 3 deletions.
16 changes: 15 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 @@ -106,6 +113,13 @@ sub files {
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 ();
}

# get original ARGV
(my $bin, local @ARGV) = nr_parse_cmd($pid);

Expand Down
16 changes: 15 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 @@ -137,6 +144,13 @@ sub files {
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 ();
}

# get original ARGV
(my $bin, local @ARGV) = nr_parse_cmd($pid);

Expand Down
16 changes: 15 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 @@ -134,6 +141,13 @@ sub files {
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 ();
}

# get original ARGV
(my $bin, local @ARGV) = nr_parse_cmd($pid);

Expand Down

0 comments on commit 8eca39d

Please sign in to comment.