Created
September 10, 2010 12:05
-
-
Save kamipo/573517 to your computer and use it in GitHub Desktop.
socketpair
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Socket; | |
use IO::Handle; | |
my @callback; | |
for my $host (@ARGV) { | |
socketpair(my $child, my $parent, AF_UNIX, SOCK_STREAM, PF_UNSPEC) | |
or die $!; | |
$child->autoflush(1); | |
$parent->autoflush(1); | |
if (my $pid = fork) { | |
close $parent; | |
push @callback, sub { | |
local $/ = undef; | |
chomp(my $line = <$child>); | |
print "$host: $line"; | |
close $child; | |
waitpid($pid, 0); | |
}; | |
} elsif (defined $pid) { | |
close $child; | |
close STDOUT; | |
open STDOUT, '>&' . fileno($parent); | |
close $parent; | |
exec "squidclient -h $host -p 8080 mgr:5min | grep 'syscalls.sock.writes'"; | |
exit; | |
} else { | |
die $!; | |
} | |
} | |
$_->() for @callback; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment