From 938092a21341b69604e9da6294fe76c13d6a1c07 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 26 Apr 2013 11:44:19 +0200 Subject: [PATCH] find-runtime-roots.pl: Use Nix::Utils::readFile --- scripts/find-runtime-roots.pl.in | 34 ++++++++++++++------------------ 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/scripts/find-runtime-roots.pl.in b/scripts/find-runtime-roots.pl.in index 64c17419ff..a53cefd4ef 100755 --- a/scripts/find-runtime-roots.pl.in +++ b/scripts/find-runtime-roots.pl.in @@ -1,22 +1,21 @@ -#! @perl@ -w +#! @perl@ -w @perlFlags@ use strict; - -my $procDir = "/proc"; +use Nix::Utils; sub readProc { - return unless -d $procDir; + return unless -d "/proc"; + + opendir DIR, "/proc" or return; - opendir DIR, $procDir or return; - foreach my $name (readdir DIR) { next unless $name =~ /^\d+$/; - my $process = "$procDir/$name"; + my $process = "/proc/$name"; #print STDERR "=== $process\n"; - + my $target; print "$target\n" if $target = readlink "$process/exe"; print "$target\n" if $target = readlink "$process/cwd"; @@ -58,18 +57,15 @@ readProc; lsof; -sub readFile { - my $path = shift; - if (-e $path) { - if (open FILE, "$path") { - while () { - print; - } - close FILE; - } +sub printFile { + my ($fn) = @_; + if (-e $fn) { + print Nix::Utils::readFile($fn), "\n"; } } + # This is rather NixOS-specific, so it probably shouldn't be here. -readFile "/proc/sys/kernel/modprobe"; -readFile "/proc/sys/kernel/fbsplash"; +printFile "/proc/sys/kernel/modprobe"; +printFile "/proc/sys/kernel/fbsplash"; +printFile "/proc/sys/kernel/poweroff_cmd";