diff options
author | Daniel Mack <github@zonque.org> | 2015-09-08 15:53:56 +0200 |
---|---|---|
committer | Daniel Mack <github@zonque.org> | 2015-09-08 15:53:56 +0200 |
commit | da323858ef34a0216aa96f4089810053c90f09ce (patch) | |
tree | 6255edf3ad93f2ce0cee28856ec3de90915caccd /src/detect-virt/detect-virt.c | |
parent | 4211d5bd135ae4c43bd2012ae5f327b1cc1596c0 (diff) | |
parent | 75f86906c52735c98dc0aa7e24b773edb42ee814 (diff) |
Merge pull request #1190 from poettering/rework-virt
basic: rework virtualization detection API
Diffstat (limited to 'src/detect-virt/detect-virt.c')
-rw-r--r-- | src/detect-virt/detect-virt.c | 31 |
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; } |