udevadm: improve error message when no option specified for 'control' command

Also drop redundant block, use SYNTHETIC_ERRNO(), and add log_oom().
This commit is contained in:
Yu Watanabe 2019-01-12 08:31:53 +09:00
parent 7ae3561a5a
commit cf7f501353

View 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;
}