1 Index: hotplug2-0.9/hotplug2.c
2 ===================================================================
3 --- hotplug2-0.9.orig/hotplug2.c 2008-08-04 10:02:27.000000000 +0200
4 +++ hotplug2-0.9/hotplug2.c 2008-08-04 10:03:04.000000000 +0200
7 #include <linux/types.h>
8 #include <linux/netlink.h>
11 #include "mem_utils.h"
12 #include "filemap_utils.h"
14 char *coldplug_command = NULL;
15 char *rules_file = HOTPLUG2_RULE_PATH;
17 + struct pollfd msg_poll;
19 + struct hotplug2_event_t *backlog = NULL;
20 + struct hotplug2_event_t *backlog_tail = NULL;
23 struct rules_t *rules = NULL;
24 struct filemap_t filemap;
26 * Open netlink socket to read the uevents
28 netlink_socket = init_netlink_socket(NETLINK_BIND);
29 + msg_poll.fd = netlink_socket;
30 + msg_poll.events = POLLIN;
32 if (netlink_socket == -1) {
33 ERROR("netlink init","Unable to open netlink socket.");
35 * Main loop reading uevents
39 - * Read the uevent packet
41 - size = recv(netlink_socket, &buffer, sizeof(buffer), 0);
43 + if ((n_backlog > 0) && (child_c < max_child_c)) {
44 + /* dequeue backlog message */
46 + backlog = backlog->next;
48 + if (backlog_tail == tmpevent)
49 + backlog_tail = NULL;
52 + * Read the uevent packet
54 + if (n_backlog >= HOTPLUG2_MSG_BACKLOG) {
55 + usleep(HOTPLUG2_THROTTLE_INTERVAL * 1000);
59 + if ((n_backlog > 0) && (child_c >= max_child_c)) {
61 + msg_poll.revents = 0;
62 + fds = poll(&msg_poll, 1, HOTPLUG2_THROTTLE_INTERVAL);
69 + size = recv(netlink_socket, &buffer, sizeof(buffer), 0);
73 - * Parse the event into an event structure
75 - tmpevent = get_hotplug2_event(buffer, size);
77 + * Parse the event into an event structure
79 + tmpevent = get_hotplug2_event(buffer, size);
81 - if (tmpevent == NULL) {
82 - ERROR("reading events", "Malformed event read (missing action prefix).");
84 + if (tmpevent == NULL) {
85 + ERROR("reading events", "Malformed event read (missing action prefix).");
92 * Unless, of course, we've specified otherwise and no rules that match
95 - if (!flags & FLAG_NOTHROTTLE) {
97 - * Okay, throttle away!
99 - while (child_c >= max_child_c) {
100 - usleep(HOTPLUG2_THROTTLE_INTERVAL);
102 + if (!(flags & FLAG_NOTHROTTLE) && (child_c >= max_child_c)) {
103 + /* log the packet and process it later */
105 + backlog_tail->next = tmpevent;
107 + backlog = tmpevent;
108 + tmpevent->next = NULL;
109 + backlog_tail = tmpevent;
114 sigemptyset(&block_mask);
115 Index: hotplug2-0.9/hotplug2.h
116 ===================================================================
117 --- hotplug2-0.9.orig/hotplug2.h 2008-08-04 10:02:27.000000000 +0200
118 +++ hotplug2-0.9/hotplug2.h 2008-08-04 10:02:27.000000000 +0200
120 #define DBG(action, fmt, arg...)
123 +#define HOTPLUG2_MSG_BACKLOG 64
124 #define UEVENT_BUFFER_SIZE 2048
125 -#define HOTPLUG2_POLL_INTERVAL 20000
126 -#define HOTPLUG2_THROTTLE_INTERVAL 10000
127 +#define HOTPLUG2_THROTTLE_INTERVAL 50
128 #define HOTPLUG2_RULE_PATH "/etc/hotplug2.rules"
135 + struct hotplug2_event_t *next;