X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fudev%2Fudevadm-settle.c;h=362c3b2f98bd2749ae64178f0bfddad1e958173e;hb=7643ac9a8add1f07ffc237c054feb443b5612717;hp=c4fc4ee4e50fea063dc45fb1ee5aa96bca40d28e;hpb=f274ece0f76b5709408821e317e87aef76123db6;p=elogind.git diff --git a/src/udev/udevadm-settle.c b/src/udev/udevadm-settle.c index c4fc4ee4e..362c3b2f9 100644 --- a/src/udev/udevadm-settle.c +++ b/src/udev/udevadm-settle.c @@ -35,16 +35,27 @@ #include #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); @@ -55,48 +66,45 @@ 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; - int seconds; - - option = getopt_long(argc, argv, "s:e:t:E:qh", options, NULL); - if (option == -1) - 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; case 'e': end = strtoull(optarg, NULL, 0); break; - case 't': - seconds = atoi(optarg); - if (seconds >= 0) - timeout = seconds; - else - fprintf(stderr, "invalid timeout value\n"); - break; - case 'q': - quiet = 1; + case 't': { + int r; + + r = safe_atou(optarg, &timeout); + if (r < 0) { + fprintf(stderr, "Invalid timeout value '%s': %s\n", + optarg, strerror(-r)); + exit(EXIT_FAILURE); + }; 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);