udevadm: improve error message when no option specified for 'control' command
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 11 Jan 2019 23:31:53 +0000 (08:31 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 12 Jan 2019 22:37:49 +0000 (07:37 +0900)
Also drop redundant block, use SYNTHETIC_ERRNO(), and add log_oom().

src/udev/udevadm-control.c

index cb9b4cc..1966af7 100644 (file)
@@ -77,11 +77,12 @@ int control_main(int argc, char *argv[], void *userdata) {
         }
 
         if (argc <= 1)
-                log_error("Option missing");
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "This command expects one or more options.");
 
         uctrl = udev_ctrl_new();
         if (!uctrl)
-                return -ENOMEM;
+                return log_oom();
 
         while ((c = getopt_long(argc, argv, "el:sSRp:m:t:Vh", options, NULL)) >= 0)
                 switch (c) {
@@ -158,13 +159,9 @@ int control_main(int argc, char *argv[], void *userdata) {
                         assert_not_reached("Unknown option.");
                 }
 
-        if (optind < argc) {
-                log_error("Extraneous argument: %s", argv[optind]);
-                return -EINVAL;
-        } else if (optind == 1) {
-                log_error("Option missing");
-                return -EINVAL;
-        }
+        if (optind < argc)
+                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "Extraneous argument: %s", argv[optind]);
 
         return 0;
 }