diff options
author | kay.sievers@vrfy.org <kay.sievers@vrfy.org> | 2004-01-23 00:28:57 -0800 |
---|---|---|
committer | Greg KH <gregkh@suse.de> | 2005-04-26 21:13:17 -0700 |
commit | 7fafc0324272731c5666047715b9f58f56761534 (patch) | |
tree | e889be520c65f9a1de15fd3cf77017c55eadffce /udevsend.c | |
parent | 659c37bb4b9b28ffdef18e2cbe02728c0eeb2a44 (diff) |
[PATCH] spilt udev into pieces
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.
Diffstat (limited to 'udevsend.c')
-rw-r--r-- | udevsend.c | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/udevsend.c b/udevsend.c new file mode 100644 index 0000000000..37afaf55fa --- /dev/null +++ b/udevsend.c @@ -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; +} |