chiark / gitweb /
[PATCH] add MANAGED_EVENT to the forked udev environment
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Tue, 23 Nov 2004 05:14:21 +0000 (06:14 +0100)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 05:35:00 +0000 (22:35 -0700)
This will prevent a loop, if udev sends events back into the
daemon.

udevd.c
udevd.h
udevsend.c

diff --git a/udevd.c b/udevd.c
index 2337493f1ebdf00c37f431b1397f73d8f23fc2b0..bd36d2c192d1e606a84b03e75c1689931cb8e7b4 100644 (file)
--- a/udevd.c
+++ b/udevd.c
@@ -291,7 +291,7 @@ static void handle_udevsend_msg(int sock)
        /* copy environment buffer and reconstruct envp */
        memcpy(msg->envbuf, usend_msg.envbuf, envbuf_size);
        bufpos = 0;
        /* copy environment buffer and reconstruct envp */
        memcpy(msg->envbuf, usend_msg.envbuf, envbuf_size);
        bufpos = 0;
-       for (i = 0; (bufpos < envbuf_size) && (i < HOTPLUG_NUM_ENVP-1); i++) {
+       for (i = 0; (bufpos < envbuf_size) && (i < HOTPLUG_NUM_ENVP-2); i++) {
                int keylen;
                char *key;
 
                int keylen;
                char *key;
 
@@ -314,6 +314,7 @@ static void handle_udevsend_msg(int sock)
                if (strncmp(key, "SEQNUM=", 7) == 0)
                        msg->seqnum = strtoull(&key[7], NULL, 10);
        }
                if (strncmp(key, "SEQNUM=", 7) == 0)
                        msg->seqnum = strtoull(&key[7], NULL, 10);
        }
+       msg->envp[i++] = "MANAGED_EVENT=1";
        msg->envp[i] = NULL;
 
        /* if no seqnum is given, we move straight to exec queue */
        msg->envp[i] = NULL;
 
        /* if no seqnum is given, we move straight to exec queue */
diff --git a/udevd.h b/udevd.h
index b393a28bf94ad8a55eb646a3d7b7786167450219..31f07de8265a693ec3b2c8b0d5af677e67b527f6 100644 (file)
--- a/udevd.h
+++ b/udevd.h
@@ -36,7 +36,7 @@
 
 struct udevsend_msg {
        char magic[20];
 
 struct udevsend_msg {
        char magic[20];
-       char envbuf[HOTPLUG_BUFFER_SIZE];
+       char envbuf[HOTPLUG_BUFFER_SIZE+256];
 };
 
 struct hotplug_msg {
 };
 
 struct hotplug_msg {
@@ -47,6 +47,6 @@ struct hotplug_msg {
        char *devpath;
        char *subsystem;
        unsigned long long seqnum;
        char *devpath;
        char *subsystem;
        unsigned long long seqnum;
-       char *envp[HOTPLUG_NUM_ENVP];
+       char *envp[HOTPLUG_NUM_ENVP+1];
        char envbuf[];
 };
        char envbuf[];
 };
index 9f324077b3b92ee6d3e67f53363ff28566193099..7d865573c27b62f95073cca655df969cb1058941 100644 (file)
@@ -132,6 +132,12 @@ int main(int argc, char *argv[], char *envp[])
                goto exit;
        }
 
                goto exit;
        }
 
+       /* prevent loops in the scripts we execute */
+       if (getenv("MANAGED_EVENT") != NULL) {
+               dbg("seems that the event source is not the kernel, just exit");
+               goto exit;
+       }
+
        sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
        if (sock == -1) {
                dbg("error getting socket");
        sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
        if (sock == -1) {
                dbg("error getting socket");