diff --git a/scripts/zmcontrol.pl.in b/scripts/zmcontrol.pl.in index d1f50cf43..8a93a19a4 100644 --- a/scripts/zmcontrol.pl.in +++ b/scripts/zmcontrol.pl.in @@ -61,12 +61,12 @@ GetOptions( 'autostop' =>\$options{autostop}, ) or pod2usage(-exitstatus => -1); -if ( !$id ) { +if (!$id) { print(STDERR "Please give a valid monitor id\n"); pod2usage(-exitstatus => -1); } -( $id ) = $id =~ /^(\w+)$/; +($id) = $id =~ /^(\w+)$/; logInit($id?(id=>'zmcontrol_'.$id):()); my $sock_file = $Config{ZM_PATH_SOCKS}.'/zmcontrol-'.$id.'.sock'; @@ -76,7 +76,7 @@ socket(CLIENT, PF_UNIX, SOCK_STREAM, 0) or Fatal("Can't open socket: $!"); my $saddr = sockaddr_un($sock_file); -if ( $options{command} ) { +if ($options{command}) { # Have a command, so we are the client, connect to the server and send it. my $tries = 10; @@ -101,18 +101,16 @@ if ( $options{command} ) { Error("Unable to connect to zmcontrol server at $sock_file"); } } else { - # The server isn't there my $monitor = zmDbGetMonitorAndControl($id); - if ( !$monitor ) { - Fatal("Unable to load control data for monitor $id"); - } + Fatal("Unable to load control data for monitor $id") if !$monitor; + my $protocol = $monitor->{Protocol}; - if ( !$protocol ) { + if (!$protocol) { Fatal('No protocol is set in monitor. Please edit the monitor, edit control type, select the control capability and fill in the Protocol field'); } - if ( -x $protocol ) { + if (-x $protocol) { # Protocol is actually a script! # Holdover from previous versions my $command .= $protocol.' '.$arg_string; @@ -120,11 +118,11 @@ if ( $options{command} ) { my $output = qx($command); my $status = $? >> 8; - if ( $status || logDebugging() ) { + if ($status || logDebugging()) { chomp($output); Debug("Output: $output"); } - if ( $status ) { + if ($status) { Error("Command '$command' exited with status: $status"); exit($status); } @@ -134,7 +132,7 @@ if ( $options{command} ) { Info("Starting control server $id/$protocol"); close(CLIENT); - if ( ! can_load( modules => { "ZoneMinder::Control::$protocol" => undef } ) ) { + if (!can_load(modules => {'ZoneMinder::Control::'.$protocol => undef})) { Fatal("Can't load ZoneMinder::Control::$protocol\n$Module::Load::Conditional::ERROR"); } @@ -159,7 +157,7 @@ if ( $options{command} ) { $control->open(); # If we have a command when starting up, then do it. - if ( $options{command} ) { + if ($options{command}) { my $command = $options{command}; $control->$command(\%options); }