From bdab09849e60299392b37d99de8008b87b8b8a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 16 Nov 2018 10:53:47 +0100 Subject: detect-virt: define main through macro --- src/detect-virt/detect-virt.c | 48 +++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 31 deletions(-) (limited to 'src/detect-virt') diff --git a/src/detect-virt/detect-virt.c b/src/detect-virt/detect-virt.c index b98ddbd0c6..d1a2ab95a0 100644 --- a/src/detect-virt/detect-virt.c +++ b/src/detect-virt/detect-virt.c @@ -120,7 +120,7 @@ static int parse_argv(int argc, char *argv[]) { return 1; } -int main(int argc, char *argv[]) { +static int run(int argc, char *argv[]) { int r; /* This is mostly intended to be used for scripts which want @@ -132,59 +132,45 @@ int main(int argc, char *argv[]) { r = parse_argv(argc, argv); if (r <= 0) - return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; + return r; switch (arg_mode) { - case ONLY_VM: r = detect_vm(); - if (r < 0) { - log_error_errno(r, "Failed to check for VM: %m"); - return EXIT_FAILURE; - } - + if (r < 0) + return log_error_errno(r, "Failed to check for VM: %m"); break; case ONLY_CONTAINER: r = detect_container(); - if (r < 0) { - log_error_errno(r, "Failed to check for container: %m"); - return EXIT_FAILURE; - } - + if (r < 0) + return log_error_errno(r, "Failed to check for container: %m"); break; case ONLY_CHROOT: r = running_in_chroot(); - if (r < 0) { - log_error_errno(r, "Failed to check for chroot() environment: %m"); - return EXIT_FAILURE; - } - - return r ? EXIT_SUCCESS : EXIT_FAILURE; + if (r < 0) + return log_error_errno(r, "Failed to check for chroot() environment: %m"); + return !r; case ONLY_PRIVATE_USERS: r = running_in_userns(); - if (r < 0) { - log_error_errno(r, "Failed to check for user namespace: %m"); - return EXIT_FAILURE; - } - - return r ? EXIT_SUCCESS : EXIT_FAILURE; + if (r < 0) + return log_error_errno(r, "Failed to check for user namespace: %m"); + return !r; case ANY_VIRTUALIZATION: default: r = detect_virtualization(); - if (r < 0) { - log_error_errno(r, "Failed to check for virtualization: %m"); - return EXIT_FAILURE; - } - + if (r < 0) + return log_error_errno(r, "Failed to check for virtualization: %m"); break; } if (!arg_quiet) puts(virtualization_to_string(r)); - return r != VIRTUALIZATION_NONE ? EXIT_SUCCESS : EXIT_FAILURE; + return r == VIRTUALIZATION_NONE; } + +DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run); -- cgit v1.2.1