summaryrefslogtreecommitdiff
path: root/udevsend.c
diff options
context:
space:
mode:
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>2004-01-23 21:25:17 -0800
committerGreg KH <gregkh@suse.de>2005-04-26 21:13:18 -0700
commit33db4b8da001242b8b3b0ce8a746ef46d4416d6d (patch)
treea3d05a5b41f92c095ef621d7f0e821ea938c66ed /udevsend.c
parent90c210eb6bfc2ae294202fffb080315f3c47a57b (diff)
[PATCH] udev - next round of udev event order daemon
Here is the next round of udevd/udevsend: udevsend - If the IPC message we send is not catched by a receiver we fork the udevd daemon to process this and the following events udevd - We reorder the events we receive and execute our current udev for every event. If one or more events are missing, we wait 10 seconds and then go ahead in the queue. If the queue is empty and we don't receive any event for the next 30 seconds, the daemon exits. The next incoming event will fork the daemon again. config - The path's to the executable are specified in udevd.h Now they are pointing to the current directory only. I don't like daemons hiding secrets (and mem leaks :)) inside, so I want to try this model. It should be enough logic to get all possible hotplug events executed in the right order. If no event, then no daemon! So everybody should be happy :) Here we see: 1. the daemon fork, 2. the udev work, 3. the 10 sec timeout and the skipped events, 4. the udev work, ..., 5. and the 30 sec timeout and exit. EVENTS: pim:/home/kay/src/udev.kay# test/udevd_test.sh pim:/home/kay/src/udev.kay# SEQNUM=15 ./udevsend block pim:/home/kay/src/udev.kay# SEQNUM=16 ./udevsend block pim:/home/kay/src/udev.kay# SEQNUM=17 ./udevsend block pim:/home/kay/src/udev.kay# SEQNUM=18 ./udevsend block pim:/home/kay/src/udev.kay# SEQNUM=20 ./udevsend block pim:/home/kay/src/udev.kay# SEQNUM=21 ./udevsend block LOG: Jan 23 15:35:35 pim udev[11795]: message is still in the ipc queue, starting daemon... Jan 23 15:35:35 pim udev[11799]: configured rule in '/etc/udev/udev.rules' at line 19 applied, 'sda' becomes '%k-flash' Jan 23 15:35:35 pim udev[11799]: creating device node '/udev/sda-flash' Jan 23 15:35:35 pim udev[11800]: creating device node '/udev/sdb' Jan 23 15:35:35 pim udev[11804]: creating device node '/udev/sdc' Jan 23 15:35:35 pim udev[11805]: removing device node '/udev/sda-flash' Jan 23 15:35:35 pim udev[11808]: removing device node '/udev/sdb' Jan 23 15:35:35 pim udev[11809]: removing device node '/udev/sdc' Jan 23 15:35:45 pim udev[11797]: timeout reached, skip events 7 - 7 Jan 23 15:35:45 pim udev[11811]: creating device node '/udev/sdb' Jan 23 15:35:45 pim udev[11812]: creating device node '/udev/sdc' Jan 23 15:36:01 pim udev[11797]: timeout reached, skip events 10 - 14 Jan 23 15:36:01 pim udev[11814]: creating device node '/udev/sdc' Jan 23 15:36:04 pim udev[11816]: creating device node '/udev/sdc' Jan 23 15:36:12 pim udev[11818]: creating device node '/udev/sdc' Jan 23 15:36:16 pim udev[11820]: creating device node '/udev/sdc' Jan 23 15:36:38 pim udev[11797]: timeout reached, skip events 19 - 19 Jan 23 15:36:38 pim udev[11823]: creating device node '/udev/sdc' Jan 23 15:36:38 pim udev[11824]: creating device node '/udev/sdc' Jan 23 15:37:08 pim udev[11797]: we have nothing to do, so daemon exits...
Diffstat (limited to 'udevsend.c')
-rw-r--r--udevsend.c71
1 files changed, 57 insertions, 14 deletions
diff --git a/udevsend.c b/udevsend.c
index 748c8f2217..d3e5378285 100644
--- a/udevsend.c
+++ b/udevsend.c
@@ -29,6 +29,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
+#include <time.h>
+#include <wait.h>
#include "udev.h"
#include "udevd.h"
@@ -78,6 +81,39 @@ static void free_hotplugmsg(struct hotplug_msg *pmsg)
free(pmsg);
}
+static int start_daemon(void)
+{
+ pid_t pid;
+ pid_t child_pid;
+
+ pid = fork();
+ switch (pid) {
+ case 0:
+ /* helper child */
+ child_pid = fork();
+ switch (child_pid) {
+ case 0:
+ /* daemon */
+ execl(DEFAULT_UDEVD_EXEC, NULL);
+ dbg("exec of daemon failed");
+ exit(1);
+ case -1:
+ dbg("fork of daemon failed");
+ return -1;
+ default:
+ exit(0);
+ }
+ break;
+ case -1:
+ dbg("fork of helper failed");
+ return -1;
+ default:
+ wait(0);
+ }
+ return 0;
+}
+
+
int main(int argc, char* argv[])
{
int msgid;
@@ -91,6 +127,8 @@ int main(int argc, char* argv[])
int seq;
int retval = -EINVAL;
int size;
+ int loop;
+ struct timespec tspec;
subsystem = argv[1];
if (subsystem == NULL) {
@@ -118,7 +156,7 @@ int main(int argc, char* argv[])
seq = atoi(seqnum);
/* create ipc message queue or get id of our existing one */
- key = ftok(DEFAULT_EXEC_PROGRAM, IPC_KEY_ID);
+ key = ftok(DEFAULT_UDEVD_EXEC, IPC_KEY_ID);
size = build_hotplugmsg( (struct hotplug_msg**) &pmsg, action, devpath, subsystem, seq);
msgid = msgget(key, IPC_CREAT);
if (msgid == -1) {
@@ -126,15 +164,6 @@ int main(int argc, char* argv[])
goto exit;
}
- /* get state of ipc 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);
-
/* send ipc message to the daemon */
retval = msgsnd(msgid, pmsg, size, 0);
free_hotplugmsg( (struct hotplug_msg*) pmsg);
@@ -142,11 +171,25 @@ int main(int argc, char* argv[])
dbg("error sending ipc message");
goto exit;
}
- return 0;
-exit:
- if (retval > 0)
- retval = 0;
+ /* get state of ipc queue */
+ tspec.tv_sec = 0;
+ tspec.tv_nsec = 10000000; /* 10 millisec */
+ loop = 20;
+ while (loop--) {
+ 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)
+ goto exit;
+ nanosleep(&tspec, NULL);
+ }
+ info("message is still in the ipc queue, starting daemon...");
+ retval = start_daemon();
+
+exit:
return retval;
}