diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-12-17 21:48:14 -0500 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-12-18 23:58:23 -0500 |
commit | 7643ac9a8add1f07ffc237c054feb443b5612717 (patch) | |
tree | 7fb3f5ae619376e81754f3748a4efe23dde01d05 /src | |
parent | ed142bdb68fdcd5ce591152ce0ec9d29898fbac4 (diff) | |
download | systemd-7643ac9a8add1f07ffc237c054feb443b5612717.tar.gz |
udevadm,scsi_id: add short options to help strings and to the man page
Also clean things up a bit here and there.
Diffstat (limited to 'src')
-rw-r--r-- | src/udev/scsi_id/scsi_id.c | 33 | ||||
-rw-r--r-- | src/udev/udevadm-control.c | 59 | ||||
-rw-r--r-- | src/udev/udevadm-hwdb.c | 37 | ||||
-rw-r--r-- | src/udev/udevadm-info.c | 60 | ||||
-rw-r--r-- | src/udev/udevadm-monitor.c | 41 | ||||
-rw-r--r-- | src/udev/udevadm-settle.c | 61 | ||||
-rw-r--r-- | src/udev/udevadm-test-builtin.c | 17 | ||||
-rw-r--r-- | src/udev/udevadm-test.c | 25 | ||||
-rw-r--r-- | src/udev/udevadm-trigger.c | 85 |
9 files changed, 198 insertions, 220 deletions
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=<level> 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=<KEY>=<value> set a global property for all events\n" - " --children-max=<N> maximum number of children\n" - " --timeout=<seconds> 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=<modalias> query database and print result\n" - " --root=<path> 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=<type> 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=<syspath> sys device path used for query or attribute walk\n" - " --name=<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=<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=<subsystem[/devtype]> filter events by subsystem\n" - " --tag-match=<tag> 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=<seconds> maximum time to wait for events\n" + " -s,--seq-start=<seqnum> first seqnum to wait for\n" + " -e,--seq-end=<seqnum> last seqnum to wait for\n" + " -E,--exit-if-exists=<file> 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; - - 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; - } + int rc = EXIT_FAILURE, c; - 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=<seconds> maximum time to wait for events\n" - " --seq-start=<seqnum> first seqnum to wait for\n" - " --seq-end=<seqnum> last seqnum to wait for\n" - " --exit-if-exists=<file> 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] <command> <syspath>\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 <syspath>\n" - " --action=<string> 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=<action> event action value, default is \"change\"\n" + " -s,--subsystem-match=<subsystem> trigger devices from a matching subsystem\n" + " -S,--subsystem-nomatch=<subsystem> exclude devices from a matching subsystem\n" + " -a,--attr-match=<file[=<value>]> trigger devices with a matching attribute\n" + " -A,--attr-nomatch=<file[=<value>]> exclude devices with a matching attribute\n" + " -p,--property-match=<key>=<value> trigger devices with a matching property\n" + " -g,--tag-match=<key>=<value> trigger devices with a matching property\n" + " -y,--sysname-match=<name> trigger devices with a matching name\n" + " -b,--parent-match=<name> 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=<action> event action value, default is \"change\"\n" - " --subsystem-match=<subsystem> trigger devices from a matching subsystem\n" - " --subsystem-nomatch=<subsystem> exclude devices from a matching subsystem\n" - " --attr-match=<file[=<value>]> trigger devices with a matching attribute\n" - " --attr-nomatch=<file[=<value>]> exclude devices with a matching attribute\n" - " --property-match=<key>=<value> trigger devices with a matching property\n" - " --tag-match=<key>=<value> trigger devices with a matching property\n" - " --sysname-match=<name> trigger devices with a matching name\n" - " --parent-match=<name> 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); |