aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorCarlo von lynX <lynX@time.to.get.psyced.org>2016-05-31 17:00:55 +0000
committerCarlo von lynX <lynX@time.to.get.psyced.org>2016-05-31 17:00:55 +0000
commit1be4eb49815a40fd5de052b2f7ceef7b99c4e08d (patch)
tree377b0d1d78b6de01dc50550b2000f20a751c15be /contrib
parent91f664dddcbec3f1e337852b52e7faa459e2ab57 (diff)
downloadgnunet-1be4eb49815a40fd5de052b2f7ceef7b99c4e08d.tar.gz
gnunet-1be4eb49815a40fd5de052b2f7ceef7b99c4e08d.zip
taught gnunet-logread to also do what gnunet-logread-ipc used to do
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/gnunet-logread48
-rwxr-xr-xcontrib/gnunet-logread-ipc2
2 files changed, 33 insertions, 17 deletions
diff --git a/contrib/gnunet-logread b/contrib/gnunet-logread
index 1a3650d79..6205f4123 100755
--- a/contrib/gnunet-logread
+++ b/contrib/gnunet-logread
@@ -4,25 +4,28 @@
4 4
5use strict; 5use strict;
6use warnings; 6use warnings;
7my $DEFAULT_SOCKET = '/tmp/gnunet-logread-ipc.sock';
7 8
8use Getopt::Std; 9use Getopt::Std;
9my (%opts, $name, $ipc, $msg_level, $msg_regex); 10my (%opts, $name, $ipc, $msg_level, $msg_regex);
10getopts ('i:x:n:s:L:m:h', \%opts); 11getopts ('i:x:n:s:L:m:fh', \%opts);
11 12
12die <<X if $opts{h}; 13die <<X if $opts{h};
13Usage: 14Usage:
14 <gnunet-service> |& $0 [<options>] 15 <gnunet-service> |& $0 [<options>]
15 or 16 or
16 $0 [<options>] <service.log> 17 $0 [<options>] [<logfile>]
17 18
18Options: 19Options:
20 -f Follow input from IPC FIFO socket.
21
19 Regular screen output options: 22 Regular screen output options:
20 -i <regex> Include only messages that match regex. 23 -i <regex> Include only messages that match <regex>.
21 -x <regex> Exclude all messages that match regex. 24 -x <regex> Exclude all messages that match <regex>.
22 25
23 Options to enable message passing to IPC socket: 26 Options to enable message passing to IPC socket:
24 -n <component_name> Name of this component to use for IPC logging. 27 -n <component_name> Name of this component to use for IPC logging.
25 -s </path/to/ipc.sock> Path to IPC logging socket. 28 -s </path/to/ipc.sock> Default = $DEFAULT_SOCKET
26 -L <LOGLEVEL> Minimum level of messages to pass on. 29 -L <LOGLEVEL> Minimum level of messages to pass on.
27 Log levels: NONE, ERROR, WARNING, INFO, DEBUG. 30 Log levels: NONE, ERROR, WARNING, INFO, DEBUG.
28 -m <regex> Only pass messages matching a regular expression. 31 -m <regex> Only pass messages matching a regular expression.
@@ -35,6 +38,7 @@ $Term::ANSIColor::AUTOLOCAL = 1;
35my %msgtypes; 38my %msgtypes;
36my $prefix = $ENV{GNUNET_PREFIX} || '/usr'; 39my $prefix = $ENV{GNUNET_PREFIX} || '/usr';
37my $filename = "$prefix/include/gnunet/gnunet_protocols.h"; 40my $filename = "$prefix/include/gnunet/gnunet_protocols.h";
41$ipc = $opts{s} || $DEFAULT_SOCKET;
38 42
39if (open HEADER, $filename) 43if (open HEADER, $filename)
40{ 44{
@@ -56,17 +60,28 @@ X
56my %levels = ( NONE => 0, ERROR => 1, WARNING => 2, INFO => 4, DEBUG => 8 ); 60my %levels = ( NONE => 0, ERROR => 1, WARNING => 2, INFO => 4, DEBUG => 8 );
57if (exists $opts{n}) 61if (exists $opts{n})
58{ 62{
63 die "You can't read and write the socket at the same time" if exists $opts{f};
59 $name = $opts{n}; 64 $name = $opts{n};
60 $ipc = $opts{s} || '/tmp/gnunet-logread-ipc.sock'; 65 $msg_level = $opts{L} && exists $levels{$opts{L}} ? $levels{$opts{L}} : 0;
61 $msg_level = exists $levels{$opts{L}} ? $levels{$opts{L}} : 0;
62 $msg_regex = $opts{m}; 66 $msg_regex = $opts{m};
63 print STDERR "RE: /$msg_regex/\n" if defined $msg_regex; 67 print STDERR "RE: /$msg_regex/\n" if defined $msg_regex;
64 open IPC, '>', $ipc or die "$ipc: $!\n"; 68 open O, '>', $ipc or die "Cannot write to $ipc: $!";
65} 69}
66 70
67while (<>) 71if (exists $opts{f}) {
68{ 72 system('/bin/mkfifo', $ipc) unless -r $ipc;
69 if (fileno IPC) { 73 open(I, $ipc) or die "Cannot read from $ipc: $!";
74 &perform while <I>;
75 close I;
76} else {
77 &perform while <>;
78}
79fileno O and close O;
80exit;
81
82
83sub perform {
84 if (fileno O) {
70 my ($time, $type, $size, $from, $to, $level, $msg); 85 my ($time, $type, $size, $from, $to, $level, $msg);
71 if (($time, $type, $size, $from, $to) = 86 if (($time, $type, $size, $from, $to) =
72 /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)\ util-.*\b 87 /^([A-Z][a-z]{2}\ .[0-9]\ [0-9:]{8}(?:-[0-9]{6})?)\ util-.*\b
@@ -81,8 +96,8 @@ while (<>)
81 my ($time, $type, $size, $from, $to) = ($1, $2, $3, 96 my ($time, $type, $size, $from, $to) = ($1, $2, $3,
82 $4 || $name, $5 || $name); 97 $4 || $name, $5 || $name);
83 my $msg = exists $msgtypes{$type} ? $msgtypes{$type} : $type; 98 my $msg = exists $msgtypes{$type} ? $msgtypes{$type} : $type;
84 my $ofh = select IPC; 99 my $ofh = select O;
85 print IPC "$time\t$from -> $to\t$msg ($size)\n"; 100 print O "$time\t$from -> $to\t$msg ($size)\n";
86 $| = 1; 101 $| = 1;
87 select $ofh; 102 select $ofh;
88 } 103 }
@@ -93,11 +108,11 @@ while (<>)
93 && $levels{$level} <= $msg_level 108 && $levels{$level} <= $msg_level
94 && (!defined $msg_regex || $msg =~ /$msg_regex/i))) 109 && (!defined $msg_regex || $msg =~ /$msg_regex/i)))
95 { 110 {
96 print IPC "$time\t$name\t$level: $msg\n"; 111 print O "$time\t$name\t$level: $msg\n";
97 } 112 }
98 } 113 }
99 next if $opts{x} and /$opts{x}/io; 114 return if $opts{x} and /$opts{x}/io;
100 next if $opts{i} and not /$opts{i}/io; 115 return if $opts{i} and not /$opts{i}/io;
101 116
102 # Timestamp (e.g. Nov 01 19:36:11-384136) 117 # Timestamp (e.g. Nov 01 19:36:11-384136)
103 s/^([A-Z][a-z]{2} .[0-9] [0-9:]{8}(?:-[0-9]{6})?)/YELLOW $1/e; 118 s/^([A-Z][a-z]{2} .[0-9] [0-9:]{8}(?:-[0-9]{6})?)/YELLOW $1/e;
@@ -123,4 +138,3 @@ while (<>)
123 print; 138 print;
124} 139}
125 140
126fileno IPC and close IPC;
diff --git a/contrib/gnunet-logread-ipc b/contrib/gnunet-logread-ipc
index 24de434c2..77515d890 100755
--- a/contrib/gnunet-logread-ipc
+++ b/contrib/gnunet-logread-ipc
@@ -1,6 +1,8 @@
1#!/bin/sh 1#!/bin/sh
2# 2#
3# Usage: gnunet-logread-ipc | gnunet-logread 3# Usage: gnunet-logread-ipc | gnunet-logread
4#
5# ... obsoleted by gnunet-logread's new -f option that does the same thing
4 6
5ipc=${1:-/tmp/gnunet-logread-ipc.sock} 7ipc=${1:-/tmp/gnunet-logread-ipc.sock}
6test -e "$ipc" || mkfifo "$ipc" 8test -e "$ipc" || mkfifo "$ipc"