From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Fri, 23 Jan 2004 03:58:32 +0000 Subject: Re: about split the udev Message-Id: <20040123035832.GA2780@vrfy.org> MIME-Version: 1 Content-Type: multipart/mixed; boundary="gKMricLos+KVdGMg" List-Id: References: <3ACA40606221794F80A5670F0AF15F8402D4EE96@PDSMSX403.ccr.corp.intel.com> In-Reply-To: <3ACA40606221794F80A5670F0AF15F8402D4EE96@PDSMSX403.ccr.corp.intel.com> To: linux-hotplug@vger.kernel.org --gKMricLos+KVdGMg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, Jan 22, 2004 at 07:46:47PM -0800, Greg KH wrote: > On Fri, Jan 23, 2004 at 04:37:22AM +0100, Kay Sievers wrote: > > On Fri, Jan 23, 2004 at 02:00:29AM +0100, Kay Sievers wrote: > > > On Thu, Jan 22, 2004 at 04:34:08PM -0800, Greg KH wrote: > > > > On Fri, Jan 23, 2004 at 12:01:29AM +0100, Kay Sievers wrote: > > > > > > > > > > Here is the next updated updated version to apply to the lastet udev. > > > > > I've added infrastructure for getting the state of the IPC queue in the > > > > > sender and set the program to exec by the daemon. Also the magic key id > > > > > is replaced by the usual key generation by path/nr. > > > > > > > > Very nice, I applied this. > > > > > > > > > It looks promising, I use it on my machine and my 4in1 USB-flash-reader > > > > > connect/disconnect emits the events "randomly" but udevd is able to > > > > > reorder it and calls our normal udev in the right order. > > > > > > > > Hm, how are you supposed to start up udevd? like: > > > > ./udevd ./udev > > > > > > This should work, I've only tried './udevd /sbin/udev' and './udevd /bin/true' :) > > > And '/sbin/udev' is the default. > > > > > > > > > > > > Should we start the daemon if noone listens, when the sender is called? > > > > > > > > Yes. > > > > > > I will try it during the weekend. > > > > > > > > > > > Should we convert our udev to a daemon, or stay with the exec? > > > > > > > > I don't know. I was thinking of turning our udev into the daemon, but > > > > with this structure we might not need to. Let's play around with this > > > > current structure for a bit now and see how it works out. > > > > > > Fine, I like it and we can use it for anything that expects a hotplug > > > event and if someone don't like the reorder daemon he may use udev > > > directly. > > > > Sorry, some code is missing. > > Here is a fix to make the exec functional. > > Could you please change 'test/udevd_test.sh' to executable and add > > udevd und udevsender to the ignore file. > > I already made udevd_test.sh executable, and made some whitespace > changes to udevd.c which cause this patch to not apply. Care to pull > again and send the resulting diff? Here we go... thanks, Kay --gKMricLos+KVdGMg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="01-exec-fix.patch" diff -Nru a/udevd.c b/udevd.c --- a/udevd.c Fri Jan 23 04:55:52 2004 +++ b/udevd.c Fri Jan 23 04:55:52 2004 @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -49,6 +50,7 @@ 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 @@ 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) diff -Nru a/udevsend.c b/udevsend.c --- a/udevsend.c Fri Jan 23 04:55:52 2004 +++ b/udevsend.c Fri Jan 23 04:55:52 2004 @@ -117,15 +117,16 @@ } 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 @@ 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; --gKMricLos+KVdGMg-- ------------------------------------------------------- The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. http://www.eclipsecon.org/osdn _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel