A contrl script puzzled me lots days. Today I finally got a correct version.
#!/bin/bash
#
# sinetrecvctl SI-net receiver damon control script
#
# description: SI-net receiver daemon is SI-net communication proccess.
### Source function library.
if [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
else
. /etc/init.d/functions
fi
SERVER=/usr/local/sbin/sinetrecv
SERVER_NAME=sinetrecv
CHECK_PROG=/usr/local/sbin/sinetrecv_check.sh
CHECK_PROG_NAME=sinetrecv_check.sh
prog="$SERVER"
RETVAL=0
umask 077
start() {
# check the existance of offline file.
if [ ! -f /tmp/online ]; then
echo "sinetrecv: This is off-line mode."
return 0
fi
# make directory for socket path file.
if [ ! -d /tmp/bws ] ; then
mkdir /tmp/bws
fi
if [ ! -d /tmp/bws/socket ] ; then
mkdir /tmp/bws/socket
fi
# check the existance of the lock file.
if [ -f /var/lock/subsys/sinetrecv ]; then
echo "sinetrecv already exists."
else
echo -n $"Starting $prog: "
$prog &
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/sinetrecv
$CHECK_PROG &
fi
return $RETVAL
}
stop() {
echo -n $"Shutting down $CHECK_PROG: "
killall $CHECK_PROG_NAME
RETVAL=$?
echo
#[ $RETVAL -eq 0 ] && rm -f /tmp/sinetrecv_check.lock
rm -f /tmp/sinetrecv_check.lock
echo -n $"Shutting down $prog: "
killall sleep
killall $SERVER_NAME
RETVAL=$?
#echo
#[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sinetrecv
rm -f /var/lock/subsys/sinetrecv
return $RETVAL
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
There is a trap in code.
if(shmid = shmget(GKCMN_COS_BUFFER_KEY, 0, 0666) >= 0){
...
}
The priority of "=" is lower than ">=", so the variable "shmid" get
the result of "shmget(GKCMN_COS_BUFFER_KEY, 0, 0666) >= 0". That is wrong!
So, this cause the following codes error.
#!/bin/bash
#
# sinetrecvctl SI-net receiver damon control script
#
# description: SI-net receiver daemon is SI-net communication proccess.
### Source function library.
if [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
else
. /etc/init.d/functions
fi
SERVER=/usr/local/sbin/sinetrecv
SERVER_NAME=sinetrecv
CHECK_PROG=/usr/local/sbin/sinetrecv_check.sh
CHECK_PROG_NAME=sinetrecv_check.sh
prog="$SERVER"
RETVAL=0
umask 077
start() {
# check the existance of offline file.
if [ ! -f /tmp/online ]; then
echo "sinetrecv: This is off-line mode."
return 0
fi
# make directory for socket path file.
if [ ! -d /tmp/bws ] ; then
mkdir /tmp/bws
fi
if [ ! -d /tmp/bws/socket ] ; then
mkdir /tmp/bws/socket
fi
# check the existance of the lock file.
if [ -f /var/lock/subsys/sinetrecv ]; then
echo "sinetrecv already exists."
else
echo -n $"Starting $prog: "
$prog &
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/sinetrecv
$CHECK_PROG &
fi
return $RETVAL
}
stop() {
echo -n $"Shutting down $CHECK_PROG: "
killall $CHECK_PROG_NAME
RETVAL=$?
echo
#[ $RETVAL -eq 0 ] && rm -f /tmp/sinetrecv_check.lock
rm -f /tmp/sinetrecv_check.lock
echo -n $"Shutting down $prog: "
killall sleep
killall $SERVER_NAME
RETVAL=$?
#echo
#[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sinetrecv
rm -f /var/lock/subsys/sinetrecv
return $RETVAL
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
There is a trap in code.
if(shmid = shmget(GKCMN_COS_BUFFER_KEY, 0, 0666) >= 0){
...
}
The priority of "=" is lower than ">=", so the variable "shmid" get
the result of "shmget(GKCMN_COS_BUFFER_KEY, 0, 0666) >= 0". That is wrong!
So, this cause the following codes error.