Hmmm.. I've tried to patch ifupdown in order to kill dhclient3 based
on its PID file, but the problem is that dhclient3 will not write its
PID file (at /var/run/) until it times out asking for a lease. That
means that even with some code trying to kill dhclient3 based on its
PID it will be unable to kill it while it is still running trying to
get a lease.
I've tried patching ifupdown as per the attached patch, which tries to
kill the dhclient when the interface is stopped/started. However, as
dhclient3 will not write its pid until it abandons trying to get the
lease there is still a race condition if you run ifdown right when
ifup is still trying to get a lease.
The start-stop-daemon code when upping, however, could take care of
the old dhclient3 process *if* it already abandoned the lease. If both
are still trying to get the IP address you'll end up with two
dhclient3 processes nevertheless. I don't see an easy way around this
short of having something go through the process table and try to find
an old instance of dhclient3 before it has written its pidfile.
BTW, the 'exists' function was temporarily introduced to test for
/var/run/dhclient.%iface%.pid , but I ended up not using it.
I'm just sending in the patch in case it's useful for somebody else,
but it does not fix the issue at hand fully. It only fixes it in this
situation:
1- you run 'ifup XXX'
[ inmediately after, before ifup finishes ]
2- you run 'ifdown XXX' while it is still trying to get a lease (so
the '-r' argument is useless as there is no PID file)
[ at this point there is a dhclient3 process working ]
[ wait some time here... if you wait until it abandons its attempt it
will write its PID file ]
3- you run 'ifup XXXX' again
With the current code you would end up with two dhclient3 processes
after step 3). With the attached patch you end up only with one.
Regards
Javier
diff -Nru ifupdown-0.6.8/archlinux.h ifupdown-0.6.9/archlinux.h
--- ifupdown-0.6.8/archlinux.h 2006-09-28 18:10:27.000000000 +0100
+++ ifupdown-0.6.9/archlinux.h 2007-06-18 12:18:51.000000000 +0100
@@ -2,3 +2,4 @@
unsigned int mylinuxver();
unsigned int mylinux(int,int,int);
int execable(char *);
+int exists(char *);
diff -Nru ifupdown-0.6.8/debian/changelog ifupdown-0.6.9/debian/changelog
--- ifupdown-0.6.8/debian/changelog 2006-09-28 18:08:55.000000000 +0100
+++ ifupdown-0.6.9/debian/changelog 2007-06-18 11:13:59.000000000 +0100
@@ -1,3 +1,9 @@
+ifupdown (0.6.9) unstable; urgency=low
+
+ * Interim fix
+
+ -- jfs <[EMAIL PROTECTED]> Mon, 18 Jun 2007 11:13:55 +0100
+
ifupdown (0.6.8) unstable; urgency=low
* Add myself as co-maintainer with approval from Anthony Towns.
diff -Nru ifupdown-0.6.8/ifupdown.nw ifupdown-0.6.9/ifupdown.nw
--- ifupdown-0.6.8/ifupdown.nw 2006-09-28 18:12:18.000000000 +0100
+++ ifupdown-0.6.9/ifupdown.nw 2007-06-18 12:18:47.000000000 +0100
@@ -3817,6 +3817,7 @@
unsigned int mylinuxver();
unsigned int mylinux(int,int,int);
int execable(char *);
+int exists(char *);
@
<<archlinux.c>>=
@@ -3862,6 +3863,15 @@
}
return 0;
}
+
+int exists(char *file) {
+ struct stat buf;
+
+ if (0 == stat(file, &buf)) {
+ if S_ISREG(buf.st_mode) return 1;
+ }
+ return 1;
+}
@
\subsection{IPv4 Address Family}
@@ -3965,6 +3975,7 @@
up
[[ifconfig %iface% hw %hwaddress%]]
+ start-stop-daemon --stop --oknodo --pidfile /var/run/dhclient.%iface%.pid --exec /sbin/dhclient3;
dhclient3 -pf /var/run/dhclient.%iface%.pid -lf /var/lib/dhcp3/dhclient.%iface%.leases %iface% \
if (execable("/sbin/dhclient3"))
dhclient -e -pf /var/run/dhclient.%iface%.pid -lf /var/lib/dhcp/dhclient.%iface%.leases %iface% \
@@ -3979,7 +3990,8 @@
elsif (execable("/sbin/dhcpcd"))
down
- dhclient3 -r -pf /var/run/dhclient.%iface%.pid -lf /var/lib/dhcp3/dhclient.%iface%.leases %iface% \
+ dhclient3 -r -pf /var/run/dhclient.%iface%.pid -lf /var/lib/dhcp3/dhclient.%iface%.leases %iface% ; \
+ start-stop-daemon --stop --oknodo --pidfile /var/run/dhclient.%iface%.pid --exec /sbin/dhclient3 \
if (execable("/sbin/dhclient3"))
cat /var/run/dhclient.%iface%.pid | xargs -i kill -TERM {} \
elsif (execable("/sbin/dhclient"))
@@ -3990,6 +4002,7 @@
dhcpcd -k %iface% \
elsif (execable("/sbin/dhcpcd"))
+
ifconfig %iface% down
@
diff -Nru ifupdown-0.6.8/inet.defn ifupdown-0.6.9/inet.defn
--- ifupdown-0.6.8/inet.defn 2006-09-28 18:10:29.000000000 +0100
+++ ifupdown-0.6.9/inet.defn 2007-06-18 12:18:52.000000000 +0100
@@ -75,6 +75,7 @@
up
[[ifconfig %iface% hw %hwaddress%]]
+ start-stop-daemon --stop --oknodo --pidfile /var/run/dhclient.%iface%.pid --exec /sbin/dhclient3;
dhclient3 -pf /var/run/dhclient.%iface%.pid -lf /var/lib/dhcp3/dhclient.%iface%.leases %iface% \
if (execable("/sbin/dhclient3"))
dhclient -e -pf /var/run/dhclient.%iface%.pid -lf /var/lib/dhcp/dhclient.%iface%.leases %iface% \
@@ -89,7 +90,8 @@
elsif (execable("/sbin/dhcpcd"))
down
- dhclient3 -r -pf /var/run/dhclient.%iface%.pid -lf /var/lib/dhcp3/dhclient.%iface%.leases %iface% \
+ dhclient3 -r -pf /var/run/dhclient.%iface%.pid -lf /var/lib/dhcp3/dhclient.%iface%.leases %iface% ; \
+ start-stop-daemon --stop --oknodo --pidfile /var/run/dhclient.%iface%.pid --exec /sbin/dhclient3 \
if (execable("/sbin/dhclient3"))
cat /var/run/dhclient.%iface%.pid | xargs -i kill -TERM {} \
elsif (execable("/sbin/dhclient"))
@@ -100,6 +102,7 @@
dhcpcd -k %iface% \
elsif (execable("/sbin/dhcpcd"))
+
ifconfig %iface% down
method bootp
description