5 #include <linux/types.h>
6 #include <linux/netlink.h>
10 #include "filemap_utils.h"
12 char *coldplug_command = NULL;
13 char *rules_file = HOTPLUG2_RULE_PATH;
15 + struct pollfd msg_poll;
17 + struct hotplug2_event_t *backlog = NULL;
18 + struct hotplug2_event_t *backlog_tail = NULL;
21 struct rules_t *rules = NULL;
22 struct filemap_t filemap;
24 * Open netlink socket to read the uevents
26 netlink_socket = init_netlink_socket(NETLINK_BIND);
27 + msg_poll.fd = netlink_socket;
28 + msg_poll.events = POLLIN;
30 if (netlink_socket == -1) {
31 ERROR("netlink init","Unable to open netlink socket.");
33 * Main loop reading uevents
37 - * Read the uevent packet
39 - size = recv(netlink_socket, &buffer, sizeof(buffer), 0);
41 + if ((n_backlog > 0) && (child_c < max_child_c)) {
42 + /* dequeue backlog message */
44 + backlog = backlog->next;
46 + if (backlog_tail == tmpevent)
47 + backlog_tail = NULL;
50 + * Read the uevent packet
52 + if (n_backlog >= HOTPLUG2_MSG_BACKLOG) {
53 + usleep(HOTPLUG2_THROTTLE_INTERVAL * 1000);
57 + if ((n_backlog > 0) && (child_c >= max_child_c)) {
59 + msg_poll.revents = 0;
60 + fds = poll(&msg_poll, 1, HOTPLUG2_THROTTLE_INTERVAL);
62 + perror("POLL FAILED");
68 + size = recv(netlink_socket, &buffer, sizeof(buffer), 0);
72 - * Parse the event into an event structure
74 - tmpevent = get_hotplug2_event(buffer, size);
76 + * Parse the event into an event structure
78 + tmpevent = get_hotplug2_event(buffer, size);
80 - if (tmpevent == NULL) {
81 - ERROR("reading events", "Malformed event read (missing action prefix).");
83 + if (tmpevent == NULL) {
84 + ERROR("reading events", "Malformed event read (missing action prefix).");
91 * Unless, of course, we've specified otherwise and no rules that match
94 - if (!flags & FLAG_NOTHROTTLE) {
96 - * Okay, throttle away!
98 - while (child_c >= max_child_c) {
99 - usleep(HOTPLUG2_THROTTLE_INTERVAL);
101 + if (!(flags & FLAG_NOTHROTTLE) && (child_c >= max_child_c)) {
102 + /* log the packet and process it later */
104 + backlog_tail->next = tmpevent;
106 + backlog = tmpevent;
107 + tmpevent->next = NULL;
108 + backlog_tail = tmpevent;
113 sigemptyset(&block_mask);
117 #define DBG(action, fmt, arg...)
120 +#define HOTPLUG2_MSG_BACKLOG 64
121 #define UEVENT_BUFFER_SIZE 2048
122 -#define HOTPLUG2_POLL_INTERVAL 20000
123 -#define HOTPLUG2_THROTTLE_INTERVAL 10000
124 +#define HOTPLUG2_THROTTLE_INTERVAL 50
125 #define HOTPLUG2_RULE_PATH "/etc/hotplug2.rules"
132 + struct hotplug2_event_t *next;