dnsmasq: fix remove pidfile on shutdown regression
[openwrt/openwrt.git] / package / network / services / dnsmasq / files / dnsmasq.init
index 3809e6c119ffc714517996ac916323162bb74194..4cd5f673d8b5f1ce9d97241dd01d2e074b62a6f1 100644 (file)
@@ -1,7 +1,7 @@
 #!/bin/sh /etc/rc.common
 # Copyright (C) 2007-2012 OpenWrt.org
 
-START=60
+START=19
 
 USE_PROCD=1
 PROG=/usr/sbin/dnsmasq
@@ -64,6 +64,12 @@ dhcp_check() {
 
        [ -s "$stamp" ] && return $(cat "$stamp")
 
+       # If there's no carrier yet, skip this interface.
+       # The init script will be called again once the link is up
+       case "$(devstatus "$ifname" | jsonfilter -e @.carrier)" in
+               false) return 1;;
+       esac
+
        udhcpc -n -q -s /bin/true -t 1 -i "$ifname" >&- && rv=1 || rv=0
 
        [ $rv -eq 1 ] && \
@@ -113,12 +119,12 @@ append_ipset() {
 }
 
 append_interface() {
-       local ifname=$(uci_get_state network "$1" ifname "$1")
+       network_get_device ifname "$1" || return
        xappend "--interface=$ifname"
 }
 
 append_notinterface() {
-       local ifname=$(uci_get_state network "$1" ifname "$1")
+       network_get_device ifname "$1" || return
        xappend "--except-interface=$ifname"
 }
 
@@ -616,14 +622,18 @@ dhcp_relay_add() {
 service_triggers()
 {
        procd_add_reload_trigger "dhcp"
+       procd_add_raw_trigger "interface.*" 2000 /etc/init.d/dnsmasq reload
 }
 
-boot() {
-       # Will be launched through hotplug
-       return 0
+boot()
+{
+       BOOT=1
+       start "$@"
 }
 
 start_service() {
+       [ -n "$BOOT" ] && return
+
        include /lib/functions
 
        config_load dhcp
@@ -633,6 +643,7 @@ start_service() {
        mkdir -p $(dirname $CONFIGFILE)
        mkdir -p /var/lib/misc
        touch /tmp/dhcp.leases
+       chown dnsmasq:dnsmasq /var/run/dnsmasq
 
        [ -f "$TIMESTAMPFILE" ] && rm -f "$TIMESTAMPFILE"