#!/bin/sh DAEMON=dnsmasq DAEMON_LONG_NAME=dnsmasq DAEMON_USER=nobody DAEMON_GROUP=nobody PID_FILE=/var/run/$DAEMON/$DAEMON.pid . /etc/init.d/modlibrc PID_MULTID=$(pidof -s multid) if [ ! -z "$PID_MULTID" ]; then MULTID=$(xargs -0 /mod/etc/$DAEMON.conf echo -n 'Starting dnsmasq...' if [ "$1" != "nomultid" ]; then multid -s > /dev/null 2>&1 fi OPTIONS="--pid-file=$PID_FILE $DNSMASQ_OPTIONS" if [ "$DNSMASQ_DNS_PORT" ]; then OPTIONS="$OPTIONS -p \"$DNSMASQ_DNS_PORT\"" fi eval "$DAEMON $OPTIONS" exitval=$? if [ "$1" != "nomultid" ]; then $MULTID > /dev/null 2>&1 # protect against dnsmasq crash [ -f /var/tmp/avm-resolv.conf -a ! -L /var/tmp/avm-resolv.conf ] && mv /var/tmp/avm-resolv.conf /var/tmp/resolv.conf ln -s resolv.conf /var/tmp/avm-resolv.conf fi if [ ! -L "/var/flash/multid.leases" -a "$DNSMASQ_DHCP" = "yes" ]; then rm -f /var/flash/multid.leases touch /var/tmp/multid.leases ln -s /var/tmp/multid.leases /var/flash/multid.leases fi # this could pose problems when a client comes too fast for lease in /var/tmp/multid.leases /var/tmp/dnsmasq.leases; do if [ -f $lease ]; then chmod 0664 $lease chown root:nobody $lease fi done if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi } stop() { echo -n 'Stopping dnsmasq...' if [ "$1" != "nomultid" ]; then multid -s > /dev/null 2>&1 rm /var/tmp/avm-resolv.conf fi kill $(cat $PID_FILE) 2> /dev/null exitval=$? if [ "$1" != "nomultid" ]; then $MULTID > /dev/null 2>&1 fi rm -f /mod/etc/$DAEMON.conf if [ -L "/var/flash/multid.leases" ]; then major="$(grep tffs /proc/devices)" rm -f /var/flash/multid.leases mknod /var/flash/multid.leases c ${major%%tffs} $((0x70)) fi if [ "$exitval" -eq 0 ]; then echo 'done.' else echo 'failed.' exit $exitval fi } case "$1" in ""|load) modreg cgi 'dnsmasq' 'Dnsmasq' deffile='/mod/etc/default.dnsmasq/dnsmasq_extra.def' [ -r "/tmp/flash/dnsmasq_extra.def" ] && deffile='/tmp/flash/dnsmasq_extra.def' modreg file 'dnsmasq_extra' 'Dnsmasq-Extra' 0 "$deffile" if [ "$DNSMASQ_ENABLED" != "yes" ]; then echo "$DAEMON is disabled" 1>&2 exit 1; fi if modlib_check_running; then echo "$DAEMON already started." else if [ -z "$(pidof multid)" ]; then start nomultid else start fi fi ;; unload) stop modunreg cgi 'dnsmasq' ;; start) start ;; stop) stop ;; restart) stop nomultid sleep 1 start nomultid ;; status) modlib_status ;; *) echo "Usage: $0 [load|unload|start|stop|restart|status]" 1>&2 exit 1 ;; esac exit 0