Modify

Opened 10 years ago

Closed 10 years ago

#462 closed defect (fixed)

problem in dhcp part of do_ifup in functions.sh

Reported by: thilo.bangert@… Owned by: developers
Priority: low Milestone: 0.9/rc6
Component: base system Version:
Keywords: Cc:

Description

while debugging a dhcp problem i ran into this part in the logfile (logread):

Jan  1 00:00:11 (none) user.info : cat: /var/run/vlan1.pid: No such file or directory
Jan  1 00:00:11 (none) user.info : info, udhcpc (v0.9.9-pre) started
Jan  1 00:00:11 (none) kern.debug kernel: vlan1: add 01:00:5e:00:00:01 mcast address to master interface
Jan  1 00:00:11 (none) user.info : debug, Sending discover...
Jan  1 00:00:12 (none) user.info : kill: 1: Usage: kill [-s sigspec | -signum | -sigspec] [pid | job]... or
Jan  1 00:00:12 (none) user.info : kill -l [exitstatus]
Jan  1 00:00:13 (none) user.info : debug, Sending discover...
Jan  1 00:00:15 (none) user.info : debug, Sending discover...
Jan  1 00:00:19 (none) user.info : info, No lease, forking to background.

the code producing this output is guessed to be the following snippet from the dhcp part of the do_ifup function in /etc/functions.sh

oldpid=$(cat $pidfile)
${DEBUG:-eval} "udhcpc $DHCP_ARGS"
pidof udhcpc | grep "$oldpid" >&- 2>&- && {
  sleep 1
  kill -9 $oldpid
}

it seems to me, the purpose of this code is to kill old instances of udhcpc, but only after the new instance is already running. (unfortunately it is unclear to me, why this is done after starting the new instance... especially since the original instance already has been killed once (in the beginning of do_ifup()))

i suggest the following (which may or may not be an improvement)

[ -f $pidfile ] && oldpid=$(cat $pidfile)
${DEBUG:-eval} "udhcpc $DHCP_ARGS"
[ ${oldpid:-0} != 0 ] && pidof udhcpc | grep "$oldpid" >/dev/null && {
  sleep 1
  kill -9 $oldpid
}

this is to

  • make sure the pidfile is only accessed if it exists
  • only check for the old instance if the pidfile exists
  • not change the exit value because of closed file descriptors (see also the following observation)
bangert@marsupilami ~ $ pidof udhcpd
20157
bangert@marsupilami ~ $ echo $?
0
bangert@marsupilami ~ $ pidof udhcpd | grep 20157
20157
bangert@marsupilami ~ $ echo $?
0
bangert@marsupilami ~ $ pidof udhcpd | grep 20157 >&- 2>&-
bangert@marsupilami ~ $ echo $?
1
bangert@marsupilami ~ $ pidof udhcpd | grep 20157 >/dev/null
bangert@marsupilami ~ $ echo $?
0

i have this running on my router here...

Attachments (0)

Change History (1)

comment:1 Changed 10 years ago by nico

  • Resolution set to fixed
  • Status changed from new to closed

Spurious error messages were fixed in [3503], however, I can't reproduce the behaviour you observed with closed file descriptors.

Add Comment

Modify Ticket

Action
as closed .
The resolution will be deleted. Next status will be 'reopened'.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.