From 344ba205c17889fbed44eb90fc878429efc597f1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Thu, 4 May 2023 20:23:30 +0200 Subject: [PATCH] enosys: add common arguments MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Weißschuh --- misc-utils/enosys.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/misc-utils/enosys.c b/misc-utils/enosys.c index 5a337fd813..793b646463 100644 --- a/misc-utils/enosys.c +++ b/misc-utils/enosys.c @@ -73,6 +73,24 @@ static const struct syscall syscalls[] = { { "fallocate", __NR_fallocate }, }; +static void __attribute__((__noreturn__)) usage(void) +{ + FILE *out = stdout; + + fputs(USAGE_HEADER, out); + fprintf(out, _(" %s [options] -- \n"), program_invocation_short_name); + + fputs(USAGE_OPTIONS, out); + fputs(_(" -s, --syscall syscall to block\n"), out); + + fputs(USAGE_SEPARATOR, out); + fprintf(out, USAGE_HELP_OPTIONS(25)); + + fprintf(out, USAGE_MAN_TAIL("enosys(1)")); + + exit(EXIT_SUCCESS); +} + int main(int argc, char **argv) { int c; @@ -80,12 +98,14 @@ int main(int argc, char **argv) bool found; static const struct option longopts[] = { { "syscall", required_argument, NULL, 's' }, + { "version", no_argument, NULL, 'V' }, + { "help", no_argument, NULL, 'h' }, { 0 } }; bool blocked_syscalls[ARRAY_SIZE(syscalls)] = {}; - while ((c = getopt_long (argc, argv, "s:", longopts, NULL)) != -1) { + while ((c = getopt_long (argc, argv, "Vhs:", longopts, NULL)) != -1) { switch (c) { case 's': found = 0; @@ -99,13 +119,17 @@ int main(int argc, char **argv) if (!found) errx(EXIT_FAILURE, "Unknown syscall '%s'", optarg); break; + case 'V': + print_version(EXIT_SUCCESS); + case 'h': + usage(); default: - errx(EXIT_FAILURE, "Unknown option"); + errtryhelp(EXIT_FAILURE); } } if (optind >= argc) - errx(EXIT_FAILURE, "No executable specified"); + errtryhelp(EXIT_FAILURE); #define N_FILTERS (ARRAY_SIZE(syscalls) + 3) -- 2.47.2