]> git.proxmox.com Git - systemd.git/blobdiff - src/udev/udevadm-test.c
New upstream version 236
[systemd.git] / src / udev / udevadm-test.c
index e8ffe2f309d9161d226cda2298e6ec7ba8590f55..ef1f2f0269a257269a6c5c6d057ca5e374e8913d 100644 (file)
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
 /*
  * Copyright (C) 2003-2004 Greg Kroah-Hartman <greg@kroah.com>
  * Copyright (C) 2004-2008 Kay Sievers <kay@vrfy.org>
 #include "string-util.h"
 #include "udev-util.h"
 #include "udev.h"
+#include "udevadm-util.h"
 
 static void help(void) {
 
-        printf("%s test OPTIONS <syspath>\n\n"
-               "Test an event run.\n"
+        printf("%s test [OPTIONS] DEVPATH\n\n"
+               "Test an event run.\n\n"
                "  -h --help                            Show this help\n"
-               "     --version                         Show package version\n"
+               "  -V --version                         Show package version\n"
                "  -a --action=ACTION                   Set action string\n"
                "  -N --resolve-names=early|late|never  When to resolve names\n"
                , program_invocation_short_name);
@@ -53,15 +55,16 @@ static int adm_test(struct udev *udev, int argc, char *argv[]) {
         int rc = 0, c;
 
         static const struct option options[] = {
-                { "action", required_argument, NULL, 'a' },
+                { "action",        required_argument, NULL, 'a' },
                 { "resolve-names", required_argument, NULL, 'N' },
-                { "help", no_argument, NULL, 'h' },
+                { "version",       no_argument,       NULL, 'V' },
+                { "help",          no_argument,       NULL, 'h' },
                 {}
         };
 
         log_debug("version %s", PACKAGE_VERSION);
 
-        while ((c = getopt_long(argc, argv, "a:N:h", options, NULL)) >= 0)
+        while ((c = getopt_long(argc, argv, "a:N:Vh", options, NULL)) >= 0)
                 switch (c) {
                 case 'a':
                         action = optarg;
@@ -79,6 +82,9 @@ static int adm_test(struct udev *udev, int argc, char *argv[]) {
                                 exit(EXIT_FAILURE);
                         }
                         break;
+                case 'V':
+                        print_version();
+                        exit(EXIT_SUCCESS);
                 case 'h':
                         help();
                         exit(EXIT_SUCCESS);
@@ -116,7 +122,7 @@ static int adm_test(struct udev *udev, int argc, char *argv[]) {
                 strscpyl(filename, sizeof(filename), "/sys", syspath, NULL);
         else
                 strscpy(filename, sizeof(filename), syspath);
-        util_remove_trailing_chars(filename, '/');
+        delete_trailing_chars(filename, "/");
 
         dev = udev_device_new_from_synthetic_event(udev, filename, action);
         if (dev == NULL) {