[PATCH 2/5] ifupdown: dhcp_down: wait until udhcpc has been killed

Andreas Oberritter obi at opendreambox.org
Mon Apr 22 08:48:38 UTC 2013


Ping.

On 20.03.2013 15:31, Andreas Oberritter wrote:
> * Otherwise there's a race condition between ifdown and udhcpc,
>   which executes deconfig scripts in /etc/udhcpc.d.
> 
> Signed-off-by: Andreas Oberritter <obi at opendreambox.org>
> ---
>  networking/ifupdown.c |   23 +++++++++++++++++------
>  1 file changed, 17 insertions(+), 6 deletions(-)
> 
> diff --git a/networking/ifupdown.c b/networking/ifupdown.c
> index 0f0857c..61c6607 100644
> --- a/networking/ifupdown.c
> +++ b/networking/ifupdown.c
> @@ -612,18 +612,29 @@ static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd, execfn *exec)
>  static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd, execfn *exec)
>  {
>  	int result;
> -	result = execute(
> -		"test -f /var/run/udhcpc.%iface%.pid && "
> -		"kill `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null",
> -		ifd, exec);
> +	char *pidfile_name;
> +	pid_t pid_from_pidfile;
> +
> +	pidfile_name = xasprintf(_PATH_VARRUN "udhcpc.%s.pid", ifd->iface);
> +	pid_from_pidfile = read_pidfile(pidfile_name);
> +	result = (pid_from_pidfile > 0);
>  	/* Also bring the hardware interface down since
>  	   killing the dhcp client alone doesn't do it.
>  	   This enables consecutive ifup->ifdown->ifup */
>  	/* Sleep a bit, otherwise static_down tries to bring down interface too soon,
>  	   and it may come back up because udhcpc is still shutting down */
> -	usleep(100000);
> +	if (result && kill(pid_from_pidfile, SIGTERM) == 0) {
> +		unsigned int i;
> +		for (i = 0; i < 100; i++) {
> +			if (kill(pid_from_pidfile, 0) < 0) {
> +				result++;
> +				break;
> +			}
> +			usleep(100000);
> +		}
> +	}
>  	result += static_down(ifd, exec);
> -	return ((result == 3) ? 3 : 0);
> +	return ((result == 4) ? 4 : 0);
>  }
>  # else
>  static int FAST_FUNC dhcp_down(struct interface_defn_t *ifd UNUSED_PARAM,
> 



More information about the busybox mailing list