1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-11-21 00:25:50 +00:00

Overhaul of rc script which was non-functional

Most notable change is the renaming of $samplicator_user to
$samplicator_runas. The reasoning is that the usage of daemon(8) and
$name_user does not mix well; it resulted in the following:

_doit='su -m $name_user -c '\''sh -c "/usr/sbin/daemon -u $name_user ..."

This defeats the purpose of daemon which has to be launched as root.

Sponsored by:	SupraNet Communications, Inc
This commit is contained in:
Mark Felder 2014-05-19 13:04:08 +00:00
parent 9b8fa99c53
commit 49748d6df2
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=354537
2 changed files with 24 additions and 27 deletions

View File

@ -2,7 +2,7 @@
PORTNAME= samplicator
PORTVERSION= 1.3.7.b6
PORTREVISION= 1
PORTREVISION= 2
CATEGORIES= net
MASTER_SITES= ${MASTER_SITE_GOOGLE_CODE}
MASTER_SITE_SUBDIR= samplicator

View File

@ -11,13 +11,13 @@
# samplicator_enable="YES"
# # optional
# samplicator_flags="-S -p 2055 -c %%PREFIX%%/etc/samplicator.conf"
# samplicator_user="nobody"
# samplicator_runas="nobody"
#
# The default is to run samplicator as nobody, which will prevent you from
# using the -S flag (maintain (spoof) source addresses).
# If you want to maintain (spoof) source addresses, you will need to run as
# root.
# This can be accomplished by adding samplicator_user="root" to /etc/rc.conf
# This can be accomplished by adding samplicator_runas="root" to /etc/rc.conf
. /etc/rc.subr
@ -26,45 +26,42 @@ rcvar=samplicator_enable
load_rc_config $name
# Set defaults
samplicator_enable=${samplicator_enable:-"NO"}
samplicator_flags=${samplicator_flags:-"-p 2055 -c %%PREFIX%%/etc/samplicator.conf"}
samplicator_user=${samplicator_user:-"nobody"}
: ${samplicator_enable:=NO}
: ${samplicator_flags="-p 2055 -c %%PREFIX%%/etc/samplicator.conf"}
: ${samplicator_runas:=nobody}
pidfile=/var/run/samplicator.pid
command=%%PREFIX%%/bin/samplicate
procname="%%PREFIX%%/bin/samplicate"
command=/usr/sbin/daemon
command_args=" -cf -p ${pidfile} -u ${samplicator_runas} ${procname} ${samplicator_flags}"
required_files=%%PREFIX%%/etc/samplicator.conf
start_precmd=samplicator_precmd
start_cmd=samplicator_start
stop_postcmd=samplicator_cleanup
stop_postcmd="[ -f ${pidfile} ] && rm ${pidfile}"
samplicator_precmd()
{
# since we are using daemon(1) to drop privs, we cannot let samplicator fork
%%ECHO%% "${samplicator_flags}" | %%EGREP%% -q "(^\-f| \-f)" 2>&1 > /dev/null
# bypass rc_flags as we use samplicator_flags directly via daemon(8)
rc_flags=""
# create empty pidfile with correct permissions
install -o ${samplicator_runas} /dev/null ${pidfile}
# since we are using daemon(8) to drop privs, we cannot let samplicator fork
echo "${samplicator_flags}" | egrep -q "(^\-f| \-f)"
if [ $? -eq 0 ]; then
%%ECHO%% "Please remove parameter -f from samplicator_flags"
%%ECHO%%
echo "Please remove parameter -f from samplicator_flags"
echo
return 1
fi
# root is required for -S, do a pre-launch sanity check
%%ECHO%% "${samplicator_flags}" | %%EGREP%% -q "(^\-S| \-S)" 2>&1 > /dev/null
if [ $? -eq 0 && ${samplicator_user} -ne "root" ]; then
%%ECHO%% "-S requires that samplicator_user be set to root."
%%ECHO%%
echo "${samplicator_flags}" | egrep -q "(^\-S| \-S)"
if [ $? -eq 0 ] && [ $(id -u ${samplicator_runas}) -ne 0 ]; then
echo "-S requires that samplicator_runas be set to root."
echo
return 1
fi
}
samplicator_start() {
echo "Starting samplicator."
%%TOUCH%% ${pidfile} && %%CHOWN%% ${samplicator_user} ${pidfile}
/usr/sbin/daemon -cf -p ${pidfile} -u ${samplicator_user} ${command} ${samplicator_flags}
}
samplicator_cleanup() {
[ -f ${pidfile} ] && %%RM%% ${pidfile}
}
run_rc_command "$1"