if (!ref($cmd)) {
$cmdstr = $cmd;
- if ($cmd =~ m/|/) {
+ if ($cmd =~ m/\|/) {
# see 'man bash' for option pipefail
$cmd = [ '/bin/bash', '-c', "set -o pipefail && $cmd" ];
} else {
LocalPort => $p,
ReuseAddr => 1,
Family => $family,
- Proto => 0);
+ Proto => 0,
+ GetAddrInfoFlags => 0);
if ($sock) {
close($sock);
return ($count, $lines);
}
+sub dump_journal {
+ my ($start, $limit, $filter) = @_;
+
+ my $lines = [];
+ my $count = 0;
+
+ $start = 0 if !$start;
+ $limit = 50 if !$limit;
+
+ my $parser = sub {
+ my $line = shift;
+
+ return if $count++ < $start;
+ return if $limit <= 0;
+ push @$lines, { n => int($count), t => $line};
+ $limit--;
+ };
+
+ my $cmd = ['journalctl', '-o', 'short', '--no-pager'];
+ run_command($cmd, outfunc => $parser);
+
+ # HACK: ExtJS store.guaranteeRange() does not like empty array
+ # so we add a line
+ if (!$count) {
+ $count++;
+ push @$lines, { n => $count, t => "no content"};
+ }
+
+ return ($count, $lines);
+}
+
sub dir_glob_regex {
my ($dir, $regex) = @_;
return ($family, $port, $host);
}
-sub get_host_address_family {
- my ($hostname, $socktype) = @_;
+sub getaddrinfo_all {
+ my ($hostname, @opts) = @_;
my %hints = ( flags => AI_V4MAPPED | AI_ALL,
- socktype => $socktype );
+ @opts );
my ($err, @res) = Socket::getaddrinfo($hostname, '0', \%hints);
- die "failed to resolve $hostname: $err\n" if $err;
+ die "failed to get address info for: $hostname: $err\n" if $err;
+ return @res;
+}
- return ${res[0]}->{family};
+sub get_host_address_family {
+ my ($hostname, $socktype) = @_;
+ my @res = getaddrinfo_all($hostname, socktype => $socktype);
+ return $res[0]->{family};
}
1;