summaryrefslogtreecommitdiffstats
path: root/src/detect-virt/detect-virt.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-11-16 10:53:47 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2018-11-17 09:13:35 +0100
commitbdab09849e60299392b37d99de8008b87b8b8a21 (patch)
treeadcc975170258efa0a8bca6233a09edef8bc4383 /src/detect-virt/detect-virt.c
parentcoredump: define main through macro (diff)
downloadsystemd-bdab09849e60299392b37d99de8008b87b8b8a21.tar.xz
systemd-bdab09849e60299392b37d99de8008b87b8b8a21.zip
detect-virt: define main through macro
Diffstat (limited to 'src/detect-virt/detect-virt.c')
-rw-r--r--src/detect-virt/detect-virt.c48
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);