linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: Re: about split the udev
Date: Fri, 23 Jan 2004 03:37:22 +0000	[thread overview]
Message-ID: <20040123033722.GA2696@vrfy.org> (raw)
In-Reply-To: <3ACA40606221794F80A5670F0AF15F8402D4EE96@PDSMSX403.ccr.corp.intel.com>

[-- Attachment #1: Type: text/plain, Size: 1721 bytes --]

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.

thanks,
Kay

[-- Attachment #2: 01-exec-fix.patch --]
[-- Type: text/plain, Size: 2330 bytes --]

diff -Nru a/udevd.c b/udevd.c
--- a/udevd.c	Fri Jan 23 04:30:51 2004
+++ b/udevd.c	Fri Jan 23 04:30:51 2004
@@ -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 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:30:51 2004
+++ b/udevsend.c	Fri Jan 23 04:30:51 2004
@@ -116,17 +116,18 @@
 		goto exit;
 	}
 
+	/* create ipc message queue or get id of our existing one */
 	seq = atoi(seqnum);
 	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 the ipc queue */
 	retval = msgctl(msgid, IPC_STAT, &msg_queue);
 	if (retval == -1) {
 		dbg("error getting info on ipc queue");
@@ -135,11 +136,12 @@
 	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;

  parent reply	other threads:[~2004-01-23  3:37 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-12  7:53 about split the udev Ling, Xiaofeng
2004-01-12  9:36 ` Martin Waitz
2004-01-12 13:54 ` Kay Sievers
2004-01-12 16:23 ` Martin Waitz
2004-01-12 16:28 ` Robert Love
2004-01-12 17:51 ` David Zeuthen
2004-01-13  1:12 ` Greg KH
2004-01-13  1:29 ` Greg KH
2004-01-13 19:05 ` Tristan Wibberley
2004-01-13 20:36 ` Greg KH
2004-01-15 14:36 ` Ling, Xiaofeng
2004-01-15 21:45 ` Greg KH
2004-01-21 13:38 ` Kay Sievers
2004-01-22  0:27 ` Kay Sievers
2004-01-22  1:08 ` Kay Sievers
2004-01-22 23:01 ` Kay Sievers
2004-01-23  0:34 ` Greg KH
2004-01-23  1:00 ` Kay Sievers
2004-01-23  3:37 ` Kay Sievers [this message]
2004-01-23  3:46 ` Greg KH
2004-01-23  3:58 ` Kay Sievers
2004-01-23  4:04 ` Greg KH
2004-01-24 16:06 ` Ling, Xiaofeng
2004-01-24 16:57 ` Kay Sievers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040123033722.GA2696@vrfy.org \
    --to=kay.sievers@vrfy.org \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).