--- p910nd.orig 2011-02-15 08:31:56.000000000 -0500 +++ p910nd 2015-01-28 06:03:29.535579694 -0500 @@ -31,11 +31,17 @@ P910ND_OPTS="" P910ND_NUM="" +P910ND_USERNAME=lp # Read configuration variable file if it is present [ -r /etc/default/$NAME ] && . /etc/default/$NAME +# Fix pidfile name if needed +if [ -n "$P910ND_NUM" ] ; then + PIDFILE=/var/run/p910"$P910ND_NUM"d.pid +fi + DAEMON_ARGS=" $P910ND_OPTS $P910ND_NUM" # Load the VERBOSE setting and other rcS variables @@ -50,14 +56,26 @@ # do_start() { + # Use username with trailing colon for chown if no group is specified + if expr "$P910ND_USERNAME" : ".*:" >/dev/null ; then + CHOWN_USERNAME="$P910ND_USERNAME" + else + CHOWN_USERNAME="$P910ND_USERNAME": + fi + # pidfile must exist since nonroot daemon can't create it + touch "$PIDFILE" + # Make sure lockdir and pidfile are owned/grouped for the daemon + chown "$CHOWN_USERNAME" /var/lock/p910nd "$PIDFILE" + # Return # 0 if daemon has been started # 1 if daemon was already running # 2 if daemon could not be started - start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ + start-stop-daemon --start --quiet --chuid "$P910ND_USERNAME" \ + --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ || return 1 - start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \ - $DAEMON_ARGS \ + start-stop-daemon --start --quiet --chuid "$P910ND_USERNAME" \ + --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS \ || return 2 }