mytop
mytop copied to clipboard
Fix warning when gethostbyaddr did not return anything
I get the following error lots of times: Use of uninitialized value $host in substitution (s///) at ./mytop line 958.
This happens when gethostbyaddr returns null. In that case we should show the IP instead:
From 602d063dbac4ae94b2d2273ceef9fbf01f9ca1d9 Mon Sep 17 00:00:00 2001
From: Christoph Brill <[email protected]>
Date: Tue, 27 Aug 2013 16:11:13 +0200
Subject: [PATCH] If gethostbyaddr return nothing, keep using the IP
---
mytop | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/mytop b/mytop
index fba27fd..8d6bf42 100755
--- a/mytop
+++ b/mytop
@@ -955,8 +955,11 @@ sub GetData()
{
$thread->{Host} =~ s/:\d+$//;
my $host = gethostbyaddr(inet_aton($thread->{Host}), AF_INET);
- $host =~ s/^([^.]+).*/$1/;
- $thread->{Host} = $host;
+ if ($host)
+ {
+ $host =~ s/^([^.]+).*/$1/;
+ $thread->{Host} = $host;
+ }
}
## Fix possible undefs
--
1.8.4