chiark / gitweb /
udevd: control - no not delete socket file when --daemon is used
[elogind.git] / udev / udevadm-settle.c
index afd4af5f4b06617676f3bc8f4b8aed9d19ffb2de..a59d7c39e5b283e71288ff68ed8c6b3f38d0630e 100644 (file)
@@ -36,7 +36,7 @@
 
 #include "udev.h"
 
-int udevadm_settle(struct udev *udev, int argc, char *argv[])
+static int adm_settle(struct udev *udev, int argc, char *argv[])
 {
        static const struct option options[] = {
                { "seq-start", required_argument, NULL, 's' },
@@ -52,7 +52,7 @@ int udevadm_settle(struct udev *udev, int argc, char *argv[])
        unsigned long long end = 0;
        int quiet = 0;
        const char *exists = NULL;
-       unsigned int timeout = 180;
+       unsigned int timeout = 120;
        struct pollfd pfd[1];
        struct udev_queue *udev_queue = NULL;
        int rc = EXIT_FAILURE;
@@ -96,7 +96,9 @@ int udevadm_settle(struct udev *udev, int argc, char *argv[])
                               "  --exit-if-exists=<file> stop waiting if file exists\n"
                               "  --quiet                 do not print list after timeout\n"
                               "  --help\n\n");
-                       exit(0);
+                       exit(EXIT_SUCCESS);
+               default:
+                       exit(EXIT_FAILURE);
                }
        }
 
@@ -136,7 +138,7 @@ int udevadm_settle(struct udev *udev, int argc, char *argv[])
        if (getuid() == 0) {
                struct udev_ctrl *uctrl;
 
-               uctrl = udev_ctrl_new_from_socket(udev, UDEV_CTRL_SOCK_PATH);
+               uctrl = udev_ctrl_new(udev);
                if (uctrl != NULL) {
                        if (udev_ctrl_send_ping(uctrl, timeout) < 0) {
                                info(udev, "no connection to daemon\n");
@@ -153,7 +155,7 @@ int udevadm_settle(struct udev *udev, int argc, char *argv[])
        if (pfd[0].fd < 0) {
                err(udev, "inotify_init failed: %m\n");
        } else {
-               if (inotify_add_watch(pfd[0].fd, udev_get_run_path(udev), IN_CLOSE_WRITE) < 0) {
+               if (inotify_add_watch(pfd[0].fd, udev_get_run_path(udev), IN_MOVED_TO) < 0) {
                        err(udev, "watching '%s' failed\n", udev_get_run_path(udev));
                        close(pfd[0].fd);
                        pfd[0].fd = -1;
@@ -183,8 +185,14 @@ int udevadm_settle(struct udev *udev, int argc, char *argv[])
                }
 
                if (pfd[0].fd >= 0) {
-                       /* wake up once every second, or whenever the queue file gets gets closed */
-                       if (poll(pfd, 1, 1000) > 0 && pfd[0].revents & POLLIN) {
+                       int delay;
+
+                       if (exists != NULL || start > 0)
+                               delay = 100;
+                       else
+                               delay = 1000;
+                       /* wake up after delay, or immediately after the queue is rebuilt */
+                       if (poll(pfd, 1, delay) > 0 && pfd[0].revents & POLLIN) {
                                char buf[sizeof(struct inotify_event) + PATH_MAX];
 
                                read(pfd[0].fd, buf, sizeof(buf));
@@ -219,3 +227,9 @@ out:
        udev_queue_unref(udev_queue);
        return rc;
 }
+
+const struct udevadm_cmd udevadm_settle = {
+       .name = "settle",
+       .cmd = adm_settle,
+       .help = "wait for the event queue to finish",
+};