sysdump: ignore files inside /sys/kernel/debug to avoid hanging
authorMichael Prokop <mika@grml.org>
Fri, 9 Jun 2017 20:08:03 +0000 (22:08 +0200)
committerMichael Prokop <mika@grml.org>
Fri, 9 Jun 2017 20:08:03 +0000 (22:08 +0200)
There are several files inside /sys/kernel/debug which aren't
safe for cat-ing, like for example
/sys/kernel/debug/hid/0003:80EE:0021.0001/events So ignore all
files inside /sys/kernel/debug to avoid a hanging sysdump
process.

While at it avoid read on already closed file-handle and redirect
error message to stderr if a file can't be opened/read.

Closes grml/grml#55

sysdump

diff --git a/sysdump b/sysdump
index 17c2b9f..177424c 100755 (executable)
--- a/sysdump
+++ b/sysdump
@@ -62,7 +62,15 @@ sub dump_value($$)
        my $level = shift;
        my $file = shift;
 
-       open (FILE, "<$file") || print "can't open $file: $!";
+       if ($file =~ "/sys/kernel/debug/.*") {
+               print("ignoring file $file\n");
+               return 0;
+       }
+
+       if (!open (FILE, "<$file")) {
+               print STDERR "can't open $file: '$!'\n";
+               return 0;
+       }
 
        my $value;
        {       local $/;