From e78f0c24154cd3b331782477cab72a828521f6ae Mon Sep 17 00:00:00 2001 From: hcg Date: Thu, 28 May 2009 13:20:54 +0000 Subject: [hotplug2] Move hotplug2 v0.9 to hotplug2-old git-svn-id: svn://svn.openwrt.org/openwrt/trunk@16135 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/hotplug2-old/patches/120-throttling.patch | 138 ++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 package/hotplug2-old/patches/120-throttling.patch (limited to 'package/hotplug2-old/patches/120-throttling.patch') diff --git a/package/hotplug2-old/patches/120-throttling.patch b/package/hotplug2-old/patches/120-throttling.patch new file mode 100644 index 000000000..bfb7fb075 --- /dev/null +++ b/package/hotplug2-old/patches/120-throttling.patch @@ -0,0 +1,138 @@ +Index: hotplug2-0.9/hotplug2.c +=================================================================== +--- hotplug2-0.9.orig/hotplug2.c 2008-08-04 10:02:27.000000000 +0200 ++++ hotplug2-0.9/hotplug2.c 2008-08-04 10:03:04.000000000 +0200 +@@ -21,6 +21,7 @@ + #include + #include + #include ++#include + + #include "mem_utils.h" + #include "filemap_utils.h" +@@ -492,6 +493,11 @@ + char *coldplug_command = NULL; + char *rules_file = HOTPLUG2_RULE_PATH; + sigset_t block_mask; ++ struct pollfd msg_poll; ++ ++ struct hotplug2_event_t *backlog = NULL; ++ struct hotplug2_event_t *backlog_tail = NULL; ++ int n_backlog = 0; + + struct rules_t *rules = NULL; + struct filemap_t filemap; +@@ -602,6 +608,8 @@ + * Open netlink socket to read the uevents + */ + netlink_socket = init_netlink_socket(NETLINK_BIND); ++ msg_poll.fd = netlink_socket; ++ msg_poll.events = POLLIN; + + if (netlink_socket == -1) { + ERROR("netlink init","Unable to open netlink socket."); +@@ -642,20 +650,44 @@ + * Main loop reading uevents + */ + while (!terminate) { +- /* +- * Read the uevent packet +- */ +- size = recv(netlink_socket, &buffer, sizeof(buffer), 0); +- recv_errno = errno; ++ if ((n_backlog > 0) && (child_c < max_child_c)) { ++ /* dequeue backlog message */ ++ tmpevent = backlog; ++ backlog = backlog->next; ++ n_backlog--; ++ if (backlog_tail == tmpevent) ++ backlog_tail = NULL; ++ } else { ++ /* ++ * Read the uevent packet ++ */ ++ if (n_backlog >= HOTPLUG2_MSG_BACKLOG) { ++ usleep(HOTPLUG2_THROTTLE_INTERVAL * 1000); ++ continue; ++ } ++ ++ if ((n_backlog > 0) && (child_c >= max_child_c)) { ++ int fds; ++ msg_poll.revents = 0; ++ fds = poll(&msg_poll, 1, HOTPLUG2_THROTTLE_INTERVAL); ++ if (fds < 0) { ++ continue; ++ } ++ if (fds == 0) ++ continue; ++ } ++ size = recv(netlink_socket, &buffer, sizeof(buffer), 0); ++ recv_errno = errno; + +- /* +- * Parse the event into an event structure +- */ +- tmpevent = get_hotplug2_event(buffer, size); ++ /* ++ * Parse the event into an event structure ++ */ ++ tmpevent = get_hotplug2_event(buffer, size); + +- if (tmpevent == NULL) { +- ERROR("reading events", "Malformed event read (missing action prefix)."); +- continue; ++ if (tmpevent == NULL) { ++ ERROR("reading events", "Malformed event read (missing action prefix)."); ++ continue; ++ } + } + + /* +@@ -706,13 +738,16 @@ + * Unless, of course, we've specified otherwise and no rules that match + * need throttling. + */ +- if (!flags & FLAG_NOTHROTTLE) { +- /* +- * Okay, throttle away! +- */ +- while (child_c >= max_child_c) { +- usleep(HOTPLUG2_THROTTLE_INTERVAL); +- } ++ if (!(flags & FLAG_NOTHROTTLE) && (child_c >= max_child_c)) { ++ /* log the packet and process it later */ ++ if (backlog_tail) ++ backlog_tail->next = tmpevent; ++ else ++ backlog = tmpevent; ++ tmpevent->next = NULL; ++ backlog_tail = tmpevent; ++ n_backlog++; ++ continue; + } + + sigemptyset(&block_mask); +Index: hotplug2-0.9/hotplug2.h +=================================================================== +--- hotplug2-0.9.orig/hotplug2.h 2008-08-04 10:02:27.000000000 +0200 ++++ hotplug2-0.9/hotplug2.h 2008-08-04 10:02:27.000000000 +0200 +@@ -45,9 +45,9 @@ + #define DBG(action, fmt, arg...) + #endif + ++#define HOTPLUG2_MSG_BACKLOG 64 + #define UEVENT_BUFFER_SIZE 2048 +-#define HOTPLUG2_POLL_INTERVAL 20000 +-#define HOTPLUG2_THROTTLE_INTERVAL 10000 ++#define HOTPLUG2_THROTTLE_INTERVAL 50 + #define HOTPLUG2_RULE_PATH "/etc/hotplug2.rules" + + #define ACTION_ADD 0 +@@ -76,6 +76,7 @@ + int env_vars_c; + char *plain; + int plain_s; ++ struct hotplug2_event_t *next; + }; + + struct options_t { -- cgit v1.2.3