chiark / gitweb /
[PATCH] fix udevd exec
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>
Fri, 23 Jan 2004 12:01:09 +0000 (04:01 -0800)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 04:13:18 +0000 (21:13 -0700)
Sorry, some code is missing.
Here is a fix to make the exec functional.

udevd.c
udevsend.c

diff --git a/udevd.c b/udevd.c
index 08dede36ee335c597c2616709c24643195b9ec1a..6af265a3898b811a07a8d08a915698beda679902 100644 (file)
--- a/udevd.c
+++ b/udevd.c
@@ -24,6 +24,7 @@
 
 #include <sys/types.h>
 #include <sys/ipc.h>
+#include <sys/wait.h>
 #include <sys/msg.h>
 #include <signal.h>
 #include <unistd.h>
@@ -49,6 +50,7 @@ static int timeout = 0;
 static struct hotplug_msg *head = NULL;
 static char exec_program[100];
 
+
 static void sig_handler(int signum)
 {
        dbg("caught signal %d", signum);
@@ -104,13 +106,40 @@ static void dump_msg(struct hotplug_msg *pmsg)
            pmsg->seqnum, pmsg->action, pmsg->devpath, pmsg->subsystem);
 }
 
-static void dispatch_msg(struct hotplug_msg *pmsg)
+static int dispatch_msg(struct hotplug_msg *pmsg)
 {
+       pid_t pid;
+       char *argv[3];
+       int retval;
+       extern char **environ;
+
        dump_msg(pmsg);
        dbg("exec '%s'", exec_program);
+
        setenv("ACTION", pmsg->action, 1);
        setenv("DEVPATH", pmsg->devpath, 1);
-       execl(exec_program, pmsg->subsystem);
+
+       argv[0] = exec_program;
+       argv[1] = pmsg->subsystem;
+       argv[2] = NULL;
+
+       pid = fork();
+       switch (pid) {
+       case 0:
+               retval = execve(argv[0], argv, environ);
+               if (retval != 0) {
+                       dbg("child execve failed");
+                       exit(1);
+               }
+               break;
+       case -1:
+               dbg("fork failed");
+               return -1;
+       default:
+               wait(0);
+               break;
+       }
+       return 0;
 }
 
 static void reset_timer(void)
index 1a897451c0beda11cbb1c8bf20d7047d3f295317..748c8f22173e8d17a621bc4aa605f158f43f5bc9 100644 (file)
@@ -117,15 +117,16 @@ int main(int argc, char* argv[])
        }
        seq = atoi(seqnum);
 
+       /* create ipc message queue or get id of our existing one */
        key = ftok(DEFAULT_EXEC_PROGRAM, IPC_KEY_ID);
        size =  build_hotplugmsg( (struct hotplug_msg**) &pmsg, action, devpath, subsystem, seq);
        msgid = msgget(key, IPC_CREAT);
        if (msgid == -1) {
-               dbg("open ipc queue error");
+               dbg("error open ipc queue");
                goto exit;
        }
 
-       /* get state of queue */
+       /* get state of ipc queue */
        retval = msgctl(msgid, IPC_STAT, &msg_queue);
        if (retval == -1) {
                dbg("error getting info on ipc queue");
@@ -134,10 +135,11 @@ int main(int argc, char* argv[])
        if (msg_queue.msg_qnum > 0)
                dbg("%li messages already in the ipc queue", msg_queue.msg_qnum);
 
+       /* send ipc message to the daemon */
        retval = msgsnd(msgid, pmsg, size, 0);
        free_hotplugmsg( (struct hotplug_msg*) pmsg);
        if (retval == -1) {
-               dbg("send ipc message error");
+               dbg("error sending ipc message");
                goto exit;
        }
        return 0;