diff --git a/man/udevadm.xml b/man/udevadm.xml
index 30a6ac423a..6fc4e8d50c 100644
--- a/man/udevadm.xml
+++ b/man/udevadm.xml
@@ -82,6 +82,7 @@
+
Print help text.
@@ -89,26 +90,28 @@
- udevadm info options
+ udevadm info OPTIONS DEVPATH|FILE
Queries the udev database for device information
stored in the udev database. It can also query the properties
of a device from its sysfs representation to help creating udev
rules that match this device.
-
+
+
Query the database for the specified type of device
data. It needs the or
- to identify the specified
- device. Valid queries are: name,
- symlink, path,
- property,
+ to identify the specified device.
+ Valid TYPEs are:
+ name, symlink,
+ path, property,
all.
-
+
+
The /sys path of the device to
query, e.g.
@@ -121,7 +124,8 @@
-
+
+
The name of the device node or a symlink to query,
e.g. /dev/sda.
@@ -132,6 +136,7 @@
+
Print absolute paths in name or symlink
@@ -139,6 +144,7 @@
+
Print all sysfs properties of the specified device that can be used
@@ -147,31 +153,36 @@
+
Print output as key/value pairs. Values are enclosed in single quotes.
-
+
+
Add a prefix to the key name of exported values.
-
+
+
Print major/minor numbers of the underlying device, where the file
lives on.
+
Export the content of the udev database.
+
Cleanup the udev database.
@@ -184,6 +195,7 @@
+
Print help text.
@@ -196,19 +208,22 @@
Request device events from the kernel. Primarily used to replay events at system coldplug time.
+
Print the list of devices which will be triggered.
+
Do not actually trigger the event.
-
+
+
Trigger a specific type of devices. Valid types are:
devices, subsystems.
@@ -216,68 +231,95 @@
-
+
+
- Type of event to be triggered. The default value is change.
+ Type of event to be triggered. The default value is
+ change.
-
+
+
- Trigger events for devices which belong to a matching subsystem. This option
- can be specified multiple times and supports shell style pattern matching.
+ Trigger events for devices which belong to a
+ matching subsystem. This option can be specified multiple
+ times and supports shell style pattern matching.
-
+
+
Do not trigger events for devices which belong to a matching subsystem. This option
can be specified multiple times and supports shell style pattern matching.
-
+
+
- Trigger events for devices with a matching sysfs attribute. If a value is specified
- along with the attribute name, the content of the attribute is matched against the given
- value using shell style pattern matching. If no value is specified, the existence of the
- sysfs attribute is checked. This option can be specified multiple times.
+ Trigger events for devices with a matching sysfs
+ attribute. If a value is specified along with the
+ attribute name, the content of the attribute is matched
+ against the given value using shell style pattern
+ matching. If no value is specified, the existence of the
+ sysfs attribute is checked. This option can be specified
+ multiple times.
-
+
+
- Do not trigger events for devices with a matching sysfs attribute. If a value is
- specified along with the attribute name, the content of the attribute is matched against
- the given value using shell style pattern matching. If no value is specified, the existence
- of the sysfs attribute is checked. This option can be specified multiple times.
+ Do not trigger events for devices with a matching
+ sysfs attribute. If a value is specified along with the
+ attribute name, the content of the attribute is matched
+ against the given value using shell style pattern
+ matching. If no value is specified, the existence of the
+ sysfs attribute is checked. This option can be specified
+ multiple times.
-
+
+
- Trigger events for devices with a matching property value. This option can be
- specified multiple times and supports shell style pattern matching.
+ Trigger events for devices with a matching property
+ value. This option can be specified multiple times and
+ supports shell style pattern matching.
-
+
+
- Trigger events for devices with a matching tag. This option can be
- specified multiple times.
+ Trigger events for devices with a matching tag. This
+ option can be specified multiple times.
-
+
+
- Trigger events for devices with a matching sys device name. This option can be
- specified multiple times and supports shell style pattern matching.
+ Trigger events for devices with a matching sys
+ device name. This option can be specified multiple times
+ and supports shell style pattern matching.
-
+
+
- Trigger events for all children of a given device.
+ Trigger events for all children of a given
+ device.
+
+
+
+
+
+
+ Print help text.
@@ -287,38 +329,46 @@
Watches the udev event queue, and exits if all current events are handled.
-
+
+
- Maximum number of seconds to wait for the event queue to become empty.
- The default value is 120 seconds. A value of 0 will check if the queue is empty
- and always return immediately.
+ Maximum number of seconds to wait for the event
+ queue to become empty. The default value is 120 seconds. A
+ value of 0 will check if the queue is empty and always
+ return immediately.
-
+
+
- Wait only for events after the given sequence number.
+ Wait only for events after the given sequence
+ number.
-
+
+
Wait only for events before the given sequence number.
-
+
+
Stop waiting if file exists.
+
Do not print any output, like the remaining queue entries when reaching the timeout.
+
Print help text.
@@ -331,12 +381,14 @@
Modify the internal state of the running udev daemon.
+
Signal and wait for systemd-udevd to exit.
+
Set the internal log level of systemd-udevd. Valid values are the numerical
@@ -345,6 +397,7 @@
+
Signal systemd-udevd to stop executing new events. Incoming events
@@ -352,12 +405,14 @@
+
Signal systemd-udevd to enable the execution of events.
+
Signal systemd-udevd to reload the rules files and other databases like the kernel
@@ -366,12 +421,14 @@
+
Set a global property for all events.
+
value
Set the maximum number of events, systemd-udevd will handle at the
@@ -385,6 +442,7 @@
+
Print help text.
@@ -400,36 +458,42 @@
+
Print the kernel uevents.
+
Print the udev event after the rule processing.
+
Also print the properties of the event.
+
Filter events by subsystem[/devtype]. Only udev events with a matching subsystem value will pass.
+
Filter events by property. Only udev events with a given tag attached will pass.
+
Print help text.
@@ -442,6 +506,7 @@
Maintain the hardware database index in /etc/udev/hwdb.bin.
+
Compile the hardware database information located in /usr/lib/udev/hwdb.d/,
@@ -452,6 +517,7 @@
+
Query the database with a modalias string, and print the
@@ -459,11 +525,19 @@
+
Alternative root path in the filesystem for reading and writing files.
+
+
+
+
+ Print help text.
+
+
@@ -471,12 +545,14 @@
Simulate a udev event run for the given device, and print debug output.
+
The action string.
+
Specify when udevadm should resolve names of users
@@ -489,6 +565,7 @@
+
Print help text.
@@ -497,10 +574,13 @@
- udevadm test-builtin options command devpath
- Run a built-in command for the given device, and print debug output.
+ udevadm test-builtin options COMMAND DEVPATH
+ Run a built-in command COMMAND
+ for device DEVPATH, and print debug
+ output.
+
Print help text.
diff --git a/src/udev/scsi_id/scsi_id.c b/src/udev/scsi_id/scsi_id.c
index f005638463..6a4cf0c09e 100644
--- a/src/udev/scsi_id/scsi_id.c
+++ b/src/udev/scsi_id/scsi_id.c
@@ -44,7 +44,7 @@ static const struct option options[] = {
{ "replace-whitespace", no_argument, NULL, 'u' },
{ "sg-version", required_argument, NULL, 's' },
{ "verbose", no_argument, NULL, 'v' },
- { "version", no_argument, NULL, 'V' },
+ { "version", no_argument, NULL, 'V' }, /* don't advertise -V */
{ "export", no_argument, NULL, 'x' },
{ "help", no_argument, NULL, 'h' },
{}
@@ -313,6 +313,22 @@ static int get_file_options(struct udev *udev,
return retval;
}
+static void help(void) {
+ printf("Usage: scsi_id [OPTION...] DEVICE\n"
+ " -d,--device= device node for SG_IO commands\n"
+ " -f,--config= location of config file\n"
+ " -p,--page=0x80|0x83|pre-spc3-83 SCSI page (0x80, 0x83, pre-spc3-83)\n"
+ " -s,--sg-version=3|4 use SGv3 or SGv4\n"
+ " -b,--blacklisted threat device as blacklisted\n"
+ " -g,--whitelisted threat device as whitelisted\n"
+ " -u,--replace-whitespace replace all whitespace by underscores\n"
+ " -v,--verbose verbose logging\n"
+ " --version print version\n"
+ " -x,--export print values as environment keys\n"
+ " -h,--help print this help text\n\n");
+
+}
+
static int set_options(struct udev *udev,
int argc, char **argv,
char *maj_min_dev)
@@ -325,7 +341,7 @@ static int set_options(struct udev *udev,
* file) we have to reset this back to 1.
*/
optind = 1;
- while ((option = getopt_long(argc, argv, "d:f:ghp:uvVx", options, NULL)) >= 0)
+ while ((option = getopt_long(argc, argv, "d:f:gp:uvVxh", options, NULL)) >= 0)
switch (option) {
case 'b':
all_good = false;
@@ -345,18 +361,7 @@ static int set_options(struct udev *udev,
break;
case 'h':
- printf("Usage: scsi_id [OPTION...] DEVICE\n"
- " --device= device node for SG_IO commands\n"
- " --config= location of config file\n"
- " --page=0x80|0x83|pre-spc3-83 SCSI page (0x80, 0x83, pre-spc3-83)\n"
- " --sg-version=3|4 use SGv3 or SGv4\n"
- " --blacklisted threat device as blacklisted\n"
- " --whitelisted threat device as whitelisted\n"
- " --replace-whitespace replace all whitespace by underscores\n"
- " --verbose verbose logging\n"
- " --version print version\n"
- " --export print values as environment keys\n"
- " --help print this help text\n\n");
+ help();
exit(0);
case 'p':
diff --git a/src/udev/udevadm-control.c b/src/udev/udevadm-control.c
index c5a189257d..00a909fc31 100644
--- a/src/udev/udevadm-control.c
+++ b/src/udev/udevadm-control.c
@@ -30,35 +30,35 @@
static void print_help(void)
{
printf("Usage: udevadm control COMMAND\n"
- " --exit instruct the daemon to cleanup and exit\n"
- " --log-priority= set the udev log level for the daemon\n"
- " --stop-exec-queue do not execute events, queue only\n"
- " --start-exec-queue execute events, flush queue\n"
- " --reload reload rules and databases\n"
- " --property== set a global property for all events\n"
- " --children-max= maximum number of children\n"
- " --timeout= maximum time to block for a reply\n"
- " --help print this help text\n\n");
+ " -e,--exit instruct the daemon to cleanup and exit\n"
+ " -l,--log-priority=LEVEL set the udev log level for the daemon\n"
+ " -s,--stop-exec-queue do not execute events, queue only\n"
+ " -S,--start-exec-queue execute events, flush queue\n"
+ " -R,--reload reload rules and databases\n"
+ " -p,--property=KEY=VALUE set a global property for all events\n"
+ " -m,--children-max=N maximum number of children\n"
+ " --timeout=SECONDS maximum time to block for a reply\n"
+ " -h,--help print this help text\n\n");
}
static int adm_control(struct udev *udev, int argc, char *argv[])
{
struct udev_ctrl *uctrl = NULL;
int timeout = 60;
- int rc = 1;
+ int rc = 1, c;
static const struct option options[] = {
- { "exit", no_argument, NULL, 'e' },
- { "log-priority", required_argument, NULL, 'l' },
- { "stop-exec-queue", no_argument, NULL, 's' },
- { "start-exec-queue", no_argument, NULL, 'S' },
- { "reload", no_argument, NULL, 'R' },
- { "reload-rules", no_argument, NULL, 'R' },
- { "property", required_argument, NULL, 'p' },
- { "env", required_argument, NULL, 'p' },
- { "children-max", required_argument, NULL, 'm' },
- { "timeout", required_argument, NULL, 't' },
- { "help", no_argument, NULL, 'h' },
+ { "exit", no_argument, NULL, 'e' },
+ { "log-priority", required_argument, NULL, 'l' },
+ { "stop-exec-queue", no_argument, NULL, 's' },
+ { "start-exec-queue", no_argument, NULL, 'S' },
+ { "reload", no_argument, NULL, 'R' },
+ { "reload-rules", no_argument, NULL, 'R' }, /* alias for -R */
+ { "property", required_argument, NULL, 'p' },
+ { "env", required_argument, NULL, 'p' }, /* alias for -p */
+ { "children-max", required_argument, NULL, 'm' },
+ { "timeout", required_argument, NULL, 't' },
+ { "help", no_argument, NULL, 'h' },
{}
};
@@ -71,14 +71,8 @@ static int adm_control(struct udev *udev, int argc, char *argv[])
if (uctrl == NULL)
return 2;
- for (;;) {
- int option;
-
- option = getopt_long(argc, argv, "el:sSRp:m:h", options, NULL);
- if (option == -1)
- break;
-
- switch (option) {
+ while ((c = getopt_long(argc, argv, "el:sSRp:m:h", options, NULL)) >= 0)
+ switch (c) {
case 'e':
if (udev_ctrl_send_exit(uctrl, timeout) < 0)
rc = 2;
@@ -157,12 +151,11 @@ static int adm_control(struct udev *udev, int argc, char *argv[])
rc = 0;
break;
}
- }
- if (argv[optind] != NULL)
- fprintf(stderr, "unknown option\n");
+ if (optind < argc)
+ fprintf(stderr, "Extraneous argument: %s\n", argv[optind]);
else if (optind == 1)
- fprintf(stderr, "missing option\n");
+ fprintf(stderr, "Option missing\n");
out:
udev_ctrl_unref(uctrl);
return rc;
diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c
index d0cce84859..61a3b08199 100644
--- a/src/udev/udevadm-hwdb.c
+++ b/src/udev/udevadm-hwdb.c
@@ -526,35 +526,29 @@ static int import_file(struct udev *udev, struct trie *trie, const char *filenam
static void help(void) {
printf("Usage: udevadm hwdb OPTIONS\n"
- " --update update the hardware database\n"
- " --test= query database and print result\n"
- " --root= alternative root path in the filesystem\n"
- " --help\n\n");
+ " -u,--update update the hardware database\n"
+ " -t,--test=MODALIAS query database and print result\n"
+ " -r,--root=PATH alternative root path in the filesystem\n"
+ " -h,--help\n\n");
}
static int adm_hwdb(struct udev *udev, int argc, char *argv[]) {
static const struct option options[] = {
- { "update", no_argument, NULL, 'u' },
- { "root", required_argument, NULL, 'r' },
- { "test", required_argument, NULL, 't' },
- { "help", no_argument, NULL, 'h' },
+ { "update", no_argument, NULL, 'u' },
+ { "test", required_argument, NULL, 't' },
+ { "root", required_argument, NULL, 'r' },
+ { "help", no_argument, NULL, 'h' },
{}
};
const char *test = NULL;
const char *root = "";
bool update = false;
struct trie *trie = NULL;
- int err;
+ int err, c;
int rc = EXIT_SUCCESS;
- for (;;) {
- int option;
-
- option = getopt_long(argc, argv, "ut:r:h", options, NULL);
- if (option == -1)
- break;
-
- switch (option) {
+ while ((c = getopt_long(argc, argv, "ut:r:h", options, NULL)) >= 0)
+ switch(c) {
case 'u':
update = true;
break;
@@ -567,12 +561,15 @@ static int adm_hwdb(struct udev *udev, int argc, char *argv[]) {
case 'h':
help();
return EXIT_SUCCESS;
+ case '?':
+ return EXIT_FAILURE;
+ default:
+ assert_not_reached("Unknown option");
}
- }
if (!update && !test) {
- help();
- return EXIT_SUCCESS;
+ log_error("Either --update or --test must be used");
+ return EXIT_FAILURE;
}
if (update) {
diff --git a/src/udev/udevadm-info.c b/src/udev/udevadm-info.c
index 2ee59fe075..2d2cf4336e 100644
--- a/src/udev/udevadm-info.c
+++ b/src/udev/udevadm-info.c
@@ -302,43 +302,44 @@ static int uinfo(struct udev *udev, int argc, char *argv[])
const char *export_prefix = NULL;
char name[UTIL_PATH_SIZE];
struct udev_list_entry *list_entry;
- int rc = 0;
+ int rc = 0, c;
static const struct option options[] = {
- { "name", required_argument, NULL, 'n' },
- { "path", required_argument, NULL, 'p' },
- { "query", required_argument, NULL, 'q' },
- { "attribute-walk", no_argument, NULL, 'a' },
- { "cleanup-db", no_argument, NULL, 'c' },
- { "export-db", no_argument, NULL, 'e' },
- { "root", no_argument, NULL, 'r' },
+ { "name", required_argument, NULL, 'n' },
+ { "path", required_argument, NULL, 'p' },
+ { "query", required_argument, NULL, 'q' },
+ { "attribute-walk", no_argument, NULL, 'a' },
+ { "cleanup-db", no_argument, NULL, 'c' },
+ { "export-db", no_argument, NULL, 'e' },
+ { "root", no_argument, NULL, 'r' },
{ "device-id-of-file", required_argument, NULL, 'd' },
- { "export", no_argument, NULL, 'x' },
- { "export-prefix", required_argument, NULL, 'P' },
- { "version", no_argument, NULL, 'V' },
- { "help", no_argument, NULL, 'h' },
+ { "export", no_argument, NULL, 'x' },
+ { "export-prefix", required_argument, NULL, 'P' },
+ { "version", no_argument, NULL, 'V' },
+ { "help", no_argument, NULL, 'h' },
{}
};
static const char *usage =
- "Usage: udevadm info OPTIONS\n"
- " --query= query device information:\n"
+ "Usage: udevadm info [OPTIONS] [DEVPATH|FILE]\n"
+ " -q,--query=TYPE query device information:\n"
" name name of device node\n"
" symlink pointing to node\n"
" path sys device path\n"
" property the device properties\n"
" all all values\n"
- " --path= sys device path used for query or attribute walk\n"
- " --name= node or symlink name used for query or attribute walk\n"
- " --root prepend dev directory to path names\n"
- " --attribute-walk print all key matches while walking along the chain\n"
+ " -p,--path=SYSPATH sys device path used for query or attribute walk\n"
+ " -n,--name=NAME node or symlink name used for query or attribute walk\n"
+ " -r,--root prepend dev directory to path names\n"
+ " -a,--attribute-walk print all key matches walking along the chain\n"
" of parent devices\n"
- " --device-id-of-file= print major:minor of device containing this file\n"
- " --export export key/value pairs\n"
- " --export-prefix export the key name with a prefix\n"
- " --export-db export the content of the udev database\n"
- " --cleanup-db cleanup the udev database\n"
- " --help\n";
+ " -d,--device-id-of-file=FILE print major:minor of device containing this file\n"
+ " -x,--export export key/value pairs\n"
+ " -P,--export-prefix export the key name with a prefix\n"
+ " -e,--export-db export the content of the udev database\n"
+ " -c,--cleanup-db cleanup the udev database\n"
+ " --version print version of the program\n"
+ " -h,--help print this message\n";
enum action_type {
ACTION_QUERY,
@@ -354,14 +355,8 @@ static int uinfo(struct udev *udev, int argc, char *argv[])
QUERY_ALL,
} query = QUERY_ALL;
- for (;;) {
- int option;
-
- option = getopt_long(argc, argv, "aced:n:p:q:rxP:RVh", options, NULL);
- if (option == -1)
- break;
-
- switch (option) {
+ while ((c = getopt_long(argc, argv, "aced:n:p:q:rxP:RVh", options, NULL)) >= 0)
+ switch (c) {
case 'n': {
if (device != NULL) {
fprintf(stderr, "device already specified\n");
@@ -441,7 +436,6 @@ static int uinfo(struct udev *udev, int argc, char *argv[])
rc = 1;
goto exit;
}
- }
switch (action) {
case ACTION_QUERY:
diff --git a/src/udev/udevadm-monitor.c b/src/udev/udevadm-monitor.c
index 4d6af49b96..2c200b7068 100644
--- a/src/udev/udevadm-monitor.c
+++ b/src/udev/udevadm-monitor.c
@@ -64,6 +64,16 @@ static void print_device(struct udev_device *device, const char *source, int pro
}
}
+static void help(void) {
+ printf("Usage: udevadm monitor [--property] [--kernel] [--udev] [--help]\n"
+ " -p,--property print the event properties\n"
+ " -k,--kernel print kernel uevents\n"
+ " -u,--udev print udev events\n"
+ " -s,--subsystem-match=SUBSYSTEM[/DEVTYPE] filter events by subsystem\n"
+ " -t,--tag-match=TAG filter events by tag\n"
+ " -h,--help\n\n");
+}
+
static int adm_monitor(struct udev *udev, int argc, char *argv[])
{
struct sigaction act = {};
@@ -79,28 +89,24 @@ static int adm_monitor(struct udev *udev, int argc, char *argv[])
int fd_ep = -1;
int fd_kernel = -1, fd_udev = -1;
struct epoll_event ep_kernel, ep_udev;
- int rc = 0;
+ int rc = 0, c;
static const struct option options[] = {
- { "property", no_argument, NULL, 'p' },
- { "environment", no_argument, NULL, 'e' },
- { "kernel", no_argument, NULL, 'k' },
- { "udev", no_argument, NULL, 'u' },
+ { "property", no_argument, NULL, 'p' },
+ { "environment", no_argument, NULL, 'e' }, /* alias for -p */
+ { "kernel", no_argument, NULL, 'k' },
+ { "udev", no_argument, NULL, 'u' },
{ "subsystem-match", required_argument, NULL, 's' },
- { "tag-match", required_argument, NULL, 't' },
- { "help", no_argument, NULL, 'h' },
+ { "tag-match", required_argument, NULL, 't' },
+ { "help", no_argument, NULL, 'h' },
{}
};
udev_list_init(udev, &subsystem_match_list, true);
udev_list_init(udev, &tag_match_list, true);
- for (;;) {
- option = getopt_long(argc, argv, "pekus:t:h", options, NULL);
- if (option == -1)
- break;
-
- switch (option) {
+ while((c = getopt_long(argc, argv, "pekus:t:h", options, NULL)) >= 0)
+ switch (c) {
case 'p':
case 'e':
prop = true;
@@ -129,19 +135,12 @@ static int adm_monitor(struct udev *udev, int argc, char *argv[])
udev_list_entry_add(&tag_match_list, optarg, NULL);
break;
case 'h':
- printf("Usage: udevadm monitor [--property] [--kernel] [--udev] [--help]\n"
- " --property print the event properties\n"
- " --kernel print kernel uevents\n"
- " --udev print udev events\n"
- " --subsystem-match= filter events by subsystem\n"
- " --tag-match= filter events by tag\n"
- " --help\n\n");
+ help();
goto out;
default:
rc = 1;
goto out;
}
- }
if (!print_kernel && !print_udev) {
print_kernel = true;
diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c
index 1468f0358f..362c3b2f98 100644
--- a/src/udev/udevadm-settle.c
+++ b/src/udev/udevadm-settle.c
@@ -37,15 +37,25 @@
#include "udev.h"
#include "util.h"
+static void help(void) {
+ printf("Usage: udevadm settle OPTIONS\n"
+ " -t,--timeout= maximum time to wait for events\n"
+ " -s,--seq-start= first seqnum to wait for\n"
+ " -e,--seq-end= last seqnum to wait for\n"
+ " -E,--exit-if-exists= stop waiting if file exists\n"
+ " -q,--quiet do not print list after timeout\n"
+ " -h,--help\n\n");
+}
+
static int adm_settle(struct udev *udev, int argc, char *argv[])
{
static const struct option options[] = {
- { "seq-start", required_argument, NULL, 's' },
- { "seq-end", required_argument, NULL, 'e' },
- { "timeout", required_argument, NULL, 't' },
+ { "seq-start", required_argument, NULL, 's' },
+ { "seq-end", required_argument, NULL, 'e' },
+ { "timeout", required_argument, NULL, 't' },
{ "exit-if-exists", required_argument, NULL, 'E' },
- { "quiet", no_argument, NULL, 'q' },
- { "help", no_argument, NULL, 'h' },
+ { "quiet", no_argument, NULL, 'q' },
+ { "help", no_argument, NULL, 'h' },
{}
};
usec_t start_usec = now(CLOCK_MONOTONIC);
@@ -56,21 +66,10 @@ static int adm_settle(struct udev *udev, int argc, char *argv[])
unsigned int timeout = 120;
struct pollfd pfd[1] = { {.fd = -1}, };
struct udev_queue *udev_queue = NULL;
- int rc = EXIT_FAILURE;
+ int rc = EXIT_FAILURE, c;
- for (;;) {
- int option;
-
- option = getopt_long(argc, argv, "s:e:t:E:qh", options, NULL);
- if (option == -1) {
- if (optind < argc) {
- fprintf(stderr, "Extraneous argument: '%s'\n", argv[optind]);
- exit(EXIT_FAILURE);
- }
- break;
- }
-
- switch (option) {
+ while ((c = getopt_long(argc, argv, "s:e:t:E:qh", options, NULL)) >= 0)
+ switch (c) {
case 's':
start = strtoull(optarg, NULL, 0);
break;
@@ -87,25 +86,25 @@ static int adm_settle(struct udev *udev, int argc, char *argv[])
exit(EXIT_FAILURE);
};
break;
- };
- case 'q':
- quiet = 1;
- break;
+ }
case 'E':
exists = optarg;
break;
+ case 'q':
+ quiet = 1;
+ break;
case 'h':
- printf("Usage: udevadm settle OPTIONS\n"
- " --timeout= maximum time to wait for events\n"
- " --seq-start= first seqnum to wait for\n"
- " --seq-end= last seqnum to wait for\n"
- " --exit-if-exists= stop waiting if file exists\n"
- " --quiet do not print list after timeout\n"
- " --help\n\n");
+ help();
exit(EXIT_SUCCESS);
- default:
+ case '?':
exit(EXIT_FAILURE);
+ default:
+ assert_not_reached("Unkown argument");
}
+
+ if (optind < argc) {
+ fprintf(stderr, "Extraneous argument: '%s'\n", argv[optind]);
+ exit(EXIT_FAILURE);
}
udev_queue = udev_queue_new(udev);
diff --git a/src/udev/udevadm-test-builtin.c b/src/udev/udevadm-test-builtin.c
index f4aa21ee72..80418783ff 100644
--- a/src/udev/udevadm-test-builtin.c
+++ b/src/udev/udevadm-test-builtin.c
@@ -37,7 +37,7 @@
static void help(struct udev *udev)
{
fprintf(stderr, "\n");
- fprintf(stderr, "Usage: udevadm builtin [--help] \n");
+ fprintf(stderr, "Usage: udevadm builtin [--help] COMMAND SYSPATH\n");
udev_builtin_list(udev);
fprintf(stderr, "\n");
}
@@ -53,21 +53,14 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[])
char filename[UTIL_PATH_SIZE];
struct udev_device *dev = NULL;
enum udev_builtin_cmd cmd;
- int rc = EXIT_SUCCESS;
+ int rc = EXIT_SUCCESS, c;
- for (;;) {
- int option;
-
- option = getopt_long(argc, argv, "h", options, NULL);
- if (option == -1)
- break;
-
- switch (option) {
+ while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
+ switch (c) {
case 'h':
help(udev);
goto out;
}
- }
command = argv[optind++];
if (command == NULL) {
@@ -79,7 +72,7 @@ static int adm_builtin(struct udev *udev, int argc, char *argv[])
syspath = argv[optind++];
if (syspath == NULL) {
- fprintf(stderr, "syspath missing\n\n");
+ fprintf(stderr, "syspath missing\n");
rc = 3;
goto out;
}
diff --git a/src/udev/udevadm-test.c b/src/udev/udevadm-test.c
index df1409bff6..cd75fad674 100644
--- a/src/udev/udevadm-test.c
+++ b/src/udev/udevadm-test.c
@@ -43,7 +43,7 @@ static int adm_test(struct udev *udev, int argc, char *argv[])
struct udev_list_entry *entry;
sigset_t mask, sigmask_orig;
int err;
- int rc = 0;
+ int rc = 0, c;
static const struct option options[] = {
{ "action", required_argument, NULL, 'a' },
@@ -54,14 +54,8 @@ static int adm_test(struct udev *udev, int argc, char *argv[])
log_debug("version %s\n", VERSION);
- for (;;) {
- int option;
-
- option = getopt_long(argc, argv, "a:s:N:fh", options, NULL);
- if (option == -1)
- break;
-
- switch (option) {
+ while((c = getopt_long(argc, argv, "a:N:h", options, NULL)) >= 0)
+ switch (c) {
case 'a':
action = optarg;
break;
@@ -80,15 +74,18 @@ static int adm_test(struct udev *udev, int argc, char *argv[])
break;
case 'h':
printf("Usage: udevadm test OPTIONS \n"
- " --action= set action string\n"
- " --help\n\n");
+ " -a,--action=ACTION set action string\n"
+ " -N,--resolve-names=early|late|never when to resolve names\n"
+ " -h,--help print this help string\n"
+ "\n");
exit(EXIT_SUCCESS);
- default:
+ case '?':
exit(EXIT_FAILURE);
+ default:
+ assert_not_reached("Unknown option");
}
- }
- syspath = argv[optind];
+ syspath = argv[optind];
if (syspath == NULL) {
fprintf(stderr, "syspath parameter missing\n");
rc = 2;
diff --git a/src/udev/udevadm-trigger.c b/src/udev/udevadm-trigger.c
index d10ca59cca..3608c35cd0 100644
--- a/src/udev/udevadm-trigger.c
+++ b/src/udev/udevadm-trigger.c
@@ -73,22 +73,41 @@ static const char *keyval(const char *str, const char **val, char *buf, size_t s
return buf;
}
+static void help(void) {
+ printf("Usage: udevadm trigger OPTIONS\n"
+ " -v,--verbose print the list of devices while running\n"
+ " -n,--dry-run do not actually trigger the events\n"
+ " -t,--type= type of events to trigger\n"
+ " devices sys devices (default)\n"
+ " subsystems sys subsystems and drivers\n"
+ " -c,--action= event action value, default is \"change\"\n"
+ " -s,--subsystem-match= trigger devices from a matching subsystem\n"
+ " -S,--subsystem-nomatch= exclude devices from a matching subsystem\n"
+ " -a,--attr-match=]> trigger devices with a matching attribute\n"
+ " -A,--attr-nomatch=]> exclude devices with a matching attribute\n"
+ " -p,--property-match== trigger devices with a matching property\n"
+ " -g,--tag-match== trigger devices with a matching property\n"
+ " -y,--sysname-match= trigger devices with a matching name\n"
+ " -b,--parent-match= trigger devices with that parent device\n"
+ " -h,--help\n\n");
+}
+
static int adm_trigger(struct udev *udev, int argc, char *argv[])
{
static const struct option options[] = {
- { "verbose", no_argument, NULL, 'v' },
- { "dry-run", no_argument, NULL, 'n' },
- { "type", required_argument, NULL, 't' },
- { "action", required_argument, NULL, 'c' },
- { "subsystem-match", required_argument, NULL, 's' },
+ { "verbose", no_argument, NULL, 'v' },
+ { "dry-run", no_argument, NULL, 'n' },
+ { "type", required_argument, NULL, 't' },
+ { "action", required_argument, NULL, 'c' },
+ { "subsystem-match", required_argument, NULL, 's' },
{ "subsystem-nomatch", required_argument, NULL, 'S' },
- { "attr-match", required_argument, NULL, 'a' },
- { "attr-nomatch", required_argument, NULL, 'A' },
- { "property-match", required_argument, NULL, 'p' },
- { "tag-match", required_argument, NULL, 'g' },
- { "sysname-match", required_argument, NULL, 'y' },
- { "parent-match", required_argument, NULL, 'b' },
- { "help", no_argument, NULL, 'h' },
+ { "attr-match", required_argument, NULL, 'a' },
+ { "attr-nomatch", required_argument, NULL, 'A' },
+ { "property-match", required_argument, NULL, 'p' },
+ { "tag-match", required_argument, NULL, 'g' },
+ { "sysname-match", required_argument, NULL, 'y' },
+ { "parent-match", required_argument, NULL, 'b' },
+ { "help", no_argument, NULL, 'h' },
{}
};
enum {
@@ -98,6 +117,7 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[])
const char *action = "change";
struct udev_enumerate *udev_enumerate;
int rc = 0;
+ int c;
udev_enumerate = udev_enumerate_new(udev);
if (udev_enumerate == NULL) {
@@ -105,23 +125,12 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[])
goto exit;
}
- for (;;) {
- int option;
+ while ((c = getopt_long(argc, argv, "vno:t:c:s:S:a:A:p:g:y:b:h", options, NULL)) >= 0) {
const char *key;
const char *val;
char buf[UTIL_PATH_SIZE];
- option = getopt_long(argc, argv, "vng:o:t:hc:p:s:S:a:A:y:b:", options, NULL);
- if (option == -1) {
- if (optind < argc) {
- fprintf(stderr, "Extraneous argument: '%s'\n", argv[optind]);
- rc = 1;
- goto exit;
- }
- break;
- }
-
- switch (option) {
+ switch (c) {
case 'v':
verbose = 1;
break;
@@ -194,29 +203,21 @@ static int adm_trigger(struct udev *udev, int argc, char *argv[])
break;
}
case 'h':
- printf("Usage: udevadm trigger OPTIONS\n"
- " --verbose print the list of devices while running\n"
- " --dry-run do not actually trigger the events\n"
- " --type= type of events to trigger\n"
- " devices sys devices (default)\n"
- " subsystems sys subsystems and drivers\n"
- " --action= event action value, default is \"change\"\n"
- " --subsystem-match= trigger devices from a matching subsystem\n"
- " --subsystem-nomatch= exclude devices from a matching subsystem\n"
- " --attr-match=]> trigger devices with a matching attribute\n"
- " --attr-nomatch=]> exclude devices with a matching attribute\n"
- " --property-match== trigger devices with a matching property\n"
- " --tag-match== trigger devices with a matching property\n"
- " --sysname-match= trigger devices with a matching name\n"
- " --parent-match= trigger devices with that parent device\n"
- " --help\n\n");
+ help();
goto exit;
- default:
+ case '?':
rc = 1;
goto exit;
+ default:
+ assert_not_reached("Unknown option");
}
}
+ if (optind < argc) {
+ fprintf(stderr, "Extraneous argument: '%s'\n", argv[optind]);
+ return 1;
+ }
+
switch (device_type) {
case TYPE_SUBSYSTEMS:
udev_enumerate_scan_subsystems(udev_enumerate);