2013-04-26 09:44:19 +00:00
|
|
|
#! @perl@ -w @perlFlags@
|
2006-07-19 16:49:59 +00:00
|
|
|
|
|
|
|
use strict;
|
2013-04-26 09:44:19 +00:00
|
|
|
use Nix::Utils;
|
2013-04-26 10:15:54 +00:00
|
|
|
use Nix::Config;
|
2006-07-19 16:49:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
sub readProc {
|
2013-04-26 09:44:19 +00:00
|
|
|
return unless -d "/proc";
|
|
|
|
|
|
|
|
opendir DIR, "/proc" or return;
|
2006-07-19 16:49:59 +00:00
|
|
|
|
|
|
|
foreach my $name (readdir DIR) {
|
|
|
|
next unless $name =~ /^\d+$/;
|
|
|
|
|
2013-04-26 09:44:19 +00:00
|
|
|
my $process = "/proc/$name";
|
2006-07-19 16:49:59 +00:00
|
|
|
|
|
|
|
my $target;
|
|
|
|
print "$target\n" if $target = readlink "$process/exe";
|
|
|
|
print "$target\n" if $target = readlink "$process/cwd";
|
|
|
|
|
|
|
|
if (opendir FDS, "$process/fd") {
|
|
|
|
foreach my $name (readdir FDS) {
|
|
|
|
$target = readlink "$process/fd/$name";
|
|
|
|
print "$target\n" if $target && substr($target, 0, 1) eq "/";
|
|
|
|
}
|
|
|
|
closedir FDS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (open MAP, "<$process/maps") {
|
|
|
|
while (<MAP>) {
|
|
|
|
next unless /^ \s* \S+ \s+ \S+ \s+ \S+ \s+ \S+ \s+ \S+ \s+ (\/\S+) \s* $/x;
|
|
|
|
print "$1\n";
|
|
|
|
}
|
|
|
|
close MAP;
|
|
|
|
}
|
2013-04-26 10:06:39 +00:00
|
|
|
|
|
|
|
# Get all store paths that appear in the environment of this process.
|
2013-12-20 12:31:31 +00:00
|
|
|
my $re = "\Q$Nix::Config::storeDir\E\/[0-9a-z]+[0-9a-zA-Z\+\-\._\?=]*";
|
2013-04-26 10:06:39 +00:00
|
|
|
eval {
|
|
|
|
my $env = Nix::Utils::readFile "$process/environ";
|
2013-12-20 12:31:31 +00:00
|
|
|
my @matches = $env =~ /$re/g;
|
2013-04-26 10:06:39 +00:00
|
|
|
print "$_\n" foreach @matches;
|
2013-12-20 12:31:31 +00:00
|
|
|
};
|
|
|
|
eval {
|
|
|
|
my $cmdline = Nix::Utils::readFile "$process/cmdline";
|
|
|
|
my @matches = $cmdline =~ /$re/g;
|
|
|
|
print "$_\n" foreach @matches;
|
|
|
|
};
|
2006-07-19 16:49:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
closedir DIR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub lsof {
|
2006-09-20 15:14:19 +00:00
|
|
|
return unless open LSOF, "lsof -n -w -F n 2> /dev/null |";
|
2006-07-19 16:49:59 +00:00
|
|
|
|
|
|
|
while (<LSOF>) {
|
|
|
|
next unless /^n (\/ .*)$/x;
|
|
|
|
print $1, "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
close LSOF;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
readProc;
|
|
|
|
lsof;
|
2007-03-20 11:13:15 +00:00
|
|
|
|
|
|
|
|
2013-04-26 09:44:19 +00:00
|
|
|
sub printFile {
|
|
|
|
my ($fn) = @_;
|
|
|
|
if (-e $fn) {
|
|
|
|
print Nix::Utils::readFile($fn), "\n";
|
2007-03-20 11:13:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-26 09:44:19 +00:00
|
|
|
|
2007-03-20 11:13:15 +00:00
|
|
|
# This is rather NixOS-specific, so it probably shouldn't be here.
|
2013-04-26 09:44:19 +00:00
|
|
|
printFile "/proc/sys/kernel/modprobe";
|
|
|
|
printFile "/proc/sys/kernel/fbsplash";
|
|
|
|
printFile "/proc/sys/kernel/poweroff_cmd";
|