Fix usage()

* The first argument to usage() was supposed to be the exit status,
    but that is not how usage() is invoked (except in the `-help`
    case). Change usage() to work with the existing invocations rather
    than fix the invocations.
  * Don't attempt to send an email when passed `-help`.
  * Include the usage error message in the emailed log.
This commit is contained in:
Richard Hansen 2020-05-28 14:00:36 -04:00
parent 3a6a2ac036
commit ca7f0927fc

View file

@ -807,11 +807,7 @@ $result = 'OK';
test_geturl(opt('geturl')) if opt('geturl'); test_geturl(opt('geturl')) if opt('geturl');
## process help option usage() if opt('help');
if (opt('help')) {
*STDERR = *STDOUT;
usage(0);
}
## read config file because 'daemon' mode may be defined there. ## read config file because 'daemon' mode may be defined there.
read_config(define($opt{'file'}, default('file')), \%config, \%globals); read_config(define($opt{'file'}, default('file')), \%config, \%globals);
@ -1411,18 +1407,10 @@ sub init_config {
## usage ## usage
###################################################################### ######################################################################
sub usage { sub usage {
my $exitcode = 1; _msg(1, 1, 'FATAL:', @_) if @_;
$exitcode = shift if @_ != 0; # use first arg if given printf { @_ ? *STDERR : *STDOUT } "%s\n", $opt_usage;
my $msg = ''; sendmail() if @_;
if (@_) { exit (@_ ? 1 : 0);
my $format = shift;
$msg .= sprintf $format, @_;
1 while chomp($msg);
$msg .= "\n";
}
printf STDERR "%s%s\n", $msg, $opt_usage;
sendmail();
exit $exitcode;
} }
###################################################################### ######################################################################