Merge lp:~smoser/ubuntu/oneiric/ifupdown/lp838968 into lp:ubuntu/oneiric/ifupdown

Proposed by Scott Moser
Status: Merged
Merged at revision: 56
Proposed branch: lp:~smoser/ubuntu/oneiric/ifupdown/lp838968
Merge into: lp:ubuntu/oneiric/ifupdown
Diff against target: 86 lines (+27/-14)
3 files modified
debian/changelog (+12/-0)
debian/ifupdown.upstart.if-up (+14/-13)
ifupdown.nw (+1/-1)
To merge this branch: bzr merge lp:~smoser/ubuntu/oneiric/ifupdown/lp838968
Reviewer Review Type Date Requested Status
Steve Langasek Approve
Ubuntu branches Pending
Review via email: mp+73741@code.launchpad.net

Description of the change

  * invoke dhclient3 with '-1', meaning it should exit failure if it does
    not receive a response in 60 seconds. (LP: #838968)
  * fix the broken static-network-up-emitted event. This now keeps
    state of which interfaces have been brought up by marker files
    in /run/network named ifup.IFACE and a directory named
    static-network-up-emitted indicating static-network-up has been
    emitted.

To post a comment you must log in.
Revision history for this message
Steve Langasek (vorlon) wrote :

I don't think the changes to the interface of the all_interfaces_up() and get_auto_interfaces() functions are an improvement. Why move the interface list to an argument to all_interfaces_up? Why returning the interface list from get_auto_interfaces() in a global variable instead of on stdout? Neither of these changes are necessary for fixing the bug, and I think they both make the code harder to read.

+# touch our own "marker" indicating that this interface has been brought up.
+date > "${MARK_DEV_PREFIX}$IFACE"
+

Makes sense to avoid use of touch, which is in /usr/bin; but we don't exactly need the datestamp. Better to use :> "${MARK_DEV_PREFIX}$IFACE" and avoid a needless fork.

+ # if no interfaces were passed in, then "all [given] were up"
+ [ $# -eq 0 ] && return 0

Redundant check. If $# -eq 0, the for loop immediately below is a no-op and you'll get the return 0 anyway; so better to leave this out.

+mkdir -p "${MARK_DEV_PREFIX%/*}" "${MARK_STATIC_NETWORK_EMITTED%/*}"

This call is always unnecessary. The /run/network directory will always be created for us by ifupdown, and both of these variables should always point at /run/network. Please drop this.

review: Needs Fixing
Revision history for this message
Scott Moser (smoser) wrote :

On Fri, 2 Sep 2011, Steve Langasek wrote:

> Review: Needs Fixing
> I don't think the changes to the interface of the all_interfaces_up()
> and get_auto_interfaces() functions are an improvement.
> Why move the interface list to an argument to all_interfaces_up?

I thought it made the function stand on its own a little better. It was
then easier to test for an arbitrary list of inputs (ie, adding eth9 to
the params should get me a "no").

It also means that all_interfaces_up has almost no chance of returning
failure due to something else failing. Ie, if it does the call to
'get_auto_interfaces' and *that* returns false, what should it return ?

> Why returning the interface list from get_auto_interfaces() in a global
> variable instead of on stdout?

It saves a fork.

> Neither of these changes are necessary for fixing the
> bug, and I think they both make the code harder to read.

I wrote the original, and I felt these were improvements.

> +# touch our own "marker" indicating that this interface has been brought up.
> +date > "${MARK_DEV_PREFIX}$IFACE"
> +
>
> Makes sense to avoid use of touch, which is in /usr/bin; but we don't
> exactly need the datestamp. Better to use :> "${MARK_DEV_PREFIX}$IFACE"
> and avoid a needless fork.

I'm willing to save the fork there. I found the date stamp nice to look
at when debugging.

> + # if no interfaces were passed in, then "all [given] were up"
> + [ $# -eq 0 ] && return 0
>
> Redundant check. If $# -eq 0, the for loop immediately below is a no-op
> and you'll get the return 0 anyway; so better to leave this out.

I knew it was redundant, but I wanted to make that obvious to someone
looking at the code. surely '[ $# -eq 0 ]' is abount as fast as anything
can be in shell.

> +mkdir -p "${MARK_DEV_PREFIX%/*}" "${MARK_STATIC_NETWORK_EMITTED%/*}"
> This call is always unnecessary. The /run/network directory will always
> be created for us by ifupdown, and both of these variables should always
> point at /run/network. Please drop this.

I wanted to ensure that if someone changed the value of
MARK_STATIC_NETWORK_EMITTED from a subdir of '/var/run/' (say, to
'/var/run/network/event-locks' or something) that this would be the only
change needed. After that, adding the mkdir of MARK_DEV_PREFIX comes at
really no cost.

I'm willing to save the fork.

64. By Scott Moser

address slangasek's objections to code restructuring.

 * remove the 'mkdir', parent dir must now exist.
   (it will in the case of /run/network)
 * do not use global _RET, but write list of interfaces
   to stdout in get_auto_interfaces.

Revision history for this message
Steve Langasek (vorlon) wrote :

Looks good to me now. Thanks for your patience :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2011-08-22 10:30:48 +0000
3+++ debian/changelog 2011-09-02 19:24:24 +0000
4@@ -1,3 +1,15 @@
5+ifupdown (0.7~alpha5.1ubuntu4) UNRELEASED; urgency=low
6+
7+ * invoke dhclient3 with '-1', meaning it should exit failure if it does
8+ not receive a response in 60 seconds. (LP: #838968)
9+ * fix the broken static-network-up-emitted event. This now keeps
10+ state of which interfaces have been brought up by marker files
11+ in /run/network named ifup.IFACE and a directory named
12+ static-network-up-emitted indicating static-network-up has been
13+ emitted.
14+
15+ -- Scott Moser <smoser@ubuntu.com> Thu, 01 Sep 2011 19:55:55 -0400
16+
17 ifupdown (0.7~alpha5.1ubuntu3) oneiric; urgency=low
18
19 * Document what events are emitted properly. (LP: #819928)
20
21=== modified file 'debian/ifupdown.upstart.if-up'
22--- debian/ifupdown.upstart.if-up 2011-08-10 17:01:24 +0000
23+++ debian/ifupdown.upstart.if-up 2011-09-02 19:24:24 +0000
24@@ -1,4 +1,6 @@
25 #!/bin/sh
26+MARK_DEV_PREFIX="/run/network/ifup."
27+MARK_STATIC_NETWORK_EMITTED="/run/network/static-network-up-emitted"
28
29 set -e
30
31@@ -13,6 +15,7 @@
32
33 get_auto_interfaces() {
34 # write to stdout a list of interfaces configured for 'auto'
35+ # in /etc/network/interfaces
36 local line="" found=" " iface
37 while read line; do
38 set -- ${line%%#*}
39@@ -25,23 +28,21 @@
40 echo "$@"
41 }
42
43-all_interfaces_up () {
44- local uplist="" up="" iface="" oifs="$IFS" phys virt
45- if [ -f /var/run/network/ifstate ] ; then
46- IFS="="
47- while read phys virt; do
48- uplist="${uplist}|${phys}"
49- done < /var/run/network/ifstate
50- IFS="$oifs"
51- fi
52- uplist="|${uplist#|}|"
53- # Check to see if all auto interfaces are up now
54+all_interfaces_up() {
55+ # return true if all interfaces listed in /etc/network/interfaces as 'auto'
56+ # are up. if no interfaces are found there, then "all [given] were up"
57+ local prefix="$1" iface=""
58 for iface in $(get_auto_interfaces); do
59- [ "${uplist#*|${iface}|}" != "${uplist}" ] || return 1
60+ # if cur interface does is not up, then all have not been brought up
61+ [ -f "${prefix}${iface}" ] || return 1
62 done
63 return 0
64 }
65
66-if all_interfaces_up && mkdir /var/run/network/static-network-up-emitted 2>/dev/null; then
67+# touch our own "marker" indicating that this interface has been brought up.
68+: > "${MARK_DEV_PREFIX}$IFACE"
69+
70+if all_interfaces_up "${MARK_DEV_PREFIX}" &&
71+ mkdir "${MARK_STATIC_NETWORK_EMITTED}" 2>/dev/null; then
72 initctl emit --no-wait static-network-up
73 fi
74
75=== modified file 'ifupdown.nw'
76--- ifupdown.nw 2011-08-09 14:41:00 +0000
77+++ ifupdown.nw 2011-09-02 19:24:24 +0000
78@@ -4423,7 +4423,7 @@
79
80 up
81 [[ip link set dev %iface% address %hwaddress%]]
82- dhclient3 [[-e IF_METRIC=%metric%]] -pf /var/run/dhclient.%iface%.pid -lf /var/lib/dhcp3/dhclient.%iface%.leases %iface% \
83+ dhclient3 [[-e IF_METRIC=%metric%]] -pf /var/run/dhclient.%iface%.pid -lf /var/lib/dhcp3/dhclient.%iface%.leases -1 %iface% \
84 if (execable("/sbin/dhclient3"))
85 dhclient [[-e IF_METRIC=%metric%]] -v -pf /var/run/dhclient.%iface%.pid -lf /var/lib/dhcp/dhclient.%iface%.leases %iface% \
86 elsif (execable("/sbin/dhclient"))

Subscribers

People subscribed via source and target branches

to all changes: