LCOV - code coverage report
Current view: top level - udev - udevadm.c (source / functions) Hit Total Coverage
Test: main_coverage.info Lines: 26 44 59.1 %
Date: 2019-08-22 15:41:25 Functions: 4 7 57.1 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: GPL-2.0+ */
       2             : 
       3             : #include <errno.h>
       4             : #include <getopt.h>
       5             : #include <stddef.h>
       6             : #include <stdio.h>
       7             : 
       8             : #include "alloc-util.h"
       9             : #include "main-func.h"
      10             : #include "pretty-print.h"
      11             : #include "selinux-util.h"
      12             : #include "string-util.h"
      13             : #include "udevadm.h"
      14             : #include "udev-util.h"
      15             : #include "verbs.h"
      16             : #include "util.h"
      17             : 
      18           3 : static int help(void) {
      19             :         static const char *const short_descriptions[][2] = {
      20             :                 { "info",         "Query sysfs or the udev database" },
      21             :                 { "trigger",      "Request events from the kernel"   },
      22             :                 { "settle",       "Wait for pending udev events"     },
      23             :                 { "control",      "Control the udev daemon"          },
      24             :                 { "monitor",      "Listen to kernel and udev events" },
      25             :                 { "test",         "Test an event run"                },
      26             :                 { "test-builtin", "Test a built-in command"          },
      27             :         };
      28             : 
      29           3 :         _cleanup_free_ char *link = NULL;
      30             :         size_t i;
      31             :         int r;
      32             : 
      33           3 :         r = terminal_urlify_man("udevadm", "8", &link);
      34           3 :         if (r < 0)
      35           0 :                 return log_oom();
      36             : 
      37           3 :         printf("%s [--help] [--version] [--debug] COMMAND [COMMAND OPTIONS]\n\n"
      38             :                "Send control commands or test the device manager.\n\n"
      39             :                "Commands:\n"
      40             :                , program_invocation_short_name);
      41             : 
      42          24 :         for (i = 0; i < ELEMENTSOF(short_descriptions); i++)
      43          21 :                 printf("  %-12s  %s\n", short_descriptions[i][0], short_descriptions[i][1]);
      44             : 
      45           3 :         printf("\nSee the %s for details.\n", link);
      46           3 :         return 0;
      47             : }
      48             : 
      49           4 : static int parse_argv(int argc, char *argv[]) {
      50             :         static const struct option options[] = {
      51             :                 { "debug",   no_argument, NULL, 'd' },
      52             :                 { "help",    no_argument, NULL, 'h' },
      53             :                 { "version", no_argument, NULL, 'V' },
      54             :                 {}
      55             :         };
      56             :         int c;
      57             : 
      58           4 :         assert(argc >= 0);
      59           4 :         assert(argv);
      60             : 
      61           4 :         while ((c = getopt_long(argc, argv, "+dhV", options, NULL)) >= 0)
      62           4 :                 switch (c) {
      63             : 
      64           0 :                 case 'd':
      65           0 :                         log_set_max_level(LOG_DEBUG);
      66           0 :                         break;
      67             : 
      68           3 :                 case 'h':
      69           3 :                         return help();
      70             : 
      71           0 :                 case 'V':
      72           0 :                         return print_version();
      73             : 
      74           1 :                 case '?':
      75           1 :                         return -EINVAL;
      76             : 
      77           0 :                 default:
      78           0 :                         assert_not_reached("Unhandled option");
      79             :                 }
      80             : 
      81           0 :         return 1; /* work to do */
      82             : }
      83             : 
      84           0 : static int version_main(int argc, char *argv[], void *userdata) {
      85           0 :         return print_version();
      86             : }
      87             : 
      88           0 : static int help_main(int argc, char *argv[], void *userdata) {
      89           0 :         return help();
      90             : }
      91             : 
      92           0 : static int udevadm_main(int argc, char *argv[]) {
      93             :         static const Verb verbs[] = {
      94             :                 { "info",         VERB_ANY, VERB_ANY, 0, info_main    },
      95             :                 { "trigger",      VERB_ANY, VERB_ANY, 0, trigger_main },
      96             :                 { "settle",       VERB_ANY, VERB_ANY, 0, settle_main  },
      97             :                 { "control",      VERB_ANY, VERB_ANY, 0, control_main },
      98             :                 { "monitor",      VERB_ANY, VERB_ANY, 0, monitor_main },
      99             :                 { "hwdb",         VERB_ANY, VERB_ANY, 0, hwdb_main    },
     100             :                 { "test",         VERB_ANY, VERB_ANY, 0, test_main    },
     101             :                 { "test-builtin", VERB_ANY, VERB_ANY, 0, builtin_main },
     102             :                 { "version",      VERB_ANY, VERB_ANY, 0, version_main },
     103             :                 { "help",         VERB_ANY, VERB_ANY, 0, help_main    },
     104             :                 {}
     105             :         };
     106             : 
     107           0 :         return dispatch_verb(argc, argv, verbs, NULL);
     108             : }
     109             : 
     110           4 : static int run(int argc, char *argv[]) {
     111             :         int r;
     112             : 
     113           4 :         udev_parse_config();
     114           4 :         log_parse_environment();
     115           4 :         log_open();
     116             : 
     117           4 :         r = parse_argv(argc, argv);
     118           4 :         if (r <= 0)
     119           4 :                 return r;
     120             : 
     121           0 :         log_set_max_level_realm(LOG_REALM_SYSTEMD, log_get_max_level());
     122             : 
     123           0 :         mac_selinux_init();
     124           0 :         return udevadm_main(argc, argv);
     125             : }
     126             : 
     127           4 : DEFINE_MAIN_FUNCTION(run);

Generated by: LCOV version 1.14