Move display of usage text into display_usage() so usage() always exits.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-License-Identifier: ISC
|
* SPDX-License-Identifier: ISC
|
||||||
*
|
*
|
||||||
* Copyright (c) 2019-2022 Todd C. Miller <Todd.Miller@sudo.ws>
|
* Copyright (c) 2019-2023 Todd C. Miller <Todd.Miller@sudo.ws>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -1891,19 +1891,24 @@ daemonize(bool nofork)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage(bool fatal)
|
display_usage(FILE *fp)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: %s [-n] [-f conf_file] [-R percentage]\n",
|
fprintf(fp, "usage: %s [-n] [-f conf_file] [-R percentage]\n",
|
||||||
getprogname());
|
getprogname());
|
||||||
if (fatal)
|
}
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
|
sudo_noreturn static void
|
||||||
|
usage(void)
|
||||||
|
{
|
||||||
|
display_usage(stderr);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
sudo_noreturn static void
|
sudo_noreturn static void
|
||||||
help(void)
|
help(void)
|
||||||
{
|
{
|
||||||
printf("%s - %s\n\n", getprogname(), _("sudo log server"));
|
printf("%s - %s\n\n", getprogname(), _("sudo log server"));
|
||||||
usage(false);
|
display_usage(stdout);
|
||||||
printf("\n%s\n", _("Options:"));
|
printf("\n%s\n", _("Options:"));
|
||||||
printf(" -f, --file %s\n",
|
printf(" -f, --file %s\n",
|
||||||
_("path to configuration file"));
|
_("path to configuration file"));
|
||||||
@@ -1987,7 +1992,7 @@ main(int argc, char *argv[])
|
|||||||
PACKAGE_VERSION);
|
PACKAGE_VERSION);
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
default:
|
||||||
usage(true);
|
usage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-License-Identifier: ISC
|
* SPDX-License-Identifier: ISC
|
||||||
*
|
*
|
||||||
* Copyright (c) 2019-2022 Todd C. Miller <Todd.Miller@sudo.ws>
|
* Copyright (c) 2019-2023 Todd C. Miller <Todd.Miller@sudo.ws>
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
@@ -98,18 +98,23 @@ static void client_msg_cb(int fd, int what, void *v);
|
|||||||
static void server_msg_cb(int fd, int what, void *v);
|
static void server_msg_cb(int fd, int what, void *v);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage(bool fatal)
|
display_usage(FILE *fp)
|
||||||
{
|
{
|
||||||
#if defined(HAVE_OPENSSL)
|
#if defined(HAVE_OPENSSL)
|
||||||
fprintf(stderr, "usage: %s [-AnV] [-b ca_bundle] [-c cert_file] [-h host] "
|
fprintf(fp, "usage: %s [-AnV] [-b ca_bundle] [-c cert_file] [-h host] "
|
||||||
"[-i iolog-id] [-k key_file] [-p port] "
|
"[-i iolog-id] [-k key_file] [-p port] "
|
||||||
#else
|
#else
|
||||||
fprintf(stderr, "usage: %s [-AnV] [-h host] [-i iolog-id] [-p port] "
|
fprintf(fp, "usage: %s [-AnV] [-h host] [-i iolog-id] [-p port] "
|
||||||
#endif
|
#endif
|
||||||
"[-r restart-point] [-R reject-reason] [-s stop-point] [-t number] /path/to/iolog\n",
|
"[-r restart-point] [-R reject-reason] [-s stop-point] [-t number] /path/to/iolog\n",
|
||||||
getprogname());
|
getprogname());
|
||||||
if (fatal)
|
}
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
|
sudo_noreturn static void
|
||||||
|
usage(void)
|
||||||
|
{
|
||||||
|
display_usage(stderr);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
sudo_noreturn static void
|
sudo_noreturn static void
|
||||||
@@ -117,7 +122,7 @@ help(void)
|
|||||||
{
|
{
|
||||||
printf("%s - %s\n\n", getprogname(),
|
printf("%s - %s\n\n", getprogname(),
|
||||||
_("send sudo I/O log to remote server"));
|
_("send sudo I/O log to remote server"));
|
||||||
usage(false);
|
display_usage(stdout);
|
||||||
printf("\n%s\n", _("Options:"));
|
printf("\n%s\n", _("Options:"));
|
||||||
printf(" --help %s\n",
|
printf(" --help %s\n",
|
||||||
_("display help message and exit"));
|
_("display help message and exit"));
|
||||||
@@ -1766,7 +1771,7 @@ main(int argc, char *argv[])
|
|||||||
PACKAGE_VERSION);
|
PACKAGE_VERSION);
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
default:
|
||||||
usage(true);
|
usage();
|
||||||
/* NOTREACHED */
|
/* NOTREACHED */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1787,16 +1792,16 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (sudo_timespecisset(&restart) != (iolog_id != NULL)) {
|
if (sudo_timespecisset(&restart) != (iolog_id != NULL)) {
|
||||||
sudo_warnx("%s", U_("both restart point and iolog ID must be specified"));
|
sudo_warnx("%s", U_("both restart point and iolog ID must be specified"));
|
||||||
usage(true);
|
usage();
|
||||||
}
|
}
|
||||||
if (sudo_timespecisset(&restart) && (accept_only || reject_reason)) {
|
if (sudo_timespecisset(&restart) && (accept_only || reject_reason)) {
|
||||||
sudo_warnx("%s", U_("a restart point may not be set when no I/O is sent"));
|
sudo_warnx("%s", U_("a restart point may not be set when no I/O is sent"));
|
||||||
usage(true);
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remaining arg should be to I/O log dir to send. */
|
/* Remaining arg should be to I/O log dir to send. */
|
||||||
if (argc != 1)
|
if (argc != 1)
|
||||||
usage(true);
|
usage();
|
||||||
iolog_dir = argv[0];
|
iolog_dir = argv[0];
|
||||||
if ((iolog_dir_fd = open(iolog_dir, O_RDONLY)) == -1) {
|
if ((iolog_dir_fd = open(iolog_dir, O_RDONLY)) == -1) {
|
||||||
sudo_warn("%s", iolog_dir);
|
sudo_warn("%s", iolog_dir);
|
||||||
|
Reference in New Issue
Block a user