summaryrefslogtreecommitdiff
path: root/src/detect-virt/detect-virt.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-09-07 13:42:47 +0200
committerLennart Poettering <lennart@poettering.net>2015-09-07 13:42:47 +0200
commit75f86906c52735c98dc0aa7e24b773edb42ee814 (patch)
treed2d0701f8df51d5a09586073ebd387bb831743e7 /src/detect-virt/detect-virt.c
parent47f5a38cdf98a220d6a0d4eb11a710a0a42ae5c4 (diff)
basic: rework virtualization detection API
Introduce a proper enum, and don't pass around string ids anymore. This simplifies things quite a bit, and makes virtualization detection more similar to architecture detection.
Diffstat (limited to 'src/detect-virt/detect-virt.c')
-rw-r--r--src/detect-virt/detect-virt.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/detect-virt/detect-virt.c b/src/detect-virt/detect-virt.c
index 606d073cbc..97ae569ca5 100644
--- a/src/detect-virt/detect-virt.c
+++ b/src/detect-virt/detect-virt.c
@@ -108,9 +108,7 @@ static int parse_argv(int argc, char *argv[]) {
}
int main(int argc, char *argv[]) {
- const char *id = NULL;
- int retval = EXIT_SUCCESS;
- int r;
+ int retval = EXIT_SUCCESS, r;
/* This is mostly intended to be used for scripts which want
* to detect whether we are being run in a virtualized
@@ -125,42 +123,39 @@ int main(int argc, char *argv[]) {
switch (arg_mode) {
- case ANY_VIRTUALIZATION: {
- int v;
-
- v = detect_virtualization(&id);
- if (v < 0) {
- log_error_errno(v, "Failed to check for virtualization: %m");
+ case ONLY_VM:
+ r = detect_vm();
+ if (r < 0) {
+ log_error_errno(r, "Failed to check for vm: %m");
return EXIT_FAILURE;
}
- retval = v != VIRTUALIZATION_NONE ? EXIT_SUCCESS : EXIT_FAILURE;
break;
- }
case ONLY_CONTAINER:
- r = detect_container(&id);
+ r = detect_container();
if (r < 0) {
log_error_errno(r, "Failed to check for container: %m");
return EXIT_FAILURE;
}
- retval = r > 0 ? EXIT_SUCCESS : EXIT_FAILURE;
break;
- case ONLY_VM:
- r = detect_vm(&id);
+ case ANY_VIRTUALIZATION:
+ default:
+ r = detect_virtualization();
if (r < 0) {
- log_error_errno(r, "Failed to check for vm: %m");
+ log_error_errno(r, "Failed to check for virtualization: %m");
return EXIT_FAILURE;
}
- retval = r > 0 ? EXIT_SUCCESS : EXIT_FAILURE;
break;
}
if (!arg_quiet)
- puts(id ? id : "none");
+ puts(virtualization_to_string(r));
+
+ retval = r != VIRTUALIZATION_NONE ? EXIT_SUCCESS : EXIT_FAILURE;
return retval;
}