diff options
Diffstat (limited to 'src/detect-virt/detect-virt.c')
-rw-r--r-- | src/detect-virt/detect-virt.c | 48 |
1 files changed, 17 insertions, 31 deletions
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); |