From 4e020cb5583dfce89d110935912cce084dbed9c7 Mon Sep 17 00:00:00 2001 From: Thomas Liske Date: Sun, 15 Jan 2017 19:46:40 +0100 Subject: [PATCH] [Interp] Make paths when searching source files relative to the root path of the process (closes #54 by Tomasz Kontusz @ktosiek). --- ChangeLog | 3 +++ perl/lib/NeedRestart/Interp/Java.pm | 2 +- perl/lib/NeedRestart/Interp/Perl.pm | 6 +++--- perl/lib/NeedRestart/Interp/Python.pm | 8 ++++---- perl/lib/NeedRestart/Interp/Ruby.pm | 8 ++++---- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index be262d72..c72d2884 100644 --- a/ChangeLog +++ b/ChangeLog @@ -20,6 +20,9 @@ needrestart (2.11) unstable; urgency=medium (Debian Bug#844283 by Paul Wise ) - [Core] Add display-manager 'lxdm' to override. (Debian Bug#845996 by Rodrigo Campos ) + - [Interp] Make paths when searching source files relative to the root + path of the process. + (github issue #54 by Tomasz Kontusz @ktosiek) -- Thomas Liske diff --git a/perl/lib/NeedRestart/Interp/Java.pm b/perl/lib/NeedRestart/Interp/Java.pm index d52ddc4f..6c41cf3e 100644 --- a/perl/lib/NeedRestart/Interp/Java.pm +++ b/perl/lib/NeedRestart/Interp/Java.pm @@ -55,7 +55,7 @@ sub files { my $pid = shift; my %ret = map { - my $stat = nr_stat($_); + my $stat = nr_stat("/proc/$pid/root/$_"); $_ => ( defined($stat) ? $stat->{ctime} : undef ); } map { my $l = readlink; diff --git a/perl/lib/NeedRestart/Interp/Perl.pm b/perl/lib/NeedRestart/Interp/Perl.pm index 9ddcaf0c..ecc6dede 100644 --- a/perl/lib/NeedRestart/Interp/Perl.pm +++ b/perl/lib/NeedRestart/Interp/Perl.pm @@ -57,7 +57,7 @@ sub source { return (); } my $cwd = getcwd(); - chdir($ptable->{cwd}); + chdir("/proc/$pid/root/$ptable->{cwd}"); # get original ARGV (my $bin, local @ARGV) = nr_parse_cmd($pid); @@ -104,7 +104,7 @@ sub files { return (); } my $cwd = getcwd(); - chdir($ptable->{cwd}); + chdir("/proc/$pid/root/$ptable->{cwd}"); # get original ARGV (my $bin, local @ARGV) = nr_parse_cmd($pid); @@ -167,7 +167,7 @@ sub files { } my %ret = map { - my $stat = nr_stat($href->{$_}->{file}); + my $stat = nr_stat("/proc/$pid/root/$href->{$_}->{file}"); $href->{$_}->{file} => ( defined($stat) ? $stat->{ctime} : undef ); } keys %$href; diff --git a/perl/lib/NeedRestart/Interp/Python.pm b/perl/lib/NeedRestart/Interp/Python.pm index 1469d387..c0594898 100644 --- a/perl/lib/NeedRestart/Interp/Python.pm +++ b/perl/lib/NeedRestart/Interp/Python.pm @@ -88,7 +88,7 @@ sub source { return (); } my $cwd = getcwd(); - chdir($ptable->{cwd}); + chdir("/proc/$pid/root/$ptable->{cwd}"); # get original ARGV (my $bin, local @ARGV) = nr_parse_cmd($pid); @@ -135,7 +135,7 @@ sub files { return (); } my $cwd = getcwd(); - chdir($ptable->{cwd}); + chdir("/proc/$pid/root/$ptable->{cwd}"); # get original ARGV (my $bin, local @ARGV) = nr_parse_cmd($pid); @@ -198,7 +198,7 @@ sub files { chomp($path); $path =~ s/^\['//; $path =~ s/'\$//; - @path = split("', '", $path); + @path = map { "/proc/$pid/root/$_"; } split("', '", $path); } else { print STDERR "$LOGPREF #$pid: failed to retrieve include path\n" if($self->{debug}); @@ -208,7 +208,7 @@ sub files { _scan($self->{debug}, $pid, $src, \%files, \@path); my %ret = map { - my $stat = nr_stat($_); + my $stat = nr_stat("/proc/$pid/root/$_"); $_ => ( defined($stat) ? $stat->{ctime} : undef ); } keys %files; diff --git a/perl/lib/NeedRestart/Interp/Ruby.pm b/perl/lib/NeedRestart/Interp/Ruby.pm index e8ccbed0..58b4d01e 100644 --- a/perl/lib/NeedRestart/Interp/Ruby.pm +++ b/perl/lib/NeedRestart/Interp/Ruby.pm @@ -85,7 +85,7 @@ sub source { return (); } my $cwd = getcwd(); - chdir($ptable->{cwd}); + chdir("/proc/$pid/root/$ptable->{cwd}"); # get original ARGV (my $bin, local @ARGV) = nr_parse_cmd($pid); @@ -132,7 +132,7 @@ sub files { return (); } my $cwd = getcwd(); - chdir($ptable->{cwd}); + chdir("/proc/$pid/root/$ptable->{cwd}"); # get original ARGV (my $bin, local @ARGV) = nr_parse_cmd($pid); @@ -184,7 +184,7 @@ sub files { # get include path my $rbread = nr_fork_pipe($self->{debug}, $ptable->{exec}, '-e', 'puts $:'); - my @path = <$rbread>; + my @path = map { "/proc/$pid/root/$_"; } <$rbread>; close($rbread); chomp(@path); @@ -192,7 +192,7 @@ sub files { _scan($self->{debug}, $pid, $src, \%files, \@path); my %ret = map { - my $stat = nr_stat($_); + my $stat = nr_stat("/proc/$pid/root/$_"); $_ => ( defined($stat) ? $stat->{ctime} : undef ); } keys %files;