This file is indexed.

/etc/init.d/gapd is in gap-scscp 2.1.4+ds-3.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#! /bin/sh
### BEGIN INIT INFO
# Provides:          gapd
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: GAP SCSCP server
# Description:       SCSCP server for the GAP Computer Algebraic System
### END INIT INFO

#
# Author: Jerome Benoit <calculus@rezozer.net>
#

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="GAP SCSCP server"
NAME=gapd
REALNAME=gap
DAEMON=/usr/sbin/gapd
DAEMONUSER=_gapd
DAEMONARGS="-t log"
RUNDIR=/var/run/gapd
LOCKFILE=$RUNDIR/gapd.lock
PIDFILE=$RUNDIR/gapd.pid
WKSFILE=$RUNDIR/gapd.wks
LOGDIR=/var/log/gapd
LOGFILE=$LOGDIR/gapd.log
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Exit if the DAEMONUSER does not exist
if ! getent passwd | grep -q "^$DAEMONUSER:"; then exit 0 ; fi

# Cleanup enviroment
unset TMPDIR TMP TEMPDIR TEMP LANG LANGUAGE

# Reset TMPDIR
export TMPDIR=$(su -l $DAEMONUSER -c 'printenv TMPDIR')
[ "$TMPDIR" ] || unset TMPDIR

# Read configuration variable file if it is present
GAPD_OPTIONS=""
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
DAEMONARGS="$DAEMONARGS $GAPD_OPTIONS"

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
. /lib/lsb/init-functions

# START_GAPD meant to be set up in /etc/default/$NAME
case "$START_GAPD" in
  NO|no)
    START_GAPD=NO
  ;;
  *)
    START_GAPD=YES
  ;;
esac

daemon_mkdir()
{
	local dmod=$1
	local ddir=$2
	mkdir --parents $ddir
	chmod $dmod $ddir
	chown $DAEMONUSER $ddir
	chgrp $DAEMONUSER $ddir
}

daemon_touch_log()
{
	touch $LOGFILE
	chmod 0640 $LOGFILE
	chown $DAEMONUSER $LOGFILE
	chgrp $DAEMONUSER $LOGFILE
}

do_start()
{
	# Return
	#   0 if daemon has been started
	#   1 if daemon was already running
	#   2 if daemon could not be started
	#   4 if daemon is disabled

	[ "$START_GAPD" = "NO"  ] && return 4

	local counter=60
	local WORKSPACE

	daemon_mkdir 0700 $RUNDIR
	daemon_mkdir 0750 $LOGDIR

	daemon_touch_log

	start-stop-daemon --start --quiet --chuid $DAEMONUSER --pidfile $PIDFILE --startas $DAEMON --test > /dev/null 2>&1 || return 1

	WORKSPACE=$(mktemp --quiet --tmpdir --directory gapd-XXXXXXXXXXX) > /dev/null 2>&1 || return 2
	chown $DAEMONUSER $WORKSPACE
	chgrp $DAEMONUSER $WORKSPACE
	export TMPDIR=$WORKSPACE
	echo $WORKSPACE > $WKSFILE

	start-stop-daemon --start --quiet --chuid $DAEMONUSER --chdir $WORKSPACE --pidfile $PIDFILE --startas $DAEMON -- $DAEMONARGS > /dev/null 2>&1 || return 2

	while [ -f ${LOCKFILE} -a 0 -lt $counter ]; do
		sleep 0.5
		counter=$((counter - 1))
	done

	return 0
}

do_stop()
{
	# Return
	#   0 if daemon has been stopped
	#   1 if daemon was already stopped
	#   2 if daemon could not be stopped
	#   other if a failure occurred

	local WORKSPACE

	start-stop-daemon --stop --quiet --user $DAEMONUSER --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $REALNAME
	RETVAL="$?"
	[ "$RETVAL" = 2 ] && return 2

	sleep 0.25

	start-stop-daemon --stop --quiet --user $DAEMONUSER --oknodo --retry=0/30/KILL/5 --exec $DAEMON
	[ "$?" = 2 ] && return 2

	if [ -f $WKSFILE ]; then
		WORKSPACE=$(cat $WKSFILE)
		if [ -d $WORKSPACE ]; then
			rm -rf $WORKSPACE
		fi
		rm -f $WKSFILE
	fi
	rm -f $PIDFILE

	return "$RETVAL"
}

case "$1" in
  start)
	[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
	do_start
	case "$?" in
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
		4) [ "$VERBOSE" != no ] && { log_progress_msg "disabled, see /etc/default/gapd" ; log_end_msg 255 ; } ;;
	esac
	;;
  stop)
	[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
	do_stop
	case "$?" in
		0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
		2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
	esac
	;;
  status)
	status_of_proc -p $PIDFILE "$DAEMON" "$NAME" && exit 0 || exit $?
	;;
  restart|force-reload)
	log_daemon_msg "Restarting $DESC" "$NAME"
	do_stop
	case "$?" in
	  0|1)
		do_start
		case "$?" in
			0) log_end_msg 0 ;;
			1) log_end_msg 1 ;; # Old process is still running
			*) log_end_msg 1 ;; # Failed to start
		esac
		;;
	  *)
		# Failed to stop
		log_end_msg 1
		;;
	esac
	;;
  *)
	echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
	exit 3
	;;
esac

: