chiark / gitweb /
importd: add new bus calls for importing local tar and raw images
[elogind.git] / src / detect-virt / detect-virt.c
index a83fb3ced52059501ab6beae0c08edbfc6f99eb8..606d073cbcf7b0a68ed5db069f3784744422a7ca 100644 (file)
@@ -22,7 +22,6 @@
 #include <stdlib.h>
 #include <stdbool.h>
 #include <errno.h>
-#include <string.h>
 #include <getopt.h>
 
 #include "util.h"
@@ -36,18 +35,15 @@ static enum {
         ONLY_CONTAINER
 } arg_mode = ANY_VIRTUALIZATION;
 
-static int help(void) {
-
+static void help(void) {
         printf("%s [OPTIONS...]\n\n"
                "Detect execution in a virtualized environment.\n\n"
                "  -h --help             Show this help\n"
                "     --version          Show package version\n"
                "  -c --container        Only detect whether we are run in a container\n"
                "  -v --vm               Only detect whether we are run in a VM\n"
-               "  -q --quiet            Don't output anything, just set return value\n",
-               program_invocation_short_name);
-
-        return 0;
+               "  -q --quiet            Don't output anything, just set return value\n"
+               , program_invocation_short_name);
 }
 
 static int parse_argv(int argc, char *argv[]) {
@@ -61,8 +57,8 @@ static int parse_argv(int argc, char *argv[]) {
                 { "version",   no_argument,       NULL, ARG_VERSION   },
                 { "container", no_argument,       NULL, 'c'           },
                 { "vm",        optional_argument, NULL, 'v'           },
-                { "quiet",     required_argument, NULL, 'q'           },
-                { NULL,        0,                 NULL, 0             }
+                { "quiet",     no_argument,       NULL, 'q'           },
+                {}
         };
 
         int c;
@@ -70,7 +66,7 @@ static int parse_argv(int argc, char *argv[]) {
         assert(argc >= 0);
         assert(argv);
 
-        while ((c = getopt_long(argc, argv, "hqcv", options, NULL)) >= 0) {
+        while ((c = getopt_long(argc, argv, "hqcv", options, NULL)) >= 0)
 
                 switch (c) {
 
@@ -80,7 +76,6 @@ static int parse_argv(int argc, char *argv[]) {
 
                 case ARG_VERSION:
                         puts(PACKAGE_STRING);
-                        puts(DISTRIBUTION);
                         puts(SYSTEMD_FEATURES);
                         return 0;
 
@@ -100,13 +95,12 @@ static int parse_argv(int argc, char *argv[]) {
                         return -EINVAL;
 
                 default:
-                        log_error("Unknown option code %c", c);
-                        return -EINVAL;
+                        assert_not_reached("Unhandled option");
                 }
-        }
 
         if (optind < argc) {
-                help();
+                log_error("%s takes no arguments.",
+                          program_invocation_short_name);
                 return -EINVAL;
         }
 
@@ -115,7 +109,8 @@ static int parse_argv(int argc, char *argv[]) {
 
 int main(int argc, char *argv[]) {
         const char *id = NULL;
-        int retval, r;
+        int retval = EXIT_SUCCESS;
+        int r;
 
         /* This is mostly intended to be used for scripts which want
          * to detect whether we are being run in a virtualized
@@ -131,11 +126,11 @@ int main(int argc, char *argv[]) {
         switch (arg_mode) {
 
         case ANY_VIRTUALIZATION: {
-                Virtualization v;
+                int v;
 
                 v = detect_virtualization(&id);
                 if (v < 0) {
-                        log_error("Failed to check for virtualization: %s", strerror(-v));
+                        log_error_errno(v, "Failed to check for virtualization: %m");
                         return EXIT_FAILURE;
                 }
 
@@ -146,7 +141,7 @@ int main(int argc, char *argv[]) {
         case ONLY_CONTAINER:
                 r = detect_container(&id);
                 if (r < 0) {
-                        log_error("Failed to check for container: %s", strerror(-r));
+                        log_error_errno(r, "Failed to check for container: %m");
                         return EXIT_FAILURE;
                 }
 
@@ -156,7 +151,7 @@ int main(int argc, char *argv[]) {
         case ONLY_VM:
                 r = detect_vm(&id);
                 if (r < 0) {
-                        log_error("Failed to check for vm: %s", strerror(-r));
+                        log_error_errno(r, "Failed to check for vm: %m");
                         return EXIT_FAILURE;
                 }