chiark / gitweb /
_noreturn_ --> noreturn for C11 compat
[elogind.git] / src / udev / udevadm-settle.c
index d7fbc9e5605ac12c00d9d3d93015f34a94879347..1468f0358fe54d6b638f9173ba8e9d64fad119c6 100644 (file)
@@ -35,6 +35,7 @@
 #include <sys/types.h>
 
 #include "udev.h"
+#include "util.h"
 
 static int adm_settle(struct udev *udev, int argc, char *argv[])
 {
@@ -47,23 +48,27 @@ static int adm_settle(struct udev *udev, int argc, char *argv[])
                 { "help", no_argument, NULL, 'h' },
                 {}
         };
-        unsigned long long start_usec = now_usec();
-        unsigned long long start = 0;
-        unsigned long long end = 0;
+        usec_t start_usec = now(CLOCK_MONOTONIC);
+        usec_t start = 0;
+        usec_t end = 0;
         int quiet = 0;
         const char *exists = NULL;
         unsigned int timeout = 120;
-        struct pollfd pfd[1];
+        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)
+                if (option == -1) {
+                        if (optind < argc) {
+                                fprintf(stderr, "Extraneous argument: '%s'\n", argv[optind]);
+                                exit(EXIT_FAILURE);
+                        }
                         break;
+                }
 
                 switch (option) {
                 case 's':
@@ -72,13 +77,17 @@ static int adm_settle(struct udev *udev, int argc, char *argv[])
                 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");
+                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 'q':
                         quiet = 1;
                         break;
@@ -123,7 +132,7 @@ static int adm_settle(struct udev *udev, int argc, char *argv[])
                         start = 0;
                         end = 0;
                 }
-                log_debug("start=%llu end=%llu current=%llu\n", start, end, kernel_seq);
+                log_debug("start=%llu end=%llu current=%llu\n", (unsigned long long)start, (unsigned long long)end, kernel_seq);
         } else {
                 if (end > 0) {
                         log_error("seq-end needs seq-start parameter, ignoring\n");
@@ -152,8 +161,8 @@ static int adm_settle(struct udev *udev, int argc, char *argv[])
         if (pfd[0].fd < 0) {
                 log_error("inotify_init failed: %m\n");
         } else {
-                if (inotify_add_watch(pfd[0].fd, udev_get_run_path(udev), IN_MOVED_TO) < 0) {
-                        log_error("watching '%s' failed\n", udev_get_run_path(udev));
+                if (inotify_add_watch(pfd[0].fd, "/run/udev" , IN_MOVED_TO) < 0) {
+                        log_error("watching /run/udev failed\n");
                         close(pfd[0].fd);
                         pfd[0].fd = -1;
                 }
@@ -199,9 +208,9 @@ static int adm_settle(struct udev *udev, int argc, char *argv[])
                 }
 
                 if (timeout > 0) {
-                        unsigned long long age_usec;
+                        usec_t age_usec;
 
-                        age_usec = now_usec() - start_usec;
+                        age_usec = now(CLOCK_MONOTONIC) - start_usec;
                         if (age_usec / (1000 * 1000) >= timeout) {
                                 struct udev_list_entry *list_entry;