* Re: about split the udev
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
` (21 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: Martin Waitz @ 2004-01-12 9:36 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 817 bytes --]
hi :)
On Mon, Jan 12, 2004 at 03:53:01PM +0800, Ling, Xiaofeng wrote:
> In the TODO, there is an item "split program into two pieces",
> If no one is working on it, I'd like to try for it.
> What do you think is better to communicate between the two pieces?
> Unix socket, named pipe or share memory?
HAL already has a small program that sends a d-bus message for
every hotplug event.
perhaps that could be reused so that udev would simply become
a daemon listening for events...
--
CU, / Friedrich-Alexander University Erlangen, Germany
Martin Waitz // Department of Computer Science 3 _________
______________/// - - - - - - - - - - - - - - - - - - - - ///
dies ist eine manuell generierte mail, sie beinhaltet //
tippfehler und ist auch ohne grossbuchstaben gueltig. /
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
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
` (20 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: Kay Sievers @ 2004-01-12 13:54 UTC (permalink / raw)
To: linux-hotplug
On Mon, Jan 12, 2004 at 10:36:06AM +0100, Martin Waitz wrote:
> hi :)
>
> On Mon, Jan 12, 2004 at 03:53:01PM +0800, Ling, Xiaofeng wrote:
> > In the TODO, there is an item "split program into two pieces",
> > If no one is working on it, I'd like to try for it.
> > What do you think is better to communicate between the two pieces?
> > Unix socket, named pipe or share memory?
>
> HAL already has a small program that sends a d-bus message for
> every hotplug event.
>
> perhaps that could be reused so that udev would simply become
> a daemon listening for events...
Huhh, what a magic :)
udev is a part of hotplug.
udev _sends_ DBUS-messages.
HAL receives these messages with the node name _from_ udev.
Kay
-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
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
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
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
` (19 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: Martin Waitz @ 2004-01-12 16:23 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 1175 bytes --]
hi :)
On Mon, Jan 12, 2004 at 02:54:14PM +0100, Kay Sievers wrote:
> udev is a part of hotplug.
> udev _sends_ DBUS-messages.
> HAL receives these messages with the node name _from_ udev.
if one wants to convert udev to become a daemon, that could
be changed to:
* hotplug sends a d-bus message, possibly by using the
little program which exists in HAL today
* udev daemon receives the message, reacts and sends a new
message containing its reactions
* HAL receives both messages and updates its device database
on the other hand, the current systems works quite fine, too.
so perhaps we could simply remove that item from TODO.
i just wanted to point out that we don't need multiple methods to
send hotplug events to a running daemon.
we already have one method that gets used in HAL and we should
try to reuse things...
--
CU, / Friedrich-Alexander University Erlangen, Germany
Martin Waitz // Department of Computer Science 3 _________
______________/// - - - - - - - - - - - - - - - - - - - - ///
dies ist eine manuell generierte mail, sie beinhaltet //
tippfehler und ist auch ohne grossbuchstaben gueltig. /
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (2 preceding siblings ...)
2004-01-12 16:23 ` Martin Waitz
@ 2004-01-12 16:28 ` Robert Love
2004-01-12 17:51 ` David Zeuthen
` (18 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: Robert Love @ 2004-01-12 16:28 UTC (permalink / raw)
To: linux-hotplug
On Mon, 2004-01-12 at 08:54, Kay Sievers wrote:
> Huhh, what a magic :)
>
> udev is a part of hotplug.
> udev _sends_ DBUS-messages.
> HAL receives these messages with the node name _from_ udev.
HAL _also_ installs a hotplug script to listen for events and emit a
D-BUS signal, because HAL wants to know about all hotplug events, not
just ones that udev handles. So I think Martin's idea is actually
pretty good.
It would mean we end up with a really clean progression for hardware
integration:
kernel -> hotplug (via /sbin/hotplug) -> hal.hotplug ->
udev daemon (via D-BUS) -> HAL daemon (via D-BUS) ->
upper levels of the desktop (via D-BUS)
Which I like.
Robert Love
-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
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
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (3 preceding siblings ...)
2004-01-12 16:28 ` Robert Love
@ 2004-01-12 17:51 ` David Zeuthen
2004-01-13 1:12 ` Greg KH
` (17 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: David Zeuthen @ 2004-01-12 17:51 UTC (permalink / raw)
To: linux-hotplug
On Mon, 2004-01-12 at 17:28, Robert Love wrote:
> On Mon, 2004-01-12 at 08:54, Kay Sievers wrote:
>
> > Huhh, what a magic :)
> >
> > udev is a part of hotplug.
> > udev _sends_ DBUS-messages.
> > HAL receives these messages with the node name _from_ udev.
>
> HAL _also_ installs a hotplug script to listen for events and emit a
> D-BUS signal, because HAL wants to know about all hotplug events, not
> just ones that udev handles. So I think Martin's idea is actually
> pretty good.
>
> It would mean we end up with a really clean progression for hardware
> integration:
>
> kernel -> hotplug (via /sbin/hotplug) -> hal.hotplug ->
> udev daemon (via D-BUS) -> HAL daemon (via D-BUS) ->
> upper levels of the desktop (via D-BUS)
>
> Which I like.
Yeah, but udev and hal.hotplug works in different ways with respect to
d-bus integration.
hal.hotplug explicitly sends the hotplug events as d-bus messages
addressed to the org.freedesktop.Hal service - no one can piggy back on
these.
In contrast udev, when invoked, claims the org.kernel.udev service and
emits a signal on the org.kernel.udev.NodeMonitor interface - any
application can pick up this signal if they subscribe to it on the
system messagebus.
Due to the nice security infrastructure of D-BUS one can actually trust
that the event originated from udev.
(BUT... note that we do in udev today is fundamentally racey as multiple
copies of udev run at the same time. So in reality a copy of udev
doesn't always claim the org.kernel.udev service; it becomes a
"secondary owner" of the service instead.
This means that signals stemming from such a copy doesn't seem to
originate from the org.kernel.udev service. This is an issue I think
need to be solved in d-bus; I've already raised it on message-bus-list
but I haven't got a reply yet.)
What we want to do with hotplug is probably similar to what we do with
udev rather than how hal.hotplug works. If people are interested, I'll
be happy to submit code for this. Of course we'll run into the same
issues as we have with udev d-bus integration today.
Cheers,
David
-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
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
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (4 preceding siblings ...)
2004-01-12 17:51 ` David Zeuthen
@ 2004-01-13 1:12 ` Greg KH
2004-01-13 1:29 ` Greg KH
` (16 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: Greg KH @ 2004-01-13 1:12 UTC (permalink / raw)
To: linux-hotplug
On Mon, Jan 12, 2004 at 03:53:01PM +0800, Ling, Xiaofeng wrote:
> Hi, greg
> In the TODO, there is an item "split program into two pieces",
> If no one is working on it, I'd like to try for it.
> What do you think is better to communicate between the two pieces?
> Unix socket, named pipe or share memory?
I was thinking that a simple message queue would suffice. But if you
have a better suggestion, I would love to hear it.
And no, I do not think anyone is currently working on this, it would be
very helpful if you could.
thanks,
greg k-h
-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
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
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (5 preceding siblings ...)
2004-01-13 1:12 ` Greg KH
@ 2004-01-13 1:29 ` Greg KH
2004-01-13 19:05 ` Tristan Wibberley
` (15 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: Greg KH @ 2004-01-13 1:29 UTC (permalink / raw)
To: linux-hotplug
On Mon, Jan 12, 2004 at 10:36:06AM +0100, Martin Waitz wrote:
> hi :)
>
> On Mon, Jan 12, 2004 at 03:53:01PM +0800, Ling, Xiaofeng wrote:
> > In the TODO, there is an item "split program into two pieces",
> > If no one is working on it, I'd like to try for it.
> > What do you think is better to communicate between the two pieces?
> > Unix socket, named pipe or share memory?
>
> HAL already has a small program that sends a d-bus message for
> every hotplug event.
No, DBUS is too heavy for what udev needs to do, sorry.
I am talking about udev splitting into 2 pieces:
udev - called the same way udev is called today.
creates a tiny message queue message based on the hotplug
event and then exits. This can probably be done in under
6Kb of binary code.
udevd - receives the udev message queue messages. Orders them
in the proper order (based on the SEQ_NUM from the
hotplug event), and then acts on them. Size should be
about what we have today for the udev binary 50Kb or so.
We need to do this in order to properly handle out of order hotplug
events. It will also help out your DBUS issue with udev messages :)
Hope this helps,
greg k-h
-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
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
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (6 preceding siblings ...)
2004-01-13 1:29 ` Greg KH
@ 2004-01-13 19:05 ` Tristan Wibberley
2004-01-13 20:36 ` Greg KH
` (14 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: Tristan Wibberley @ 2004-01-13 19:05 UTC (permalink / raw)
To: linux-hotplug
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Greg KH wrote:
| I am talking about udev splitting into 2 pieces:
| udev - called the same way udev is called today.
| creates a tiny message queue message based on the hotplug
| event and then exits. This can probably be done in under
| 6Kb of binary code.
| udevd - receives the udev message queue messages. Orders them
| in the proper order (based on the SEQ_NUM from the
| hotplug event), and then acts on them. Size should be
| about what we have today for the udev binary 50Kb or so.
|
| We need to do this in order to properly handle out of order hotplug
| events.
Will that solve the problem? If udevd keeps up with the messages, and
the udev that supplies the second message pre-empts the one that
provides the first, will udevd process the second message because it
doesn't know that there is an earlier one about to come in?
If udevd waits for contiguous SEQ_NUMs to ensure this doesn't happen,
then a dead/locked-up udev will freeze everything (udevd won't know
which of the events it has should wait until after the unknown one). I
think a different solution is required.
Just what, I don't know - I'm quite new here :) I'm probably way off anyway.
- --
Tristan Wibberley
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD4DBQFABEF18z3lIaW+LfIRAgKdAKDOg2XGNq7SeAEO9nc0IZednOXXjACVGMsb
4DdwePXa6NP9AvgQ3OadmA=
=u3ca
-----END PGP SIGNATURE-----
-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
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
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (7 preceding siblings ...)
2004-01-13 19:05 ` Tristan Wibberley
@ 2004-01-13 20:36 ` Greg KH
2004-01-15 14:36 ` Ling, Xiaofeng
` (13 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: Greg KH @ 2004-01-13 20:36 UTC (permalink / raw)
To: linux-hotplug
On Tue, Jan 13, 2004 at 07:05:26PM +0000, Tristan Wibberley wrote:
> Greg KH wrote:
>
> | I am talking about udev splitting into 2 pieces:
> | udev - called the same way udev is called today.
> | creates a tiny message queue message based on the hotplug
> | event and then exits. This can probably be done in under
> | 6Kb of binary code.
> | udevd - receives the udev message queue messages. Orders them
> | in the proper order (based on the SEQ_NUM from the
> | hotplug event), and then acts on them. Size should be
> | about what we have today for the udev binary 50Kb or so.
> |
> | We need to do this in order to properly handle out of order hotplug
> | events.
>
> Will that solve the problem? If udevd keeps up with the messages, and
> the udev that supplies the second message pre-empts the one that
> provides the first, will udevd process the second message because it
> doesn't know that there is an earlier one about to come in?
>
> If udevd waits for contiguous SEQ_NUMs to ensure this doesn't happen,
> then a dead/locked-up udev will freeze everything (udevd won't know
> which of the events it has should wait until after the unknown one). I
> think a different solution is required.
No, udev will have to peek at future messages to see if we got them out
of order, and re-order them. And a time-out will have to be in place in
case we somehow lose one entirely.
thanks,
greg k-h
-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
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
^ permalink raw reply [flat|nested] 24+ messages in thread* RE: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (8 preceding siblings ...)
2004-01-13 20:36 ` Greg KH
@ 2004-01-15 14:36 ` Ling, Xiaofeng
2004-01-15 21:45 ` Greg KH
` (12 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: Ling, Xiaofeng @ 2004-01-15 14:36 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 1201 bytes --]
Hi, Greg
I wrote a simple implementation for the two pieces
of send and receive hotplug event,
use a message queue and a list for the out of order
hotplug event. It also has a timeout timer of 3 seconds.
They are now separate program. the file nseq is the test script.
Could you have a look to see wether it is feasible?
If so, I'll continue to merge with udev.
> -----Original Message-----
> From: Greg KH [mailto:greg@kroah.com]
> Sent: 2004年1月13日 9:13
> To: Ling, Xiaofeng
> Cc: linux-hotplug-devel@lists.sourceforge.net
> Subject: Re: about split the udev
>
>
> On Mon, Jan 12, 2004 at 03:53:01PM +0800, Ling, Xiaofeng wrote:
> > Hi, greg
> > In the TODO, there is an item "split program into two pieces",
> > If no one is working on it, I'd like to try for it. What do you
> > think is better to communicate between the two pieces? Unix socket,
> > named pipe or share memory?
>
> I was thinking that a simple message queue would suffice.
> But if you have a better suggestion, I would love to hear it.
>
> And no, I do not think anyone is currently working on this, it would
> be very helpful if you could.
>
> thanks,
>
> greg k-h
>
[-- Attachment #2: nseq --]
[-- Type: application/octet-stream, Size: 451 bytes --]
#!/bin/bash
export ACTION=add
export DEVPATH=block/sda
export SEQNUM=1
./udevs block
export SEQNUM=2
./udevs block
export SEQNUM=5
./udevs block
export SEQNUM=4
./udevs block
export SEQNUM=3
./udevs block
export SEQNUM=6
./udevs block
export SEQNUM=8
./udevs block
export SEQNUM=9
./udevs block
export SEQNUM=7
./udevs block
export SEQNUM=10
./udevs block
export SEQNUM=12
./udevs block
export SEQNUM=13
./udevs block
export SEQNUM=14
./udevs block
[-- Attachment #3: udevd.c --]
[-- Type: application/octet-stream, Size: 3353 bytes --]
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <signal.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "udev.h"
#include "udevd.h"
void add_queue(struct hotplug_msg *pmsg);
void check_queue(void);
void dispatch_msg(struct hotplug_msg *pmsg);
void reset_timer(void);
void set_timer(void);
int process_queue(void);
void dump_queue(void);
void dump_msg(struct hotplug_msg *pmsg);
static int expect_seqnum = 1;
static int timeout_value = 3;
static int timeout=0;
static struct hotplug_msg *head=NULL;
static void sig_alarmhandler(int signum)
{
dbg("caught signal %d", signum);
switch (signum) {
case SIGALRM:
timeout = 1;
dbg("timeout,lose one event\n");
default:
dbg("unhandled signal");
}
}
void dump_queue(void)
{
struct hotplug_msg *p;
p = head;
printf("checking...(%d)", expect_seqnum);
while(p)
{
printf("%d->", p->seqnum);
p=p->next;
}
printf("\n");
}
void dump_msg(struct hotplug_msg *pmsg)
{
printf("<<%d,", pmsg->seqnum);
printf("%s,", pmsg->action);
printf("%s,", pmsg->devpath);
printf("%s>>\n", pmsg->subsystem);
}
void check_queue(void)
{
struct hotplug_msg *p;
p = head;
dump_queue();
while(head && head->seqnum == expect_seqnum) {
dispatch_msg(head);
expect_seqnum++;
p = head;
head=head->next;
free(p);
}
if(head)
set_timer();
else
reset_timer();
}
void add_queue(struct hotplug_msg *pmsg)
{
struct hotplug_msg *pnewmsg, *p, *p1;
p=head;
p1=NULL;
pnewmsg = malloc(sizeof(struct hotplug_msg));
*pnewmsg = *pmsg;
pnewmsg->next = NULL;
while(p && pmsg->seqnum > p->seqnum){
p1=p;
p=p->next;
}
pnewmsg->next = p;
if(!p1){
head = pnewmsg;
}else
p1->next = pnewmsg;
dump_queue();
}
void dispatch_msg(struct hotplug_msg *pmsg)
{
dump_msg(pmsg);
}
void reset_timer(void)
{
alarm(0);
}
void set_timer(void)
{
signal(SIGALRM, sig_alarmhandler);
alarm(timeout_value);
}
int process_queue()
{
int msgid;
key_t key;
struct hotplug_msg *pmsg;
char buf[1024];
int ret;
key = 12345; /*may use inode number of /etc/udev? */
pmsg = (struct hotplug_msg *) buf;
msgid = msgget(key, IPC_CREAT);
if (msgid == -1) {
dbg("open message queue error");
goto exit;
}
while (1) {
ret =
msgrcv(msgid, (struct msgbuf *) buf, 1020, HOTPLUGMSGTYPE,
0);
if (ret != -1) {
dbg("<<%d:%d>>\n", pmsg->seqnum, expect_seqnum);
if (pmsg->seqnum > expect_seqnum) {
add_queue(pmsg);
set_timer();
} else if (pmsg->seqnum == expect_seqnum) {
dispatch_msg(pmsg);
expect_seqnum++;
check_queue();
} else {
dbg("timeout event come again?");
}
} else if (errno == EINTR) {
dbg("recv signal : %s\n", strerror(errno));
{
expect_seqnum++;
check_queue();
timeout=0;
}
} else {
dbg("recv error: %s", strerror(errno));
}
}
return 0;
exit:
return -1;
}
int main(int argc, char *argv[])
{
process_queue();
return 0;
}
[-- Attachment #4: udevd.h --]
[-- Type: application/octet-stream, Size: 164 bytes --]
#define HOTPLUGMSGTYPE 44
struct hotplug_msg {
long mtype;
struct hotplug_msg *next;
int seqnum;
char action[8];
char devpath[128];
char subsystem[16];
};
[-- Attachment #5: udevs.c --]
[-- Type: application/octet-stream, Size: 2073 bytes --]
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "udev.h"
#include "udevd.h"
static inline char *get_action(void)
{
char *action;
action = getenv("ACTION");
return action;
}
static inline char *get_devpath(void)
{
char *devpath;
devpath = getenv("DEVPATH");
return devpath;
}
static inline char *get_seqnum(void)
{
char *seqnum;
seqnum = getenv("SEQNUM");
return seqnum;
}
int
build_hotplugmsg(struct hotplug_msg **ppmsg, char *action,
char *devpath, char *subsystem, int seqnum)
{
struct hotplug_msg *pmsg;
pmsg = malloc(sizeof(struct hotplug_msg));
pmsg->mtype = HOTPLUGMSGTYPE;
pmsg->seqnum = seqnum;
strncpy(pmsg->action, action, 8);
strncpy(pmsg->devpath, devpath, 128);
strncpy(pmsg->subsystem, subsystem, 16);
*ppmsg = pmsg;
return sizeof(struct hotplug_msg);
}
void
free_hotplugmsg(struct hotplug_msg *pmsg)
{
free(pmsg);
}
int
main(int argc, char* argv[])
{
int msgid;
struct msgbuf *pmsg;
key_t key;
char *action;
char *devpath;
char *subsystem;
char *seqnum;
int seq;
int retval = -EINVAL;
int size;
subsystem = argv[1];
key = 12345; /*may use inode number of /etc/udev?*/
devpath = get_devpath();
if (!devpath) {
dbg ("no devpath?");
goto exit;
}
dbg("looking at '%s'", devpath);
action = get_action();
if (!action) {
dbg ("no action?");
goto exit;
}
seqnum = get_seqnum();
if (!seqnum) {
dbg ("no seqnum?");
goto exit;
}
seq = atoi(seqnum);
size = build_hotplugmsg((struct hotplug_msg**)&pmsg, action, devpath, subsystem, seq);
msgid = msgget(key, IPC_CREAT);
if(msgid == -1)
{
dbg("open message queue error");
goto exit;
}
retval = msgsnd(msgid, pmsg, size, 0);
free_hotplugmsg((struct hotplug_msg*)pmsg);
if(retval == -1)
{
dbg("send message error");
goto exit;
}
return 0;
exit:
if (retval > 0)
retval = 0;
return -retval;
}
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (9 preceding siblings ...)
2004-01-15 14:36 ` Ling, Xiaofeng
@ 2004-01-15 21:45 ` Greg KH
2004-01-21 13:38 ` Kay Sievers
` (11 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: Greg KH @ 2004-01-15 21:45 UTC (permalink / raw)
To: linux-hotplug
On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> Hi, Greg
> I wrote a simple implementation for the two pieces
> of send and receive hotplug event,
> use a message queue and a list for the out of order
> hotplug event. It also has a timeout timer of 3 seconds.
> They are now separate program. the file nseq is the test script.
> Could you have a look to see wether it is feasible?
> If so, I'll continue to merge with udev.
Yes, very nice start. Please continue on.
One minor comment, please stick with the kernel coding style when you
are writing new code for udev.
thanks,
greg k-h
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (10 preceding siblings ...)
2004-01-15 21:45 ` Greg KH
@ 2004-01-21 13:38 ` Kay Sievers
2004-01-22 0:27 ` Kay Sievers
` (10 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: Kay Sievers @ 2004-01-21 13:38 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 1239 bytes --]
On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > Hi, Greg
> > I wrote a simple implementation for the two pieces
> > of send and receive hotplug event,
> > use a message queue and a list for the out of order
> > hotplug event. It also has a timeout timer of 3 seconds.
> > They are now separate program. the file nseq is the test script.
> > Could you have a look to see wether it is feasible?
> > If so, I'll continue to merge with udev.
>
> Yes, very nice start. Please continue on.
>
> One minor comment, please stick with the kernel coding style when you
> are writing new code for udev.
I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
tweaked the debugging, added the udev exec and created a patch for the current tree.
It seems functional now, by simply executing our current udev (dirty hack).
It reorders the incoming events and if one is missing it delays the
execution of the following ones up to a maximum of 10 seconds.
Test script is included, but you can't mix hotplug sequence numbers and
test script numbers, it will result in waiting for the missing numbers :)
please have a look at it...
thanks,
Kay
[-- Attachment #2: 01-udevd2.patch --]
[-- Type: text/plain, Size: 10544 bytes --]
diff -Nru a/Makefile b/Makefile
--- a/Makefile Wed Jan 21 14:12:22 2004
+++ b/Makefile Wed Jan 21 14:12:22 2004
@@ -31,6 +31,8 @@
ROOT = udev
+DAEMON = udevd
+SENDER = udevsend
VERSION = 013_bk
INSTALL_DIR = /usr/local/bin
RELEASE_NAME = $(ROOT)-$(VERSION)
@@ -155,7 +157,7 @@
CFLAGS += -I$(PWD)/libsysfs
-all: $(ROOT)
+all: $(ROOT) $(DAEMON) $(SENDER)
@extras="$(EXTRAS)" ; for target in $$extras ; do \
echo $$target ; \
$(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
@@ -229,10 +231,18 @@
$(LD) $(LDFLAGS) -o $(ROOT) $(CRT0) $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
$(STRIPCMD) $(ROOT)
+$(DAEMON): $(ROOT) udevd.h udevd.o
+ $(LD) $(LDFLAGS) -o $(DAEMON) $(CRT0) udevd.o logging.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
+ $(STRIPCMD) $(ROOT)
+
+$(SENDER): $(ROOT) udevd.h udevsend.o
+ $(LD) $(LDFLAGS) -o $(SENDER) $(CRT0) udevsend.o logging.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
+ $(STRIPCMD) $(ROOT)
+
clean:
-find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
| xargs rm -f
- -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS)
+ -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(DAEMON) $(SENDER)
$(MAKE) -C klibc clean
@extras="$(EXTRAS)" ; for target in $$extras ; do \
echo $$target ; \
diff -Nru a/test/udevd_test.sh b/test/udevd_test.sh
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/test/udevd_test.sh Wed Jan 21 14:12:22 2004
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+
+export ACTION=add
+export DEVPATH=/block/sda
+export SEQNUM=1
+./udevsend block
+export SEQNUM=2
+./udevsend block
+export SEQNUM=3
+./udevsend block
+export SEQNUM=5
+./udevsend block
+export SEQNUM=4
+./udevsend block
+export SEQNUM=6
+./udevsend block
+export SEQNUM=7
+./udevsend block
+export SEQNUM=10
+./udevsend block
+export SEQNUM=9
+./udevsend block
+export SEQNUM=8
+./udevsend block
+export SEQNUM=11
+./udevsend block
+export SEQNUM=12
+./udevsend block
+export SEQNUM=13
+./udevsend block
diff -Nru a/udevd.c b/udevd.c
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/udevd.c Wed Jan 21 14:12:22 2004
@@ -0,0 +1,198 @@
+/*
+ * udevd.c
+ *
+ * Userspace devfs
+ *
+ * Copyright (C) 2004 Ling, Xiaofeng <xiaofeng.ling@intel.com>
+ * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <signal.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "udev.h"
+#include "udevd.h"
+#include "logging.h"
+
+#define BUFFER_SIZE 1024
+#define TIMEOUT_SECONDS 10
+
+static int expect_seqnum = 0;
+static int timeout_value = TIMEOUT_SECONDS;
+static int timeout = 0;
+static struct hotplug_msg *head = NULL;
+
+
+static void sig_alarmhandler(int signum)
+{
+ dbg("caught signal %d", signum);
+ switch (signum) {
+ case SIGALRM:
+ timeout = 1;
+ dbg("timeout, event lost");
+ default:
+ dbg("unhandled signal");
+ }
+}
+
+static void dump_queue(void)
+{
+ struct hotplug_msg *p;
+ p = head;
+ dbg("next expected sequence %d", expect_seqnum);
+ while(p) {
+ dbg("waiting for sequence %d", p->seqnum);
+ p=p->next;
+ }
+}
+
+static void dump_msg(struct hotplug_msg *pmsg)
+{
+ dbg("sequence %d, '%s', '%s', '%s'",
+ pmsg->seqnum, pmsg->action, pmsg->devpath, pmsg->subsystem);
+}
+
+static void dispatch_msg(struct hotplug_msg *pmsg)
+{
+ char name[100];
+
+ dump_msg(pmsg);
+
+ /* FIXME: this is proof of concept only :) */
+ setenv("ACTION", pmsg->action, 1);
+ setenv("DEVPATH", pmsg->devpath, 1);
+
+ strcpy(name, "/sbin/udev ");
+ strncat(name, pmsg->subsystem, sizeof(name));
+ system(name);
+}
+
+static void reset_timer(void)
+{
+ alarm(0);
+}
+
+static void set_timer(void)
+{
+ signal(SIGALRM, sig_alarmhandler);
+ alarm(timeout_value);
+}
+
+static void check_queue(void)
+{
+ struct hotplug_msg *p;
+ p = head;
+
+ dump_queue();
+ while(head && head->seqnum == expect_seqnum) {
+ dispatch_msg(head);
+ expect_seqnum++;
+ p = head;
+ head=head->next;
+ free(p);
+ }
+ if (head != NULL)
+ set_timer();
+ else
+ reset_timer();
+}
+
+static void add_queue(struct hotplug_msg *pmsg)
+{
+ struct hotplug_msg *pnewmsg;
+ struct hotplug_msg *p;
+ struct hotplug_msg *p1;
+
+ p = head;
+ p1 = NULL;
+ pnewmsg = malloc(sizeof(struct hotplug_msg));
+ *pnewmsg = *pmsg;
+ pnewmsg->next = NULL;
+ while(p && pmsg->seqnum > p->seqnum) {
+ p1 = p;
+ p = p->next;
+ }
+ pnewmsg->next = p;
+ if (p1 == NULL) {
+ head = pnewmsg;
+ } else {
+ p1->next = pnewmsg;
+ }
+ dump_queue();
+}
+
+static int process_queue(void)
+{
+ int msgid;
+ key_t key;
+ struct hotplug_msg *pmsg;
+ char buf[BUFFER_SIZE];
+ int ret;
+
+ key = 12345; /*may use inode number of /etc/udev? */
+ pmsg = (struct hotplug_msg *) buf;
+ msgid = msgget(key, IPC_CREAT);
+ if (msgid == -1) {
+ dbg("open message queue error");
+ goto exit;
+ }
+ while (1) {
+ ret = msgrcv(msgid, (struct msgbuf *) buf, BUFFER_SIZE-4, HOTPLUGMSGTYPE, 0);
+ if (ret != -1) {
+ dbg("current sequence %d, expected sequence %d", pmsg->seqnum, expect_seqnum);
+ if (expect_seqnum == 0) /* init sequence with very first call */
+ expect_seqnum = pmsg->seqnum;
+ if (pmsg->seqnum > expect_seqnum) {
+ add_queue(pmsg);
+ set_timer();
+ } else {
+ if (pmsg->seqnum == expect_seqnum) {
+ dispatch_msg(pmsg);
+ expect_seqnum++;
+ check_queue();
+ } else {
+ dbg("timeout event come again");
+ }
+ }
+ } else
+ if (errno == EINTR) {
+ dbg("recv signal '%s'", strerror(errno));
+ expect_seqnum++;
+ check_queue();
+ timeout = 0;
+ } else {
+ dbg("recv error '%s'", strerror(errno));
+ }
+ }
+ return 0;
+exit:
+ return -1;
+}
+
+int main(int argc, char *argv[])
+{
+ process_queue();
+ return 0;
+}
diff -Nru a/udevd.h b/udevd.h
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/udevd.h Wed Jan 21 14:12:22 2004
@@ -0,0 +1,33 @@
+/*
+ * udevd.h
+ *
+ * Userspace devfs
+ *
+ * Copyright (C) 2004 Ling, Xiaofeng <xiaofeng.ling@intel.com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#define HOTPLUGMSGTYPE 44
+
+struct hotplug_msg {
+ long mtype;
+ struct hotplug_msg *next;
+ int seqnum;
+ char action[8];
+ char devpath[128];
+ char subsystem[16];
+};
diff -Nru a/udevsend.c b/udevsend.c
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/udevsend.c Wed Jan 21 14:12:22 2004
@@ -0,0 +1,142 @@
+/*
+ * udevsend.c
+ *
+ * Userspace devfs
+ *
+ * Copyright (C) 2004 Ling, Xiaofeng <xiaofeng.ling@intel.com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "udev.h"
+#include "udevd.h"
+#include "logging.h"
+
+static inline char *get_action(void)
+{
+ char *action;
+
+ action = getenv("ACTION");
+ return action;
+}
+
+static inline char *get_devpath(void)
+{
+ char *devpath;
+
+ devpath = getenv("DEVPATH");
+ return devpath;
+}
+
+static inline char *get_seqnum(void)
+{
+ char *seqnum;
+
+ seqnum = getenv("SEQNUM");
+ return seqnum;
+}
+
+static int build_hotplugmsg(struct hotplug_msg **ppmsg, char *action,
+ char *devpath, char *subsystem, int seqnum)
+{
+ struct hotplug_msg *pmsg;
+ pmsg = malloc(sizeof(struct hotplug_msg));
+ pmsg->mtype = HOTPLUGMSGTYPE;
+ pmsg->seqnum = seqnum;
+ strncpy(pmsg->action, action, 8);
+ strncpy(pmsg->devpath, devpath, 128);
+ strncpy(pmsg->subsystem, subsystem, 16);
+ *ppmsg = pmsg;
+ return sizeof(struct hotplug_msg);
+}
+
+static void free_hotplugmsg(struct hotplug_msg *pmsg)
+{
+ free(pmsg);
+}
+
+int main(int argc, char* argv[])
+{
+ int msgid;
+ struct msgbuf *pmsg;
+ key_t key;
+ char *action;
+ char *devpath;
+ char *subsystem;
+ char *seqnum;
+ int seq;
+ int retval = -EINVAL;
+ int size;
+
+ key = 12345; /*may use inode number of /etc/udev?*/
+
+ subsystem = argv[1];
+ if (subsystem == NULL) {
+ dbg("no subsystem");
+ goto exit;
+ }
+
+ devpath = get_devpath();
+ if (devpath == NULL) {
+ dbg("no devpath");
+ goto exit;
+ }
+
+ action = get_action();
+ if (action == NULL) {
+ dbg("no action");
+ goto exit;
+ }
+
+ seqnum = get_seqnum();
+ if (seqnum == NULL) {
+ dbg("no seqnum");
+ goto exit;
+ }
+
+ seq = atoi(seqnum);
+
+ size = build_hotplugmsg( (struct hotplug_msg**) &pmsg, action, devpath, subsystem, seq);
+ msgid = msgget(key, IPC_CREAT);
+ if (msgid == -1)
+ {
+ dbg("open message queue error");
+ goto exit;
+ }
+
+ retval = msgsnd(msgid, pmsg, size, 0);
+ free_hotplugmsg( (struct hotplug_msg*) pmsg);
+ if (retval == -1)
+ {
+ dbg("send message error");
+ goto exit;
+ }
+ return 0;
+
+exit:
+ if (retval > 0)
+ retval = 0;
+
+ return retval;
+}
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (11 preceding siblings ...)
2004-01-21 13:38 ` Kay Sievers
@ 2004-01-22 0:27 ` Kay Sievers
2004-01-22 1:08 ` Kay Sievers
` (9 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: Kay Sievers @ 2004-01-22 0:27 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 1869 bytes --]
On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > Hi, Greg
> > > I wrote a simple implementation for the two pieces
> > > of send and receive hotplug event,
> > > use a message queue and a list for the out of order
> > > hotplug event. It also has a timeout timer of 3 seconds.
> > > They are now separate program. the file nseq is the test script.
> > > Could you have a look to see wether it is feasible?
> > > If so, I'll continue to merge with udev.
> >
> > Yes, very nice start. Please continue on.
> >
> > One minor comment, please stick with the kernel coding style when you
> > are writing new code for udev.
>
> I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> tweaked the debugging, added the udev exec and created a patch for the current tree.
>
> It seems functional now, by simply executing our current udev (dirty hack).
> It reorders the incoming events and if one is missing it delays the
> execution of the following ones up to a maximum of 10 seconds.
>
> Test script is included, but you can't mix hotplug sequence numbers and
> test script numbers, it will result in waiting for the missing numbers :)
Hey, nobody want's to play with me?
So here I'm chatting with myself :)
This is the next version with signal handling for resetting the expected
signal number. I changed the behaviour of the timeout to skip all
missing events at once and to proceed with the next event in the queue.
So it's now possible to use the test script at any time, cause it resets
the daemon, if real hotplug event coming in later all missing nimbers will
be skipped after a timeout of 10 seconds and the queued events are applied.
So, as usual, please have a look...
thanks,
Kay
[-- Attachment #2: 01-udevd2.patch --]
[-- Type: text/plain, Size: 11586 bytes --]
diff -Nru a/Makefile b/Makefile
--- a/Makefile Thu Jan 22 01:20:30 2004
+++ b/Makefile Thu Jan 22 01:20:30 2004
@@ -31,6 +31,8 @@
ROOT = udev
+DAEMON = udevd
+SENDER = udevsend
VERSION = 013_bk
INSTALL_DIR = /usr/local/bin
RELEASE_NAME = $(ROOT)-$(VERSION)
@@ -155,7 +157,7 @@
CFLAGS += -I$(PWD)/libsysfs
-all: $(ROOT)
+all: $(ROOT) $(DAEMON) $(SENDER)
@extras="$(EXTRAS)" ; for target in $$extras ; do \
echo $$target ; \
$(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
@@ -229,10 +231,18 @@
$(LD) $(LDFLAGS) -o $(ROOT) $(CRT0) $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
$(STRIPCMD) $(ROOT)
+$(DAEMON): $(ROOT) udevd.h udevd.o
+ $(LD) $(LDFLAGS) -o $(DAEMON) $(CRT0) udevd.o logging.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
+ $(STRIPCMD) $(ROOT)
+
+$(SENDER): $(ROOT) udevd.h udevsend.o
+ $(LD) $(LDFLAGS) -o $(SENDER) $(CRT0) udevsend.o logging.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
+ $(STRIPCMD) $(ROOT)
+
clean:
-find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
| xargs rm -f
- -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS)
+ -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(DAEMON) $(SENDER)
$(MAKE) -C klibc clean
@extras="$(EXTRAS)" ; for target in $$extras ; do \
echo $$target ; \
diff -Nru a/test/udevd_test.sh b/test/udevd_test.sh
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/test/udevd_test.sh Thu Jan 22 01:20:30 2004
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+# reset udevd, expected sequence number and empty queue
+killall -HUP udevd
+
+export ACTION=add
+export DEVPATH=/block/sda
+
+export SEQNUM=1
+./udevsend block
+
+export SEQNUM=2
+./udevsend block
+
+export SEQNUM=3
+./udevsend block
+
+export SEQNUM=5
+./udevsend block
+
+export SEQNUM=4
+./udevsend block
+
+export SEQNUM=6
+./udevsend block
+
+export SEQNUM=7
+./udevsend block
+
+export SEQNUM=10
+./udevsend block
+
+export SEQNUM=9
+#./udevsend block
+
+export SEQNUM=8
+#./udevsend block
+
+export SEQNUM=11
+./udevsend block
+
+export SEQNUM=12
+./udevsend block
+
+export SEQNUM=13
+./udevsend block
+
diff -Nru a/udevd.c b/udevd.c
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/udevd.c Thu Jan 22 01:20:30 2004
@@ -0,0 +1,246 @@
+/*
+ * udevd.c
+ *
+ * Userspace devfs
+ *
+ * Copyright (C) 2004 Ling, Xiaofeng <xiaofeng.ling@intel.com>
+ * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <signal.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "udev.h"
+#include "udevd.h"
+#include "logging.h"
+
+#define BUFFER_SIZE 1024
+#define TIMEOUT_SECONDS 10
+
+static void reset_timer(void);
+static void reset_queue(void);
+
+
+static int expect_seqnum = 0;
+static int timeout_value = TIMEOUT_SECONDS;
+static int timeout = 0;
+static struct hotplug_msg *head = NULL;
+
+static void sig_handler(int signum)
+{
+ dbg("caught signal %d", signum);
+ switch (signum) {
+ case SIGHUP:
+ dbg("reset requested, all waiting events killed");
+ reset_timer();
+ reset_queue();
+ timeout = 0;
+ expect_seqnum = 0;
+ break;
+
+ case SIGINT:
+ case SIGTERM:
+ case SIGKILL:
+ exit(20 + signum);
+ break;
+
+ default:
+ dbg("unhandled signal");
+ }
+}
+
+static void sig_alarmhandler(int signum)
+{
+ dbg("caught signal %d", signum);
+ switch (signum) {
+ case SIGALRM:
+ timeout = 1;
+ dbg("timeout, event lost");
+ break;
+
+ default:
+ dbg("unhandled signal");
+ }
+}
+
+static void dump_queue(void)
+{
+ struct hotplug_msg *p;
+ p = head;
+
+ dbg("next expected sequence %d", expect_seqnum);
+ while(p) {
+ dbg("queued sequence %d", p->seqnum);
+ p=p->next;
+ }
+}
+
+static void dump_msg(struct hotplug_msg *pmsg)
+{
+ dbg("sequence %d, '%s', '%s', '%s'",
+ pmsg->seqnum, pmsg->action, pmsg->devpath, pmsg->subsystem);
+}
+
+static void dispatch_msg(struct hotplug_msg *pmsg)
+{
+ dump_msg(pmsg);
+ setenv("ACTION", pmsg->action, 1);
+ setenv("DEVPATH", pmsg->devpath, 1);
+ execl("/sbin/udev", pmsg->subsystem);
+}
+
+static void reset_timer(void)
+{
+ alarm(0);
+}
+
+static void set_timer(void)
+{
+ signal(SIGALRM, sig_alarmhandler);
+ alarm(timeout_value);
+}
+
+static void reset_queue(void)
+{
+ struct hotplug_msg *p;
+ p = head;
+
+ while(head) {
+ p = head;
+ head = head->next;
+ free(p);
+ }
+}
+
+static void check_queue(void)
+{
+ struct hotplug_msg *p;
+ p = head;
+
+ dump_queue();
+ while(head && head->seqnum == expect_seqnum) {
+ dispatch_msg(head);
+ expect_seqnum++;
+ p = head;
+ head = head->next;
+ free(p);
+ }
+ if (head != NULL)
+ set_timer();
+ else
+ reset_timer();
+}
+
+static void add_queue(struct hotplug_msg *pmsg)
+{
+ struct hotplug_msg *pnewmsg;
+ struct hotplug_msg *p;
+ struct hotplug_msg *p1;
+
+ p = head;
+ p1 = NULL;
+ pnewmsg = malloc(sizeof(struct hotplug_msg));
+ *pnewmsg = *pmsg;
+ pnewmsg->next = NULL;
+ while(p && pmsg->seqnum > p->seqnum) {
+ p1 = p;
+ p = p->next;
+ }
+ pnewmsg->next = p;
+ if (p1 == NULL) {
+ head = pnewmsg;
+ } else {
+ p1->next = pnewmsg;
+ }
+ dump_queue();
+}
+
+static int process_queue(void)
+{
+ int msgid;
+ key_t key;
+ struct hotplug_msg *pmsg;
+ char buf[BUFFER_SIZE];
+ int ret;
+
+ key = 12345; /*may use inode number of /etc/udev? */
+ pmsg = (struct hotplug_msg *) buf;
+ msgid = msgget(key, IPC_CREAT);
+ if (msgid == -1) {
+ dbg("open message queue error");
+ goto exit;
+ }
+ while (1) {
+ ret = msgrcv(msgid, (struct msgbuf *) buf, BUFFER_SIZE-4, HOTPLUGMSGTYPE, 0);
+ if (ret != -1) {
+ dbg("current sequence %d, expected sequence %d", pmsg->seqnum, expect_seqnum);
+
+ /* init expected sequence with value from first call */
+ if (expect_seqnum == 0) {
+ expect_seqnum = pmsg->seqnum;
+ dbg("init next expected sequence number to %d", expect_seqnum);
+ }
+
+ if (pmsg->seqnum > expect_seqnum) {
+ add_queue(pmsg);
+ set_timer();
+ } else {
+ if (pmsg->seqnum == expect_seqnum) {
+ dispatch_msg(pmsg);
+ expect_seqnum++;
+ check_queue();
+ } else {
+ dbg("timeout event for unexpected sequence number %d", pmsg->seqnum);
+ }
+ }
+ } else
+ if (errno == EINTR) {
+ if (head != NULL) {
+ /* timeout, skip all missing, proceed with next queued event */
+ dbg("timeout reached, skip events %d - %d", expect_seqnum, head->seqnum-1);
+ expect_seqnum = head->seqnum;
+ }
+ check_queue();
+ timeout = 0;
+ } else {
+ dbg("recv error '%s'", strerror(errno));
+ }
+ }
+ return 0;
+exit:
+ return -1;
+}
+
+int main(int argc, char *argv[])
+{
+ /* set up signal handler */
+ signal(SIGINT, sig_handler);
+ signal(SIGTERM, sig_handler);
+ signal(SIGKILL, sig_handler);
+ signal(SIGHUP, sig_handler);
+
+ process_queue();
+ return 0;
+}
diff -Nru a/udevd.h b/udevd.h
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/udevd.h Thu Jan 22 01:20:30 2004
@@ -0,0 +1,33 @@
+/*
+ * udevd.h
+ *
+ * Userspace devfs
+ *
+ * Copyright (C) 2004 Ling, Xiaofeng <xiaofeng.ling@intel.com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#define HOTPLUGMSGTYPE 44
+
+struct hotplug_msg {
+ long mtype;
+ struct hotplug_msg *next;
+ int seqnum;
+ char action[8];
+ char devpath[128];
+ char subsystem[16];
+};
diff -Nru a/udevsend.c b/udevsend.c
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/udevsend.c Thu Jan 22 01:20:30 2004
@@ -0,0 +1,143 @@
+/*
+ * udevsend.c
+ *
+ * Userspace devfs
+ *
+ * Copyright (C) 2004 Ling, Xiaofeng <xiaofeng.ling@intel.com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "udev.h"
+#include "udevd.h"
+#include "logging.h"
+
+static inline char *get_action(void)
+{
+ char *action;
+
+ action = getenv("ACTION");
+ return action;
+}
+
+static inline char *get_devpath(void)
+{
+ char *devpath;
+
+ devpath = getenv("DEVPATH");
+ return devpath;
+}
+
+static inline char *get_seqnum(void)
+{
+ char *seqnum;
+
+ seqnum = getenv("SEQNUM");
+ return seqnum;
+}
+
+static int build_hotplugmsg(struct hotplug_msg **ppmsg, char *action,
+ char *devpath, char *subsystem, int seqnum)
+{
+ struct hotplug_msg *pmsg;
+
+ pmsg = malloc(sizeof(struct hotplug_msg));
+ pmsg->mtype = HOTPLUGMSGTYPE;
+ pmsg->seqnum = seqnum;
+ strncpy(pmsg->action, action, 8);
+ strncpy(pmsg->devpath, devpath, 128);
+ strncpy(pmsg->subsystem, subsystem, 16);
+ *ppmsg = pmsg;
+ return sizeof(struct hotplug_msg);
+}
+
+static void free_hotplugmsg(struct hotplug_msg *pmsg)
+{
+ free(pmsg);
+}
+
+int main(int argc, char* argv[])
+{
+ int msgid;
+ struct msgbuf *pmsg;
+ key_t key;
+ char *action;
+ char *devpath;
+ char *subsystem;
+ char *seqnum;
+ int seq;
+ int retval = -EINVAL;
+ int size;
+
+ key = 12345; /*may use inode number of /etc/udev?*/
+
+ subsystem = argv[1];
+ if (subsystem == NULL) {
+ dbg("no subsystem");
+ goto exit;
+ }
+
+ devpath = get_devpath();
+ if (devpath == NULL) {
+ dbg("no devpath");
+ goto exit;
+ }
+
+ action = get_action();
+ if (action == NULL) {
+ dbg("no action");
+ goto exit;
+ }
+
+ seqnum = get_seqnum();
+ if (seqnum == NULL) {
+ dbg("no seqnum");
+ goto exit;
+ }
+
+ seq = atoi(seqnum);
+
+ size = build_hotplugmsg( (struct hotplug_msg**) &pmsg, action, devpath, subsystem, seq);
+ msgid = msgget(key, IPC_CREAT);
+ if (msgid == -1)
+ {
+ dbg("open message queue error");
+ goto exit;
+ }
+
+ retval = msgsnd(msgid, pmsg, size, 0);
+ free_hotplugmsg( (struct hotplug_msg*) pmsg);
+ if (retval == -1)
+ {
+ dbg("send message error");
+ goto exit;
+ }
+ return 0;
+
+exit:
+ if (retval > 0)
+ retval = 0;
+
+ return retval;
+}
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (12 preceding siblings ...)
2004-01-22 0:27 ` Kay Sievers
@ 2004-01-22 1:08 ` Kay Sievers
2004-01-22 23:01 ` Kay Sievers
` (8 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: Kay Sievers @ 2004-01-22 1:08 UTC (permalink / raw)
To: linux-hotplug
On Thu, Jan 22, 2004 at 01:27:45AM +0100, Kay Sievers wrote:
> On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> > On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > > Hi, Greg
> > > > I wrote a simple implementation for the two pieces
> > > > of send and receive hotplug event,
> > > > use a message queue and a list for the out of order
> > > > hotplug event. It also has a timeout timer of 3 seconds.
> > > > They are now separate program. the file nseq is the test script.
> > > > Could you have a look to see wether it is feasible?
> > > > If so, I'll continue to merge with udev.
> > >
> > > Yes, very nice start. Please continue on.
> > >
> > > One minor comment, please stick with the kernel coding style when you
> > > are writing new code for udev.
> >
> > I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> > tweaked the debugging, added the udev exec and created a patch for the current tree.
> >
> > It seems functional now, by simply executing our current udev (dirty hack).
> > It reorders the incoming events and if one is missing it delays the
> > execution of the following ones up to a maximum of 10 seconds.
> >
> > Test script is included, but you can't mix hotplug sequence numbers and
> > test script numbers, it will result in waiting for the missing numbers :)
>
> Hey, nobody want's to play with me?
> So here I'm chatting with myself :)
>
> This is the next version with signal handling for resetting the expected
> signal number. I changed the behaviour of the timeout to skip all
> missing events at once and to proceed with the next event in the queue.
>
> So it's now possible to use the test script at any time, cause it resets
> the daemon, if real hotplug event coming in later all missing nimbers will
> be skipped after a timeout of 10 seconds and the queued events are applied.
Here for the lazy one :)
Log from the test script which demonstrates the event reordering.
Event 5 is arriving before event 4, so 4 is queued until 5 is coming in,
then both are executed.
Events 8 and 9 are completely missing, so we wait for 10 seconds then go
ahead and exec the remaining events in the queue.
thanks,
Kay
Jan 22 01:16:42 pim udev[17562]: dump_queue: next expected sequence 0
#in 1
Jan 22 01:16:42 pim udev[17562]: process_queue: current sequence 1, expected sequence 0
#out 1
Jan 22 01:16:42 pim udev[17562]: dump_msg: sequence 1, 'add', '/block/sda', 'block'
Jan 22 01:16:42 pim udev[17562]: dump_queue: next expected sequence 2
#in 2
Jan 22 01:16:42 pim udev[17562]: process_queue: current sequence 2, expected sequence 2
#out 2
Jan 22 01:16:42 pim udev[17562]: dump_msg: sequence 2, 'add', '/block/sda', 'block'
Jan 22 01:16:42 pim udev[17562]: dump_queue: next expected sequence 3
#in 3
Jan 22 01:16:42 pim udev[17562]: process_queue: current sequence 3, expected sequence 3
#out 3
Jan 22 01:16:42 pim udev[17562]: dump_msg: sequence 3, 'add', '/block/sda', 'block'
Jan 22 01:16:42 pim udev[17562]: dump_queue: next expected sequence 4
#in 5
Jan 22 01:16:42 pim udev[17562]: process_queue: current sequence 5, expected sequence 4
Jan 22 01:16:42 pim udev[17562]: dump_queue: next expected sequence 4
#queue 5
Jan 22 01:16:42 pim udev[17562]: dump_queue: queued sequence 5
#in 4
Jan 22 01:16:42 pim udev[17562]: process_queue: current sequence 4, expected sequence 4
#out 4
Jan 22 01:16:42 pim udev[17562]: dump_msg: sequence 4, 'add', '/block/sda', 'block'
Jan 22 01:16:42 pim udev[17562]: dump_queue: next expected sequence 5
Jan 22 01:16:42 pim udev[17562]: dump_queue: queued sequence 5 out queued 5
#out 5 (delayed)
Jan 22 01:16:42 pim udev[17562]: dump_msg: sequence 5, 'add', '/block/sda', 'block'
#in 6
Jan 22 01:16:42 pim udev[17562]: process_queue: current sequence 6, expected sequence 6
#out 6
Jan 22 01:16:42 pim udev[17562]: dump_msg: sequence 6, 'add', '/block/sda', 'block'
Jan 22 01:16:42 pim udev[17562]: dump_queue: next expected sequence 7
#in 7
Jan 22 01:16:42 pim udev[17562]: process_queue: current sequence 7, expected sequence 7
#out 7
Jan 22 01:16:42 pim udev[17562]: dump_msg: sequence 7, 'add', '/block/sda', 'block'
Jan 22 01:16:42 pim udev[17562]: dump_queue: next expected sequence 8
#in 10
Jan 22 01:16:42 pim udev[17562]: process_queue: current sequence 10, expected sequence 8
Jan 22 01:16:42 pim udev[17562]: dump_queue: next expected sequence 8 queue 10
Jan 22 01:16:42 pim udev[17562]: dump_queue: queued sequence 10
#in 11
Jan 22 01:16:42 pim udev[17562]: process_queue: current sequence 11, expected sequence 8
Jan 22 01:16:42 pim udev[17562]: dump_queue: next expected sequence 8 queue 11
Jan 22 01:16:42 pim udev[17562]: dump_queue: queued sequence 10
Jan 22 01:16:42 pim udev[17562]: dump_queue: queued sequence 11
#in 12
Jan 22 01:16:42 pim udev[17562]: process_queue: current sequence 12, expected sequence 8
Jan 22 01:16:42 pim udev[17562]: dump_queue: next expected sequence 8 queue 12
Jan 22 01:16:42 pim udev[17562]: dump_queue: queued sequence 10
Jan 22 01:16:42 pim udev[17562]: dump_queue: queued sequence 11
Jan 22 01:16:42 pim udev[17562]: dump_queue: queued sequence 12
#in 13
Jan 22 01:16:42 pim udev[17562]: process_queue: current sequence 13, expected sequence 8
Jan 22 01:16:42 pim udev[17562]: dump_queue: next expected sequence 8 queue 13
Jan 22 01:16:42 pim udev[17562]: dump_queue: queued sequence 10
Jan 22 01:16:42 pim udev[17562]: dump_queue: queued sequence 11
Jan 22 01:16:42 pim udev[17562]: dump_queue: queued sequence 12
Jan 22 01:16:42 pim udev[17562]: dump_queue: queued sequence 13
#10 seconds timeout, skip missing events 8 and 9, proceed with queue
Jan 22 01:16:52 pim udev[17562]: sig_alarmhandler: caught signal 14
Jan 22 01:16:52 pim udev[17562]: sig_alarmhandler: timeout, event lost
Jan 22 01:16:52 pim udev[17562]: process_queue: timeout reached, skip events 8 - 9
Jan 22 01:16:52 pim udev[17562]: dump_queue: next expected sequence 10
Jan 22 01:16:52 pim udev[17562]: dump_queue: queued sequence 10
Jan 22 01:16:52 pim udev[17562]: dump_queue: queued sequence 11
Jan 22 01:16:52 pim udev[17562]: dump_queue: queued sequence 12
Jan 22 01:16:52 pim udev[17562]: dump_queue: queued sequence 13
#out 10 (delayed)
Jan 22 01:16:52 pim udev[17562]: dump_msg: sequence 10, 'add', '/block/sda', 'block'
#out 11 (delayed)
Jan 22 01:16:52 pim udev[17562]: dump_msg: sequence 11, 'add', '/block/sda', 'block'
#out 12 (delayed)
Jan 22 01:16:52 pim udev[17562]: dump_msg: sequence 12, 'add', '/block/sda', 'block'
#out 13 (delayed)
Jan 22 01:16:52 pim udev[17562]: dump_msg: sequence 13, 'add', '/block/sda', 'block'
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (13 preceding siblings ...)
2004-01-22 1:08 ` Kay Sievers
@ 2004-01-22 23:01 ` Kay Sievers
2004-01-23 0:34 ` Greg KH
` (7 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: Kay Sievers @ 2004-01-22 23:01 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 2568 bytes --]
On Thu, Jan 22, 2004 at 01:27:45AM +0100, Kay Sievers wrote:
> On Wed, Jan 21, 2004 at 02:38:25PM +0100, Kay Sievers wrote:
> > On Thu, Jan 15, 2004 at 01:45:10PM -0800, Greg KH wrote:
> > > On Thu, Jan 15, 2004 at 10:36:25PM +0800, Ling, Xiaofeng wrote:
> > > > Hi, Greg
> > > > I wrote a simple implementation for the two pieces
> > > > of send and receive hotplug event,
> > > > use a message queue and a list for the out of order
> > > > hotplug event. It also has a timeout timer of 3 seconds.
> > > > They are now separate program. the file nseq is the test script.
> > > > Could you have a look to see wether it is feasible?
> > > > If so, I'll continue to merge with udev.
> > >
> > > Yes, very nice start. Please continue on.
> > >
> > > One minor comment, please stick with the kernel coding style when you
> > > are writing new code for udev.
> >
> > I took the code from Xiaofeng, cleaned the whitespace, renamed some bits,
> > tweaked the debugging, added the udev exec and created a patch for the current tree.
> >
> > It seems functional now, by simply executing our current udev (dirty hack).
> > It reorders the incoming events and if one is missing it delays the
> > execution of the following ones up to a maximum of 10 seconds.
> >
> > Test script is included, but you can't mix hotplug sequence numbers and
> > test script numbers, it will result in waiting for the missing numbers :)
>
> Hey, nobody want's to play with me?
> So here I'm chatting with myself :)
>
> This is the next version with signal handling for resetting the expected
> signal number. I changed the behaviour of the timeout to skip all
> missing events at once and to proceed with the next event in the queue.
>
> So it's now possible to use the test script at any time, cause it resets
> the daemon, if real hotplug event coming in later all missing nimbers will
> be skipped after a timeout of 10 seconds and the queued events are applied.
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.
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.
Should we start the daemon if noone listens, when the sender is called?
Should we convert our udev to a daemon, or stay with the exec?
thanks,
Kay
[-- Attachment #2: 01-udevd.patch --]
[-- Type: text/plain, Size: 12254 bytes --]
diff -Nru a/Makefile b/Makefile
--- a/Makefile Thu Jan 22 23:48:23 2004
+++ b/Makefile Thu Jan 22 23:48:23 2004
@@ -31,6 +31,8 @@
ROOT = udev
+DAEMON = udevd
+SENDER = udevsend
VERSION = 014
INSTALL_DIR = /usr/local/bin
RELEASE_NAME = $(ROOT)-$(VERSION)
@@ -155,7 +157,7 @@
CFLAGS += -I$(PWD)/libsysfs
-all: $(ROOT)
+all: $(ROOT) $(DAEMON) $(SENDER)
@extras="$(EXTRAS)" ; for target in $$extras ; do \
echo $$target ; \
$(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
@@ -229,10 +231,18 @@
$(LD) $(LDFLAGS) -o $(ROOT) $(CRT0) $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
$(STRIPCMD) $(ROOT)
+$(DAEMON): $(ROOT) udevd.h udevd.o
+ $(LD) $(LDFLAGS) -o $(DAEMON) $(CRT0) udevd.o logging.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
+ $(STRIPCMD) $(ROOT)
+
+$(SENDER): $(ROOT) udevd.h udevsend.o
+ $(LD) $(LDFLAGS) -o $(SENDER) $(CRT0) udevsend.o logging.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
+ $(STRIPCMD) $(ROOT)
+
clean:
-find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
| xargs rm -f
- -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS)
+ -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(DAEMON) $(SENDER)
$(MAKE) -C klibc clean
@extras="$(EXTRAS)" ; for target in $$extras ; do \
echo $$target ; \
diff -Nru a/test/udevd_test.sh b/test/udevd_test.sh
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/test/udevd_test.sh Thu Jan 22 23:48:23 2004
@@ -0,0 +1,47 @@
+#!/bin/bash
+
+# reset udevd, expected sequence number and empty queue
+killall -HUP udevd
+
+export ACTION=add
+export DEVPATH=/block/sda
+
+export SEQNUM=1
+./udevsend block
+
+export SEQNUM=2
+./udevsend block
+
+export SEQNUM=3
+./udevsend block
+
+export SEQNUM=5
+./udevsend block
+
+export SEQNUM=4
+./udevsend block
+
+export SEQNUM=6
+./udevsend block
+
+export SEQNUM=7
+./udevsend block
+
+export SEQNUM=10
+./udevsend block
+
+export SEQNUM=9
+#./udevsend block
+
+export SEQNUM=8
+#./udevsend block
+
+export SEQNUM=13
+./udevsend block
+
+export SEQNUM=12
+./udevsend block
+
+export SEQNUM=11
+./udevsend block
+
diff -Nru a/udevd.c b/udevd.c
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/udevd.c Thu Jan 22 23:48:23 2004
@@ -0,0 +1,255 @@
+/*
+ * udevd.c
+ *
+ * Userspace devfs
+ *
+ * Copyright (C) 2004 Ling, Xiaofeng <xiaofeng.ling@intel.com>
+ * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <signal.h>
+#include <unistd.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "udev.h"
+#include "udevd.h"
+#include "logging.h"
+
+#define BUFFER_SIZE 1024
+#define TIMEOUT_SECONDS 10
+
+static void reset_timer(void);
+static void reset_queue(void);
+
+
+static int expect_seqnum = 0;
+static int timeout_value = TIMEOUT_SECONDS;
+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);
+ switch (signum) {
+ case SIGHUP:
+ dbg("reset requested, all waiting events killed");
+ reset_timer();
+ reset_queue();
+ timeout = 0;
+ expect_seqnum = 0;
+ break;
+
+ case SIGINT:
+ case SIGTERM:
+ case SIGKILL:
+ exit(20 + signum);
+ break;
+
+ default:
+ dbg("unhandled signal");
+ }
+}
+
+static void sig_alarmhandler(int signum)
+{
+ dbg("caught signal %d", signum);
+ switch (signum) {
+ case SIGALRM:
+ timeout = 1;
+ dbg("event timeout reached");
+ break;
+
+ default:
+ dbg("unhandled signal");
+ }
+}
+
+static void dump_queue(void)
+{
+ struct hotplug_msg *p;
+ p = head;
+
+ dbg("next expected sequence is %d", expect_seqnum);
+ while(p) {
+ dbg("sequence %d in queue", p->seqnum);
+ p=p->next;
+ }
+}
+
+static void dump_msg(struct hotplug_msg *pmsg)
+{
+ dbg("sequence %d, '%s', '%s', '%s'",
+ pmsg->seqnum, pmsg->action, pmsg->devpath, pmsg->subsystem);
+}
+
+static void dispatch_msg(struct hotplug_msg *pmsg)
+{
+ dump_msg(pmsg);
+ dbg("exec '%s'", exec_program);
+ setenv("ACTION", pmsg->action, 1);
+ setenv("DEVPATH", pmsg->devpath, 1);
+ execl(exec_program, pmsg->subsystem);
+}
+
+static void reset_timer(void)
+{
+ alarm(0);
+}
+
+static void set_timer(void)
+{
+ signal(SIGALRM, sig_alarmhandler);
+ alarm(timeout_value);
+}
+
+static void reset_queue(void)
+{
+ struct hotplug_msg *p;
+ p = head;
+
+ while(head) {
+ p = head;
+ head = head->next;
+ free(p);
+ }
+}
+
+static void check_queue(void)
+{
+ struct hotplug_msg *p;
+ p = head;
+
+ dump_queue();
+ while(head && head->seqnum == expect_seqnum) {
+ dispatch_msg(head);
+ expect_seqnum++;
+ p = head;
+ head = head->next;
+ free(p);
+ }
+ if (head != NULL)
+ set_timer();
+ else
+ reset_timer();
+}
+
+static void add_queue(struct hotplug_msg *pmsg)
+{
+ struct hotplug_msg *pnewmsg;
+ struct hotplug_msg *p;
+ struct hotplug_msg *p1;
+
+ p = head;
+ p1 = NULL;
+ pnewmsg = malloc(sizeof(struct hotplug_msg));
+ *pnewmsg = *pmsg;
+ pnewmsg->next = NULL;
+ while(p && pmsg->seqnum > p->seqnum) {
+ p1 = p;
+ p = p->next;
+ }
+ pnewmsg->next = p;
+ if (p1 == NULL) {
+ head = pnewmsg;
+ } else {
+ p1->next = pnewmsg;
+ }
+ dump_queue();
+}
+
+static int process_queue(void)
+{
+ int msgid;
+ key_t key;
+ struct hotplug_msg *pmsg;
+ char buf[BUFFER_SIZE];
+ int ret;
+
+ key = ftok(DEFAULT_EXEC_PROGRAM, IPC_KEY_ID);
+ pmsg = (struct hotplug_msg *) buf;
+ msgid = msgget(key, IPC_CREAT);
+ if (msgid == -1) {
+ dbg("open message queue error");
+ goto exit;
+ }
+ while (1) {
+ ret = msgrcv(msgid, (struct msgbuf *) buf, BUFFER_SIZE-4, HOTPLUGMSGTYPE, 0);
+ if (ret != -1) {
+ dbg("current sequence %d, expected sequence %d", pmsg->seqnum, expect_seqnum);
+
+ /* init expected sequence with value from first call */
+ if (expect_seqnum == 0) {
+ expect_seqnum = pmsg->seqnum;
+ dbg("init next expected sequence number to %d", expect_seqnum);
+ }
+
+ if (pmsg->seqnum > expect_seqnum) {
+ add_queue(pmsg);
+ set_timer();
+ } else {
+ if (pmsg->seqnum == expect_seqnum) {
+ dispatch_msg(pmsg);
+ expect_seqnum++;
+ check_queue();
+ } else {
+ dbg("timeout event for unexpected sequence number %d", pmsg->seqnum);
+ }
+ }
+ } else
+ if (errno == EINTR) {
+ if (head != NULL) {
+ /* timeout, skip all missing, proceed with next queued event */
+ dbg("timeout reached, skip events %d - %d", expect_seqnum, head->seqnum-1);
+ expect_seqnum = head->seqnum;
+ }
+ check_queue();
+ timeout = 0;
+ } else {
+ dbg("ipc message receive error '%s'", strerror(errno));
+ }
+ }
+ return 0;
+exit:
+ return -1;
+}
+
+int main(int argc, char *argv[])
+{
+ /* get program to exec on events */
+ if (argc == 2)
+ strncpy(exec_program, argv[1], sizeof(exec_program));
+ else
+ strcpy(exec_program, DEFAULT_EXEC_PROGRAM);
+
+ /* set up signal handler */
+ signal(SIGINT, sig_handler);
+ signal(SIGTERM, sig_handler);
+ signal(SIGKILL, sig_handler);
+ signal(SIGHUP, sig_handler);
+
+ /* main loop */
+ process_queue();
+ return 0;
+}
diff -Nru a/udevd.h b/udevd.h
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/udevd.h Thu Jan 22 23:48:23 2004
@@ -0,0 +1,36 @@
+/*
+ * udevd.h
+ *
+ * Userspace devfs
+ *
+ * Copyright (C) 2004 Ling, Xiaofeng <xiaofeng.ling@intel.com>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#define HOTPLUGMSGTYPE 44
+#define DEFAULT_EXEC_PROGRAM "/sbin/udev"
+#define IPC_KEY_ID 0
+
+
+struct hotplug_msg {
+ long mtype;
+ struct hotplug_msg *next;
+ int seqnum;
+ char action[8];
+ char devpath[128];
+ char subsystem[16];
+};
diff -Nru a/udevsend.c b/udevsend.c
--- /dev/null Wed Dec 31 16:00:00 1969
+++ b/udevsend.c Thu Jan 22 23:48:23 2004
@@ -0,0 +1,152 @@
+/*
+ * udevsend.c
+ *
+ * Userspace devfs
+ *
+ * Copyright (C) 2004 Ling, Xiaofeng <xiaofeng.ling@intel.com>
+ * Copyright (C) 2004 Kay Sievers <kay.sievers@vrfy.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/msg.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "udev.h"
+#include "udevd.h"
+#include "logging.h"
+
+static inline char *get_action(void)
+{
+ char *action;
+
+ action = getenv("ACTION");
+ return action;
+}
+
+static inline char *get_devpath(void)
+{
+ char *devpath;
+
+ devpath = getenv("DEVPATH");
+ return devpath;
+}
+
+static inline char *get_seqnum(void)
+{
+ char *seqnum;
+
+ seqnum = getenv("SEQNUM");
+ return seqnum;
+}
+
+static int build_hotplugmsg(struct hotplug_msg **ppmsg, char *action,
+ char *devpath, char *subsystem, int seqnum)
+{
+ struct hotplug_msg *pmsg;
+
+ pmsg = malloc(sizeof(struct hotplug_msg));
+ pmsg->mtype = HOTPLUGMSGTYPE;
+ pmsg->seqnum = seqnum;
+ strncpy(pmsg->action, action, 8);
+ strncpy(pmsg->devpath, devpath, 128);
+ strncpy(pmsg->subsystem, subsystem, 16);
+ *ppmsg = pmsg;
+ return sizeof(struct hotplug_msg);
+}
+
+static void free_hotplugmsg(struct hotplug_msg *pmsg)
+{
+ free(pmsg);
+}
+
+int main(int argc, char* argv[])
+{
+ int msgid;
+ key_t key;
+ struct msqid_ds msg_queue;
+ struct msgbuf *pmsg;
+ char *action;
+ char *devpath;
+ char *subsystem;
+ char *seqnum;
+ int seq;
+ int retval = -EINVAL;
+ int size;
+
+ subsystem = argv[1];
+ if (subsystem == NULL) {
+ dbg("no subsystem");
+ goto exit;
+ }
+
+ devpath = get_devpath();
+ if (devpath == NULL) {
+ dbg("no devpath");
+ goto exit;
+ }
+
+ action = get_action();
+ if (action == NULL) {
+ dbg("no action");
+ goto exit;
+ }
+
+ seqnum = get_seqnum();
+ if (seqnum == NULL) {
+ dbg("no seqnum");
+ goto exit;
+ }
+
+ 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");
+ goto exit;
+ }
+
+ /* get state of queue */
+ retval = msgctl(msgid, IPC_STAT, &msg_queue);
+ if (retval == -1) {
+ dbg("error getting info on ipc queue");
+ goto exit;
+ }
+ if (msg_queue.msg_qnum > 0)
+ dbg("%li messages already in the ipc queue", msg_queue.msg_qnum);
+
+ retval = msgsnd(msgid, pmsg, size, 0);
+ free_hotplugmsg( (struct hotplug_msg*) pmsg);
+ if (retval == -1)
+ {
+ dbg("send ipc message error");
+ goto exit;
+ }
+ return 0;
+
+exit:
+ if (retval > 0)
+ retval = 0;
+
+ return retval;
+}
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (14 preceding siblings ...)
2004-01-22 23:01 ` Kay Sievers
@ 2004-01-23 0:34 ` Greg KH
2004-01-23 1:00 ` Kay Sievers
` (6 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: Greg KH @ 2004-01-23 0:34 UTC (permalink / raw)
To: linux-hotplug
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
?
> Should we start the daemon if noone listens, when the sender is called?
Yes.
> 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.
thanks,
greg k-h
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (15 preceding siblings ...)
2004-01-23 0:34 ` Greg KH
@ 2004-01-23 1:00 ` Kay Sievers
2004-01-23 3:37 ` Kay Sievers
` (5 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: Kay Sievers @ 2004-01-23 1:00 UTC (permalink / raw)
To: linux-hotplug
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.
thanks,
Kay
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (16 preceding siblings ...)
2004-01-23 1:00 ` Kay Sievers
@ 2004-01-23 3:37 ` Kay Sievers
2004-01-23 3:46 ` Greg KH
` (4 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: Kay Sievers @ 2004-01-23 3:37 UTC (permalink / raw)
To: linux-hotplug
[-- 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;
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (17 preceding siblings ...)
2004-01-23 3:37 ` Kay Sievers
@ 2004-01-23 3:46 ` Greg KH
2004-01-23 3:58 ` Kay Sievers
` (3 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: Greg KH @ 2004-01-23 3:46 UTC (permalink / raw)
To: linux-hotplug
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?
thanks,
greg k-h
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (18 preceding siblings ...)
2004-01-23 3:46 ` Greg KH
@ 2004-01-23 3:58 ` Kay Sievers
2004-01-23 4:04 ` Greg KH
` (2 subsequent siblings)
22 siblings, 0 replies; 24+ messages in thread
From: Kay Sievers @ 2004-01-23 3:58 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 2209 bytes --]
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
[-- Attachment #2: 01-exec-fix.patch --]
[-- Type: text/plain, Size: 2308 bytes --]
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 <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: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;
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (19 preceding siblings ...)
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
22 siblings, 0 replies; 24+ messages in thread
From: Greg KH @ 2004-01-23 4:04 UTC (permalink / raw)
To: linux-hotplug
On Fri, Jan 23, 2004 at 04:58:32AM +0100, Kay Sievers wrote:
> > > 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, applied. And I made those files be ignored by bk.
thanks again,
greg k-h
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 24+ messages in thread* RE: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (20 preceding siblings ...)
2004-01-23 4:04 ` Greg KH
@ 2004-01-24 16:06 ` Ling, Xiaofeng
2004-01-24 16:57 ` Kay Sievers
22 siblings, 0 replies; 24+ messages in thread
From: Ling, Xiaofeng @ 2004-01-24 16:06 UTC (permalink / raw)
To: linux-hotplug
Thank you for continuing my work. (I'm in a long vocation for two weeks)
I'm already working on making udev to a daemon but I like your idea to let udevd
invoke udev. This way there will be less effect to current udev.
I've some comments about the timeout value, see below.
> -----Original Message-----
> From: Kay Sievers [mailto:kay.sievers@vrfy.org]
> Sent: 2004Äê1ÔÂ22ÈÕ 8:28
> To: Greg KH
> Cc: Ling, Xiaofeng; linux-hotplug-devel@lists.sourceforge.net
> Subject: Re: about split the udev
>
> So it's now possible to use the test script at any time,
> cause it resets the daemon, if real hotplug event coming in
> later all missing nimbers will be skipped after a timeout of
> 10 seconds and the queued events are applied.
Is 10 seconds a little too longer?
If there is only one event lost and one user have to wait 10 seconds when plugging in
a device, is this acceptable for he/she?
Initial, my idea is making the timeout value related with the number of lost events, so
if happened there is one event lost, we just need to wait for 3 seconds.If two, wait for 6 seconds.
Of couse, maybe a maximum value is also needed.
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: about split the udev
2004-01-12 7:53 about split the udev Ling, Xiaofeng
` (21 preceding siblings ...)
2004-01-24 16:06 ` Ling, Xiaofeng
@ 2004-01-24 16:57 ` Kay Sievers
22 siblings, 0 replies; 24+ messages in thread
From: Kay Sievers @ 2004-01-24 16:57 UTC (permalink / raw)
To: linux-hotplug
On Sun, Jan 25, 2004 at 12:06:52AM +0800, Ling, Xiaofeng wrote:
> Thank you for continuing my work. (I'm in a long vocation for two weeks)
> I'm already working on making udev to a daemon but I like your idea to let udevd
> invoke udev. This way there will be less effect to current udev.
Yes, but now we wait for the exec of udev , before we do the next.
This is much too slow if you have a lot of callouts in the rules.
I think we need something that can execute without blocking, but we
need to care that "remove" is much much faster than "add".
Greg, do we need to care about the order of execution of udev for
different device pathes?
If not, we may fork all udev's in the background, unless we have one
with the same path already running.
We may maintain the state of the fork in our sequence list and delay
all events for device pathes udev is already working on.
If we receive the SIGCHLD, then we execute the delayed one.
Hmm, if this may work?
> I've some comments about the timeout value, see below.
> > From: Kay Sievers [mailto:kay.sievers@vrfy.org]
> > So it's now possible to use the test script at any time,
> > cause it resets the daemon, if real hotplug event coming in
> > later all missing nimbers will be skipped after a timeout of
> > 10 seconds and the queued events are applied.
Yes, but we need this to follow the log while testing.
If we have a working codebase, we can set it to something useful.
> Is 10 seconds a little too longer?
> If there is only one event lost and one user have to wait 10 seconds when plugging in
> a device, is this acceptable for he/she?
> Initial, my idea is making the timeout value related with the number of lost events, so
> if happened there is one event lost, we just need to wait for 3 seconds.If two, wait for 6 seconds.
> Of couse, maybe a maximum value is also needed.
I think this is already solved.
On timeout we skip all missing events and go ahead with the next
event in the queue. So if 100 events in a row missing, there will
be one timeout only.
thanks,
Kay
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 24+ messages in thread