diff options
5 files changed, 167 insertions, 4 deletions
diff --git a/meta-networking/recipes-support/dnsmasq/dnsmasq.inc b/meta-networking/recipes-support/dnsmasq/dnsmasq.inc index 7fec60678..622e63067 100644 --- a/meta-networking/recipes-support/dnsmasq/dnsmasq.inc +++ b/meta-networking/recipes-support/dnsmasq/dnsmasq.inc | |||
@@ -23,6 +23,7 @@ PACKAGECONFIG[dbus] = ",,dbus" | |||
23 | PACKAGECONFIG[idn] = ",,libidn" | 23 | PACKAGECONFIG[idn] = ",,libidn" |
24 | PACKAGECONFIG[conntrack] = ",,libnetfilter-conntrack" | 24 | PACKAGECONFIG[conntrack] = ",,libnetfilter-conntrack" |
25 | PACKAGECONFIG[lua] = ",,lua" | 25 | PACKAGECONFIG[lua] = ",,lua" |
26 | PACKAGECONFIG[resolvconf] = ",,,resolvconf" | ||
26 | EXTRA_OEMAKE = "\ | 27 | EXTRA_OEMAKE = "\ |
27 | 'COPTS=${@base_contains('PACKAGECONFIG', 'dbus', '-DHAVE_DBUS', '', d)} \ | 28 | 'COPTS=${@base_contains('PACKAGECONFIG', 'dbus', '-DHAVE_DBUS', '', d)} \ |
28 | ${@base_contains('PACKAGECONFIG', 'idn', '-DHAVE_IDN', '', d)} \ | 29 | ${@base_contains('PACKAGECONFIG', 'idn', '-DHAVE_IDN', '', d)} \ |
@@ -32,6 +33,8 @@ EXTRA_OEMAKE = "\ | |||
32 | 'LDFLAGS=${LDFLAGS}' \ | 33 | 'LDFLAGS=${LDFLAGS}' \ |
33 | " | 34 | " |
34 | 35 | ||
36 | SRC_URI += "${@bb.utils.contains('PACKAGECONFIG', 'resolvconf', 'file://dnsmasq.resolvconf file://99_dnsmasq', '', d)}" | ||
37 | |||
35 | do_compile_append() { | 38 | do_compile_append() { |
36 | # build dhcp_release | 39 | # build dhcp_release |
37 | cd ${S}/contrib/wrt | 40 | cd ${S}/contrib/wrt |
@@ -56,6 +59,13 @@ do_install () { | |||
56 | install -d ${D}${sysconfdir}/dbus-1/system.d | 59 | install -d ${D}${sysconfdir}/dbus-1/system.d |
57 | install -m 644 dbus/dnsmasq.conf ${D}${sysconfdir}/dbus-1/system.d/ | 60 | install -m 644 dbus/dnsmasq.conf ${D}${sysconfdir}/dbus-1/system.d/ |
58 | fi | 61 | fi |
62 | if [ "${@base_contains('PACKAGECONFIG', 'resolvconf', 'resolvconf', '', d)}" != "" ]; then | ||
63 | install -d ${D}${sysconfdir}/resolvconf/update.d/ | ||
64 | install -m 0755 ${WORKDIR}/dnsmasq.resolvconf ${D}${sysconfdir}/resolvconf/update.d/dnsmasq | ||
65 | |||
66 | install -d ${D}${sysconfdir}/default/volatiles | ||
67 | install -m 0644 ${WORKDIR}/99_dnsmasq ${D}${sysconfdir}/default/volatiles | ||
68 | fi | ||
59 | } | 69 | } |
60 | 70 | ||
61 | CONFFILES_${PN} = "${sysconfdir}/dnsmasq.conf" | 71 | CONFFILES_${PN} = "${sysconfdir}/dnsmasq.conf" |
diff --git a/meta-networking/recipes-support/dnsmasq/files/99_dnsmasq b/meta-networking/recipes-support/dnsmasq/files/99_dnsmasq new file mode 100644 index 000000000..f52ce4e8f --- /dev/null +++ b/meta-networking/recipes-support/dnsmasq/files/99_dnsmasq | |||
@@ -0,0 +1 @@ | |||
d root root 0755 /run/dnsmasq none | |||
diff --git a/meta-networking/recipes-support/dnsmasq/files/dnsmasq.resolvconf b/meta-networking/recipes-support/dnsmasq/files/dnsmasq.resolvconf new file mode 100755 index 000000000..06cd25cec --- /dev/null +++ b/meta-networking/recipes-support/dnsmasq/files/dnsmasq.resolvconf | |||
@@ -0,0 +1,84 @@ | |||
1 | #!/bin/sh | ||
2 | # | ||
3 | # Script to update the resolver list for dnsmasq | ||
4 | # | ||
5 | # N.B. Resolvconf may run us even if dnsmasq is not (yet) running. | ||
6 | # If dnsmasq is installed then we go ahead and update the resolver list | ||
7 | # in case dnsmasq is started later. | ||
8 | # | ||
9 | # Assumption: On entry, PWD contains the resolv.conf-type files. | ||
10 | # | ||
11 | # This file is part of the dnsmasq package. | ||
12 | # | ||
13 | |||
14 | set -e | ||
15 | |||
16 | RUN_DIR="/run/dnsmasq" | ||
17 | RSLVRLIST_FILE="${RUN_DIR}/resolv.conf" | ||
18 | TMP_FILE="${RSLVRLIST_FILE}_new.$$" | ||
19 | MY_NAME_FOR_RESOLVCONF="dnsmasq" | ||
20 | |||
21 | [ -x /usr/bin/dnsmasq ] || exit 0 | ||
22 | [ -x /lib/resolvconf/list-records ] || exit 1 | ||
23 | |||
24 | PATH=/bin:/sbin | ||
25 | |||
26 | report_err() { echo "$0: Error: $*" >&2 ; } | ||
27 | |||
28 | # Stores arguments (minus duplicates) in RSLT, separated by spaces | ||
29 | # Doesn't work properly if an argument itself contains whitespace | ||
30 | uniquify() | ||
31 | { | ||
32 | RSLT="" | ||
33 | while [ "$1" ] ; do | ||
34 | for E in $RSLT ; do | ||
35 | [ "$1" = "$E" ] && { shift ; continue 2 ; } | ||
36 | done | ||
37 | RSLT="${RSLT:+$RSLT }$1" | ||
38 | shift | ||
39 | done | ||
40 | } | ||
41 | |||
42 | if [ ! -d "$RUN_DIR" ] && ! mkdir --parents --mode=0755 "$RUN_DIR" ; then | ||
43 | report_err "Failed trying to create directory $RUN_DIR" | ||
44 | exit 1 | ||
45 | fi | ||
46 | |||
47 | RSLVCNFFILES="" | ||
48 | for F in $(/lib/resolvconf/list-records --after "lo.$MY_NAME_FOR_RESOLVCONF") ; do | ||
49 | case "$F" in | ||
50 | "lo.$MY_NAME_FOR_RESOLVCONF") | ||
51 | # Omit own record | ||
52 | ;; | ||
53 | lo.*) | ||
54 | # Include no more records after one for a local nameserver | ||
55 | RSLVCNFFILES="${RSLVCNFFILES:+$RSLVCNFFILES }$F" | ||
56 | break | ||
57 | ;; | ||
58 | *) | ||
59 | RSLVCNFFILES="${RSLVCNFFILES:+$RSLVCNFFILES }$F" | ||
60 | ;; | ||
61 | esac | ||
62 | done | ||
63 | |||
64 | NMSRVRS="" | ||
65 | if [ "$RSLVCNFFILES" ] ; then | ||
66 | uniquify $(sed -n -e 's/^[[:space:]]*nameserver[[:space:]]\+//p' $RSLVCNFFILES) | ||
67 | NMSRVRS="$RSLT" | ||
68 | fi | ||
69 | |||
70 | # Dnsmasq uses the mtime of $RSLVRLIST_FILE, with a resolution of one second, | ||
71 | # to detect changes in the file. This means that if a resolvconf update occurs | ||
72 | # within one second of the previous one then dnsmasq may fail to notice the | ||
73 | # more recent change. To work around this problem we sleep one second here | ||
74 | # if necessary in order to ensure that the new mtime is different. | ||
75 | if [ -f "$RSLVRLIST_FILE" ] && [ "$(stat -c %X "$RSLVRLIST_FILE")" = "$(date +%s)" ] ; then | ||
76 | sleep 1 | ||
77 | fi | ||
78 | |||
79 | clean_up() { rm -f "$TMP_FILE" ; } | ||
80 | trap clean_up EXIT | ||
81 | : >| "$TMP_FILE" | ||
82 | for N in $NMSRVRS ; do echo "nameserver $N" >> "$TMP_FILE" ; done | ||
83 | mv -f "$TMP_FILE" "$RSLVRLIST_FILE" | ||
84 | |||
diff --git a/meta-networking/recipes-support/dnsmasq/files/dnsmasq.service b/meta-networking/recipes-support/dnsmasq/files/dnsmasq.service index 549e15e2b..c3637e142 100644 --- a/meta-networking/recipes-support/dnsmasq/files/dnsmasq.service +++ b/meta-networking/recipes-support/dnsmasq/files/dnsmasq.service | |||
@@ -5,8 +5,11 @@ After=network.target | |||
5 | [Service] | 5 | [Service] |
6 | Type=forking | 6 | Type=forking |
7 | PIDFile=/run/dnsmasq.pid | 7 | PIDFile=/run/dnsmasq.pid |
8 | ExecStart=/usr/bin/dnsmasq -x /run/dnsmasq.pid | 8 | ExecStartPre=/usr/sbin/dnsmasq --test |
9 | ExecReload=/bin/kill -HUP $(/bin/cat /run/dnsmasq.pid) | 9 | ExecStart=/etc/init.d/dnsmasq systemd-exec |
10 | ExecStartPost=/etc/init.d/dnsmasq systemd-start-resolvconf | ||
11 | ExecStopPre=/etc/init.d/dnsmasq systemd-stop-resolvconf | ||
12 | ExecReload=/bin/kill -HUP $MAINPID | ||
10 | 13 | ||
11 | [Install] | 14 | [Install] |
12 | WantedBy=multi-user.target | 15 | WantedBy=multi-user.target |
diff --git a/meta-networking/recipes-support/dnsmasq/files/init b/meta-networking/recipes-support/dnsmasq/files/init index d1aa9e517..51c95dfed 100644 --- a/meta-networking/recipes-support/dnsmasq/files/init +++ b/meta-networking/recipes-support/dnsmasq/files/init | |||
@@ -8,15 +8,68 @@ test -f $DAEMON || exit 0 | |||
8 | 8 | ||
9 | set -e | 9 | set -e |
10 | 10 | ||
11 | if [ -r /etc/default/$NAME ] | ||
12 | then | ||
13 | . /etc/default/$NAME | ||
14 | fi | ||
15 | |||
16 | DNSMASQ_CONF="/etc/dnsmasq.conf" | ||
17 | test "/etc/dnsmasq.d/*" != '/etc/dnsmasq.d/*' && DNSMASQ_CONF="${DNSMASQ_CONF} /etc/dnsmasq.d/*" | ||
18 | |||
19 | test -z "${PIDFILE}" && PIFILE="/run/dnsmasq.pid" | ||
20 | |||
21 | if [ -z "$IGNORE_RESOLVCONF" ] | ||
22 | then | ||
23 | egrep -h -q '^no-resolv' ${DNSMASQ_CONF} && IGNORE_RESOLVCONF="yes" | ||
24 | fi | ||
25 | |||
26 | # RESOLV_CONF: | ||
27 | # If the resolvconf package is installed then use the resolv conf file | ||
28 | # that it provides as the default. Otherwise use /etc/resolv.conf as | ||
29 | # the default. | ||
30 | # | ||
31 | # If IGNORE_RESOLVCONF is set in /etc/default/dnsmasq or an explicit | ||
32 | # filename is set there then this inhibits the use of the resolvconf-provided | ||
33 | # information. | ||
34 | # | ||
35 | # Note that if the resolvconf package is installed it is not possible to | ||
36 | # override it just by configuration in /etc/dnsmasq.conf, it is necessary | ||
37 | # to set IGNORE_RESOLVCONF=yes in /etc/default/dnsmasq. | ||
38 | |||
39 | test -z "$RESOLV_CONF" -a "$IGNORE_RESOLVCONF" != "yes" -a -x /sbin/resolvconf && \ | ||
40 | RESOLV_CONF=/run/dnsmasq/resolv.conf | ||
41 | |||
42 | start_resolvconf() | ||
43 | { | ||
44 | if [ "$IGNORE_RESOLVCONF" != "yes" -a -x /sbin/resolvconf ] | ||
45 | then | ||
46 | echo "nameserver 127.0.0.1" | /sbin/resolvconf -a lo.$NAME | ||
47 | fi | ||
48 | : | ||
49 | } | ||
50 | |||
51 | stop_resolvconf() | ||
52 | { | ||
53 | if [ "$IGNORE_RESOLVCONF" != "yes" -a -x /sbin/resolvconf ] | ||
54 | then | ||
55 | /sbin/resolvconf -d lo.$NAME | ||
56 | fi | ||
57 | : | ||
58 | } | ||
59 | |||
11 | case "$1" in | 60 | case "$1" in |
12 | start) | 61 | start) |
13 | echo -n "starting $DESC: $NAME... " | 62 | echo -n "starting $DESC: $NAME... " |
14 | test -d /var/lib/misc/ || mkdir /var/lib/misc/ | 63 | test -d /var/lib/misc/ || mkdir /var/lib/misc/ |
15 | start-stop-daemon -S -x $DAEMON -- $ARGS | 64 | start-stop-daemon -S -x $DAEMON -- $ARGS \ |
65 | ${RESOLV_CONF:+ -r $RESOLV_CONF} \ | ||
66 | ${PIDFILE:+ -x $PIDFILE} | ||
67 | test $? -eq 0 && start_resolvconf | ||
16 | echo "done." | 68 | echo "done." |
17 | ;; | 69 | ;; |
18 | stop) | 70 | stop) |
19 | echo -n "stopping $DESC: $NAME... " | 71 | echo -n "stopping $DESC: $NAME... " |
72 | stop_resolvconf | ||
20 | start-stop-daemon -K -x $DAEMON | 73 | start-stop-daemon -K -x $DAEMON |
21 | echo "done." | 74 | echo "done." |
22 | ;; | 75 | ;; |
@@ -25,7 +78,7 @@ case "$1" in | |||
25 | start-stop-daemon -q -K -t -x $DAEMON | 78 | start-stop-daemon -q -K -t -x $DAEMON |
26 | RET=$? | 79 | RET=$? |
27 | if [ "$RET" = "0" ]; then | 80 | if [ "$RET" = "0" ]; then |
28 | PID=`cat /var/run/dnsmasq.pid` | 81 | PID=`cat ${PIDFILE}` |
29 | echo "($PID) is running" | 82 | echo "($PID) is running" |
30 | else | 83 | else |
31 | echo "is not running" | 84 | echo "is not running" |
@@ -43,6 +96,18 @@ case "$1" in | |||
43 | killall -HUP $(basename ${DAEMON}) | 96 | killall -HUP $(basename ${DAEMON}) |
44 | echo "done." | 97 | echo "done." |
45 | ;; | 98 | ;; |
99 | systemd-start-resolvconf) | ||
100 | start_resolvconf | ||
101 | ;; | ||
102 | systemd-stop-resolvconf) | ||
103 | stop_resolvconf | ||
104 | ;; | ||
105 | systemd-exec) | ||
106 | test -d /var/lib/misc/ || mkdir /var/lib/misc/ | ||
107 | exec $DAEMON --keep-in-foreground $ARGS \ | ||
108 | ${RESOLV_CONF:+ -r $RESOLV_CONF} \ | ||
109 | ${PIDFILE:+ -x $PIDFILE} | ||
110 | ;; | ||
46 | *) | 111 | *) |
47 | echo "Usage: $0 {start|stop|status|restart|reload}" | 112 | echo "Usage: $0 {start|stop|status|restart|reload}" |
48 | exit 1 | 113 | exit 1 |