summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Steven Schubiger <stsc@refcnt.org> 2013-09-03 22:46:21 +0200
committerGravatar Steven Schubiger <stsc@refcnt.org> 2013-09-03 22:46:21 +0200
commit577cd6cddb2b1d6bfa21d682308fde6493d9dab6 (patch)
tree250200ca8f10ef53d45cf6fad3faf27819e67054
parent16d993ce5bfa2fe1cf6000aa757bd6cca7e7e750 (diff)
downloaddistdns-577cd6cddb2b1d6bfa21d682308fde6493d9dab6.tar.gz
distdns-577cd6cddb2b1d6bfa21d682308fde6493d9dab6.tar.bz2
Indicate client/server for error messages
-rwxr-xr-xclient.pl14
-rwxr-xr-xserver.cgi6
2 files changed, 11 insertions, 9 deletions
diff --git a/client.pl b/client.pl
index 86ff3d9..9992c9d 100755
--- a/client.pl
+++ b/client.pl
@@ -36,6 +36,8 @@ my $VERSION = '0.05';
my $conf_file = catfile($Bin, 'client.conf');
+sub _die { die "$0: [client] $_[0]" }
+
sub usage
{
print <<"USAGE";
@@ -58,13 +60,13 @@ my $get_config_opts = sub
{
my ($section, $options) = @_;
- die "$0: Section $section missing in $conf_file\n" unless exists $config->{$section};
+ _die "Section $section missing in $conf_file\n" unless exists $config->{$section};
my %options;
@options{@$options} = @{$config->{$section}}{@$options};
foreach my $option (@$options) {
- die "$0: Option $option not set in $conf_file\n" unless defined $options{$option} && length $options{$option};
+ _die "Option $option not set in $conf_file\n" unless defined $options{$option} && length $options{$option};
}
return @options{@$options};
@@ -79,14 +81,14 @@ my $save_session = sub
{
my ($session) = @_;
- open(my $fh, '>', $session_file) or die "$0: Cannot open client-side $session_file for writing: $!\n";
+ open(my $fh, '>', $session_file) or _die "Cannot open $session_file for writing: $!\n";
print {$fh} "$session\n";
close($fh);
};
my $get_session = sub
{
- open(my $fh, '<', $session_file) or die "$0: Cannot open client-side $session_file for reading: $!\nPerhaps try running --init\n";
+ open(my $fh, '<', $session_file) or _die "Cannot open $session_file for reading: $!\nPerhaps try running --init\n";
my $session = do { local $/; <$fh> };
chomp $session;
close($fh);
@@ -116,7 +118,7 @@ if ($response->is_success) {
$data = decode_json($response->decoded_content);
} or exit;
- die "$0: $data->{error}" if defined $data->{error};
+ die "$0: [server] $data->{error}" if defined $data->{error};
$save_session->($session) if $opts{i};
@@ -126,7 +128,7 @@ if ($response->is_success) {
push @{$list{$entry->{netz}}}, $host;
}
- my $o = tie my @hosts, 'Tie::File', $hosts_file or die "$0: Cannot tie $hosts_file: $!\n";
+ my $o = tie my @hosts, 'Tie::File', $hosts_file or _die "Cannot tie $hosts_file: $!\n";
$o->flock(LOCK_EX);
foreach my $network (keys %list) {
diff --git a/server.cgi b/server.cgi
index bdd9ac7..67b522e 100755
--- a/server.cgi
+++ b/server.cgi
@@ -70,14 +70,14 @@ foreach my $option (@options) {
my ($json_file, $session_file) = map rel2abs($options{$_}, $Bin), @options;
if ($params{init}) {
- die "Delete server-side $session_file first\n" if -e $session_file;
+ die "Delete $session_file first\n" if -e $session_file;
- open(my $fh, '>', $session_file) or die "Cannot open server-side $session_file for writing: $!\n";
+ open(my $fh, '>', $session_file) or die "Cannot open $session_file for writing: $!\n";
print {$fh} "$params{session}\n";
close($fh);
}
else {
- open(my $fh, '<', $session_file) or die "Cannot open server-side $session_file for reading: $!\nPerhaps try running --init\n";
+ open(my $fh, '<', $session_file) or die "Cannot open $session_file for reading: $!\nPerhaps try running --init\n";
my $session = do { local $/; <$fh> };
chomp $session;
close($fh);