Add --daemon

This commit is contained in:
oblique 2014-12-14 15:57:22 +02:00
parent a1c6c411d3
commit d8c85b460a

View File

@ -45,6 +45,7 @@ usage() {
echo " close create_ap, then use this option to switch your interface" echo " close create_ap, then use this option to switch your interface"
echo " back to managed" echo " back to managed"
echo " --mac <MAC> Set MAC address" echo " --mac <MAC> Set MAC address"
echo " --daemon Run create_ap in the background"
echo " --stop <id> Send stop command to an already running create_ap. For an <id>" echo " --stop <id> Send stop command to an already running create_ap. For an <id>"
echo " you can put the PID of create_ap or the WiFi interface. You can" echo " you can put the PID of create_ap or the WiFi interface. You can"
echo " get them with --list" echo " get them with --list"
@ -71,6 +72,7 @@ usage() {
echo " $(basename $0) -m bridge wlan0 eth0 MyAccessPoint MyPassPhrase" echo " $(basename $0) -m bridge wlan0 eth0 MyAccessPoint MyPassPhrase"
echo " $(basename $0) -m bridge wlan0 br0 MyAccessPoint MyPassPhrase" echo " $(basename $0) -m bridge wlan0 br0 MyAccessPoint MyPassPhrase"
echo " $(basename $0) --driver rtl871xdrv wlan0 eth0 MyAccessPoint MyPassPhrase" echo " $(basename $0) --driver rtl871xdrv wlan0 eth0 MyAccessPoint MyPassPhrase"
echo " $(basename $0) --daemon wlan0 eth0 MyAccessPoint MyPassPhrase"
echo " $(basename $0) --stop wlan0" echo " $(basename $0) --stop wlan0"
} }
@ -412,6 +414,7 @@ FIX_UNMANAGED=0
COUNTRY= COUNTRY=
FREQ_BAND=2.4 FREQ_BAND=2.4
NEW_MACADDR= NEW_MACADDR=
DAEMONIZE=0
LIST_RUNNING=0 LIST_RUNNING=0
STOP_ID= STOP_ID=
@ -431,7 +434,7 @@ cleanup() {
trap "" SIGUSR1 trap "" SIGUSR1
echo echo
echo "Doing cleanup..." echo -n "Doing cleanup.. "
# exiting # exiting
for x in $CONFDIR/*.pid; do for x in $CONFDIR/*.pid; do
@ -509,6 +512,8 @@ cleanup() {
fi fi
networkmanager_rm_unmanaged_if_needed ${WIFI_IFACE} ${OLD_MACADDR} networkmanager_rm_unmanaged_if_needed ${WIFI_IFACE} ${OLD_MACADDR}
fi fi
echo "done"
} }
die() { die() {
@ -556,9 +561,10 @@ send_stop() {
trap "die" SIGINT trap "die" SIGINT
trap "die" SIGUSR1 trap "die" SIGUSR1
ARGS=$(getopt -o hc:w:g:dnm: -l "help","hidden","ieee80211n","ht_capab:","driver:","no-virt","fix-unmanaged","country:","freq-band:","mac:","stop:","list" -n $(basename $0) -- "$@") ARGS=( "$@" )
GETOPT_ARGS=$(getopt -o hc:w:g:dnm: -l "help","hidden","ieee80211n","ht_capab:","driver:","no-virt","fix-unmanaged","country:","freq-band:","mac:","daemon","stop:","list" -n $(basename $0) -- "$@")
[[ $? -ne 0 ]] && exit 1 [[ $? -ne 0 ]] && exit 1
eval set -- "$ARGS" eval set -- "$GETOPT_ARGS"
while :; do while :; do
case "$1" in case "$1" in
@ -635,6 +641,10 @@ while :; do
NEW_MACADDR="$1" NEW_MACADDR="$1"
shift shift
;; ;;
--daemon)
shift
DAEMONIZE=1
;;
--stop) --stop)
shift shift
STOP_ID="$1" STOP_ID="$1"
@ -676,6 +686,18 @@ if [[ $FIX_UNMANAGED -eq 1 ]]; then
exit 0 exit 0
fi fi
if [[ $DAEMONIZE -eq 1 ]]; then
# remove --daemon
NEW_ARGS=( )
for x in "${ARGS[@]}"; do
[[ "$x" != "--daemon" ]] && NEW_ARGS+=( "$x" )
done
# fork()/setsid()/fork()
setsid "$0" "${NEW_ARGS[@]}" &
exit 0
fi
if [[ $FREQ_BAND != 2.4 && $FREQ_BAND != 5 ]]; then if [[ $FREQ_BAND != 2.4 && $FREQ_BAND != 5 ]]; then
echo "ERROR: Invalid frequency band" >&2 echo "ERROR: Invalid frequency band" >&2
exit 1 exit 1