#!/bin/sh
# Script to start dctrl, the diald control window.
#
# Copyright (c) 1997 The Meme Factory, Inc.  http://www.meme.com
#
# This code is distributed under the GNU copyright.

CFG_PATH="/etc/sysconfig/network-scripts/dialdcfg-"

function start {

local iface=$1

if [ ! -f ${CFG_PATH}${iface} ] ; then
  echo "${iface}: no diald config for such interface" >&2
  exit 1
fi

. /etc/sysconfig/dialdcfg
. ${CFG_PATH}${iface}

if [ -z "${FIFO}" ] ; then
  echo "dtrl requires a fifo"
  logger -t dctrl -p daemon.info "no fifo specified, cannot start"
  exit 1
fi

DCTRL_OPTIONS=""

if [ "${ICONIFY_DCTRL}" = "yes" ] ; then
  DCTRL_OPTIONS="-iconic"
fi

if [ "${ANIMATE_DCTRL}" = "yes" ] ; then
  DCTRL_OPTIONS="$DCTRL_OPTIONS -i"
fi

if [ "${DLOG_DCTRL}" = "yes" ] ; then
  DCTRL_OPTIONS="$DCTRL_OPTIONS -dlog"
fi

if [ "${PQUEUE_DCTRL}" = "yes" ] ; then
  DCTRL_OPTIONS="$DCTRL_OPTIONS -pqueue"
fi

if [ "${TLOAD_DCTRL}" = "yes" ] ; then
  DCTRL_OPTIONS="$DCTRL_OPTIONS -tload"
fi

if [ "${GLOAD_DCTRL}" = "yes" ] ; then
  DCTRL_OPTIONS="$DCTRL_OPTIONS -gload"
fi

nohup dctrl -fifo ${FIFO} $DCTRL_OPTIONS >/dev/null &

# echo $! > /var/run/dctrl-${iface}.pid

}

. /etc/sysconfig/dialdcfg

result=0

if [ -n "$1" ] ; then
   # The user wants to control a specific interface(s).
   for IFACE in "$@" ; do
     start ${IFACE}
     [ $? ] || result=1
   done
else
   # Start dctrl for all the interfaces.
   for IFACE in $(find "$(dirname ${CFG_PATH})" -maxdepth 1 -name $(basename ${CFG_PATH})\* \
                  | sed "s\\^${CFG_PATH}\\\\") ; do
     start ${IFACE}
     [ $? ] || result=1
   done
fi

 exit ${result}
