From 3a512f87a56c986154bc92ecc47197575ab79d57 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 19 Feb 2016 10:57:52 -0500 Subject: [PATCH 1/5] Log the reason for croaking before croaking. --- .../lib/ZoneMinder/Trigger/Channel/Unix.pm | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Channel/Unix.pm b/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Channel/Unix.pm index 71d6e89fc..ea74c957e 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Channel/Unix.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Channel/Unix.pm @@ -63,9 +63,18 @@ sub open local *sfh; unlink( $self->{path} ); my $saddr = sockaddr_un( $self->{path} ); - socket( *sfh, PF_UNIX, SOCK_STREAM, 0 ) or croak( "Can't open socket: $!" ); - bind( *sfh, $saddr ) or croak( "Can't bind: $!" ); - listen( *sfh, SOMAXCONN ) or croak( "Can't listen: $!" ); + if ( ! socket( *sfh, PF_UNIX, SOCK_STREAM, 0 ) ) { + Error( "Can't open unix socket at $$self{path}: $!" ); + croak( "Can't open unix socket at $$self{path}: $!" ); + } + if ( ! bind( *sfh, $saddr ) ) { + Error( "Can't bind unix socket at $$self{path}: $!" ); + croak( "Can't bind unix socket at $$self{path}: $!" ); + } + if ( ! listen( *sfh, SOMAXCONN ) ) { + Error( "Can't listen: $!" ); + croak( "Can't listen: $!" ); + } $self->{handle} = *sfh; } @@ -93,12 +102,11 @@ __END__ =head1 NAME -ZoneMinder::Database - Perl extension for blah blah blah +ZoneMinder::Trigger::Channel::Unix - Object for Unix socket channel =head1 SYNOPSIS - use ZoneMinder::Database; - blah blah blah +See zmtrigger.pl =head1 DESCRIPTION From 327a01cb2003538f308031401c0fb8b49724118b Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 19 Feb 2016 10:59:40 -0500 Subject: [PATCH 2/5] Log error before croaking and show path to file in the error message --- scripts/ZoneMinder/lib/ZoneMinder/Trigger/Channel/File.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Channel/File.pm b/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Channel/File.pm index 6c4254a7e..0a4bdea8a 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Channel/File.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Channel/File.pm @@ -62,7 +62,10 @@ sub open local *sfh; #sysopen( *sfh, $conn->{path}, O_NONBLOCK|O_RDONLY ) or croak( "Can't sysopen: $!" ); #open( *sfh, "<".$conn->{path} ) or croak( "Can't open: $!" ); - open( *sfh, "+<", $self->{path} ) or croak( "Can't open: $!" ); + if ( ! open( *sfh, "+<", $self->{path} ) ) { + Error( "Can't open file at $$self{path}: $!" ); + croak( "Can't open file at $$self{path}: $!" ); + } $self->{state} = 'open'; $self->{handle} = *sfh; } @@ -73,7 +76,7 @@ __END__ =head1 NAME -ZoneMinder::Database - Perl extension for blah blah blah +ZoneMinder::Trigger::Channel::File - ZOneMinder object for a file based trigger channel =head1 SYNOPSIS From 64c5b64068b72a22e9030a67ebd351d63f83fce3 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 19 Feb 2016 11:04:02 -0500 Subject: [PATCH 3/5] Log error before croaking and include port# in the error message --- .../lib/ZoneMinder/Trigger/Channel/Inet.pm | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Channel/Inet.pm b/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Channel/Inet.pm index 6c5f21961..0f977f3da 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Channel/Inet.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Trigger/Channel/Inet.pm @@ -61,12 +61,21 @@ sub open { my $self = shift; local *sfh; - my $saddr = sockaddr_in( $self->{port}, INADDR_ANY ); - socket( *sfh, PF_INET, SOCK_STREAM, getprotobyname('tcp') ) - or croak( "Can't open socket: $!" ); + if ( ! socket( *sfh, PF_INET, SOCK_STREAM, getprotobyname('tcp') ) ) { + Error( "Can't open socket: $!" ); + croak( "Can't open socket: $!" ); + } setsockopt( *sfh, SOL_SOCKET, SO_REUSEADDR, 1 ); - bind( *sfh, $saddr ) or croak( "Can't bind: $!" ); - listen( *sfh, SOMAXCONN ) or croak( "Can't listen: $!" ); + + my $saddr = sockaddr_in( $self->{port}, INADDR_ANY ); + if ( ! bind( *sfh, $saddr ) ) { + Error( "Can't bind to port $$self{port}: $!" ); + croak( "Can't bind to port $$self{port}: $!" ); + } + if ( ! listen( *sfh, SOMAXCONN ) ) { + Error( "Can't listen: $!" ); + croak( "Can't listen: $!" ); + } $self->{state} = 'open'; $self->{handle} = *sfh; } @@ -95,7 +104,7 @@ __END__ =head1 NAME -ZoneMinder::Database - Perl extension for blah blah blah +ZoneMinder::Trigger::Channel::Inet =head1 SYNOPSIS From 3b07b5640018094b3e639eaa0cb2ea7019d8424f Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 19 Feb 2016 11:05:55 -0500 Subject: [PATCH 4/5] Use more descriptive names for the channels --- scripts/zmtrigger.pl.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/zmtrigger.pl.in b/scripts/zmtrigger.pl.in index 55166a492..68bcbde93 100644 --- a/scripts/zmtrigger.pl.in +++ b/scripts/zmtrigger.pl.in @@ -135,14 +135,14 @@ use ZoneMinder::Trigger::Connection; my @connections; push( @connections, ZoneMinder::Trigger::Connection->new( - name=>"Chan1", + name=>"Chan1 TCP on port 6802", channel=>ZoneMinder::Trigger::Channel::Inet->new( port=>6802 ), mode=>"rw" ) ); push( @connections, ZoneMinder::Trigger::Connection->new( - name=>"Chan2", + name=>"Chan2 Unix Socket at " $Config{ZM_PATH_SOCKS}.'/zmtrigger.sock', channel=>ZoneMinder::Trigger::Channel::Unix->new( path=>$Config{ZM_PATH_SOCKS}.'/zmtrigger.sock' ), From 826a22a2a8cc33effb5c9080b612280de433fcd8 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 19 Feb 2016 11:07:06 -0500 Subject: [PATCH 5/5] add missing . --- scripts/zmtrigger.pl.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/zmtrigger.pl.in b/scripts/zmtrigger.pl.in index 68bcbde93..222e42f79 100644 --- a/scripts/zmtrigger.pl.in +++ b/scripts/zmtrigger.pl.in @@ -142,7 +142,7 @@ push( @connections, ); push( @connections, ZoneMinder::Trigger::Connection->new( - name=>"Chan2 Unix Socket at " $Config{ZM_PATH_SOCKS}.'/zmtrigger.sock', + name=>"Chan2 Unix Socket at " . $Config{ZM_PATH_SOCKS}.'/zmtrigger.sock', channel=>ZoneMinder::Trigger::Channel::Unix->new( path=>$Config{ZM_PATH_SOCKS}.'/zmtrigger.sock' ),