chiark / gitweb /
udevinitsend: handle replay messages correctly
[elogind.git] / udevd.c
diff --git a/udevd.c b/udevd.c
index b5597eab404c44b50f3258145746635b0abecbdc..873b05d946ec276936c3b05098d488ae68b772da 100644 (file)
--- a/udevd.c
+++ b/udevd.c
@@ -542,13 +542,15 @@ static struct uevent_msg *get_udevd_msg(void)
        }
 
 switch (usend_msg.type) {
-       case UDEVD_UEVENT:
-               dbg("udevd message (UEVENT) received");
+       case UDEVD_UDEVSEND:
+       case UDEVD_INITSEND:
+               dbg("udevd event message received");
                envbuf_size = size - offsetof(struct udevd_msg, envbuf);
                dbg("envbuf_size=%i", envbuf_size);
                msg = get_msg_from_envbuf(usend_msg.envbuf, envbuf_size);
                if (msg == NULL)
                        return NULL;
+               msg->type = usend_msg.type;
                return msg;
        case UDEVD_STOP_EXEC_QUEUE:
                dbg("udevd message (STOP_EXEC_QUEUE) received");
@@ -566,7 +568,7 @@ switch (usend_msg.type) {
 }
 
 /* receive the kernel user event message and do some sanity checks */
-static struct uevent_msg *get_uevent_msg(void)
+static struct uevent_msg *get_nl_msg(void)
 {
        struct uevent_msg *msg;
        int bufpos;
@@ -591,6 +593,7 @@ static struct uevent_msg *get_uevent_msg(void)
        msg = get_msg_from_envbuf(&buffer[bufpos], size-bufpos);
        if (msg == NULL)
                return NULL;
+       msg->type = UDEVD_NL;
 
        /* validate message */
        pos = strchr(buffer, '@');
@@ -766,6 +769,8 @@ int main(int argc, char *argv[], char *envp[])
        fd_set readfds;
        const char *value;
        int uevent_nl_active = 0;
+       int daemonize = 0;
+       int i;
 
        logging_init("udevd");
        udev_init_config();
@@ -776,8 +781,18 @@ int main(int argc, char *argv[], char *envp[])
                goto exit;
        }
 
-       /* daemonize on request */
-       if (argc == 2 && strcmp(argv[1], "-d") == 0) {
+       for (i = 1 ; i < argc; i++) {
+               char *arg = argv[i];
+               if (strcmp(arg, "--daemon") == 0 || strcmp(arg, "-d") == 0) {
+                       info("will daemonize");
+                       daemonize = 1;
+               }
+               if (strcmp(arg, "--stop-exec-queue") == 0) {
+                       info("will not execute event until START_EXEC_QUEUE is received");
+                       stop_exec_q = 1;
+               }
+       }
+       if (daemonize) {
                pid_t pid;
 
                pid = fork();
@@ -923,7 +938,7 @@ int main(int argc, char *argv[], char *envp[])
                        msg = get_udevd_msg();
                        if (msg) {
                                /* discard kernel messages if netlink is active */
-                               if (uevent_nl_active && msg->seqnum != 0) {
+                               if (uevent_nl_active && msg->type == UDEVD_UDEVSEND && msg->seqnum != 0) {
                                        dbg("skip uevent_helper message, netlink is active");
                                        free(msg);
                                        continue;
@@ -933,7 +948,7 @@ int main(int argc, char *argv[], char *envp[])
                }
 
                if (FD_ISSET(uevent_nl_sock, &workreadfds)) {
-                       msg = get_uevent_msg();
+                       msg = get_nl_msg();
                        if (msg) {
                                msg_queue_insert(msg);
                                /* disable kernel uevent_helper with first netlink message */