silence lsof errors
[mirror/dsa-nagios.git] / dsa-nagios-checks / checks / dsa-check-libs
index 89d7f3a..aaaf1ee 100755 (executable)
@@ -53,6 +53,7 @@ if (!GetOptions (
        '--version'     => \$params->{'version'},
        '--quiet'       => \$params->{'quiet'},
        '--verbose'     => \$params->{'verbose'},
+       '-v'            => \$params->{'verbose'},
        '--config=s'    => \$params->{'config'},
        )) {
        dief ("$PROGRAM_NAME: Usage: $PROGRAM_NAME [--help|--version] [--verbose] [--quiet] [--config=<CONFIGFILE>]\n");
@@ -142,7 +143,7 @@ sub inVserver() {
 my $INVSERVER = inVserver();
 
 print STDERR "Running $LSOF -n\n" if $params->{'verbose'};
-open (LSOF, "$LSOF -n|") or dief ("Cannot run $LSOF -n: $!\n");
+open (LSOF, "$LSOF -n 2>/dev/null|") or dief ("Cannot run $LSOF -n: $!\n");
 my @lsof=<LSOF>;
 close LSOF;
 if ($CHILD_ERROR) { # program failed
@@ -170,6 +171,10 @@ LINE: for my $line (@lsof)  {
        my $inode = $fields{i};
        my $path  = $fields{n};
        if ($path =~ m/\.dpkg-/ || $path =~ m/\(deleted\)/ || $path =~ /path inode=/ || $path =~ m#/\.nfs# || $fd eq 'DEL') {
+               my $deleted_in_path = ($path =~ m/\(deleted\)/ || $path =~ m/\.nfs/);
+               next if ($deleted_in_path && $fd =~ /^[0-9]*$/); # Ignore deleted files that are open via normal file handles.
+               next if ($deleted_in_path && $fd eq 'cwd'); # Ignore deleted directories that we happen to be in.
+
                $path =~ s/^\(deleted\)//; # in some cases "(deleted)" is at the beginning of the string
                for my $i (@{$config->{'ignorelist'}}) {
                        my $ignore = eval($i);