Bug#509015: ifplugd waits more than the specified delays

2009-03-01 Thread Y Giridhar Appaji Nag
# Bcc: control
tags 509015 + pending
thanks

Hi Michel,

On 08/12/17 05:17 -0800, Michel Lespinasse said ...
 ifplugd should up and down the interface as soon as it detects the cable

[snip...]

 Also, I'm proposing to shorten the polling delay when an action is scheduled
 to happen before the delay expires: for example if we just detected that

[snip...]

 The attached patch implements these two suggestions. I've been running it

Patch committed as r12545 in Debian ifplugd SVN and will be included in
the next upload, thank you.

Cheers,

Giridhar

-- 
Y Giridhar Appaji Nag | http://people.debian.org/~appaji/


signature.asc
Description: Digital signature


Bug#509015: ifplugd waits more than the specified delays

2008-12-17 Thread Michel Lespinasse
Package: ifplugd
Version: 0.28-12
Tags: patch

According to ifplugd's manual, when passed the options -u0 and -d0,
ifplugd should up and down the interface as soon as it detects the cable
was connected or disconnected. For example, if running with options
-t10 -u0 -d0, one would expect the interface to get up or down at any time
within 10 seconds of the cable being connected or disconnected.

However, ifplugd actually defers this for an extra polling cycle - in my
example, any time between 10 and 20 seconds after the cable is (dis)connected.

This is easily fixed by replacing 't  time(NULL)' with 't = time(NULL)'
in the test for the action processing, thus allowing the action to be
processed if the target time t is equal to time(NULL), which is the case
for a newly detected event with -u and -d options equal to 0.


Also, I'm proposing to shorten the polling delay when an action is scheduled
to happen before the delay expires: for example if we just detected that
the cable was unplugged, and we want to down the interface in two seconds,
but the usual polling delay is 10 seconds, we should use a select timeout
of two seconds just for the current polling cycle.


The attached patch implements these two suggestions. I've been running it
with options -M -t300 -u0 -d2. The long poll cycle allows my CPU to go sleep.
The monitoring option allows ifplugd to be notified of plug and unplug events
right when they happen. ifplugd ups the interface right away (within a
quarter of a second) when the cable is connected, and waits two seconds
before downing the interface when the cable is disconnected. Works very
well for me !

-- 
Michel Walken Lespinasse
A program is never fully debugged until the last user dies.
diff -ru ifplugd-0.28.orig/src/ifplugd.c ifplugd-0.28/src/ifplugd.c
--- ifplugd-0.28.orig/src/ifplugd.c	2008-12-17 03:27:34.0 -0800
+++ ifplugd-0.28/src/ifplugd.c	2008-12-17 04:26:00.0 -0800
@@ -468,6 +468,14 @@
 tv.tv_sec = polltime;
 tv.tv_usec = 0;
 
+if (t) {
+int delay = t - time(NULL);
+if (delay  0)
+tv.tv_sec = 0;
+else if (delay  tv.tv_sec)
+tv.tv_sec = delay;
+}
+
 if (select(FD_SETSIZE, qfds, NULL, NULL, tv)  0) {
 if (errno == EINTR)
 continue;
@@ -573,7 +581,7 @@
 }
 }
 
-if (t  t  time(NULL)) {
+if (t  t = time(NULL)) {
 t = 0;
 
 if (action(status)  0)