This file is indexed.

/etc/init.d/console-log is in console-log 1.2-1.

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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#! /bin/bash
#
# console-log   init script for console-log

### BEGIN INIT INFO
# Provides:          console-log
# Required-Start:    $local_fs $remote_fs $syslog
# Required-Stop:     $local_fs $remote_fs $syslog
# Should-Start:
# Should-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Puts a logfile pager on virtual consoles
# Description:       console-log keeps logfile pagers open on virtual consoles.
### END INIT INFO


PATH=/sbin:/bin:/usr/sbin:/usr/bin
DESC="console-log"
DEFAULTPAGER="less"
LOGPAGER="/usr/share/console-log/logpager"
PIDFILEDEFDIR="/run/console-log"
CONFIGFILE="/etc/console-log.conf"
USERNAME="Debian-console-log"
MAXFILESIZE="7000000"

set -e

if [ -r "/lib/lsb/init-functions" ]; then
  . /lib/lsb/init-functions
else
  echo "E: /lib/lsb/init-functions not found, lsb-base (>= 3.0-6) needed"
  exit 1
fi

if [ -n "$CONLoGDEBUG" ]; then
  echo "now debugging $0 $@"
  set -x
fi


mkdir -p $PIDFILEDEFDIR

# this is from madduck on IRC, 2006-07-06
# There should be a better possibility to give daemon error messages
# and/or to log things
log()
{
  case "$1" in
    [[:digit:]]*) success=$1; shift;;
    *) :;;
  esac
  log_action_begin_msg "$1"; shift
  log_action_end_msg ${success:-0} "$*"
}


# WARNING! The pager might be run as root. /usr/share/console-log/logpager
# is a wrapper for the actual pager that is supposed to configure the pager
# in a secure way to not allow shell escapes. If you have extended the
# pager wrapper to support other pagers, please submit your patches via
# the BTS.

start_pager()
{
TTY="$1"
CHVT="$2"
FILE="$3"
USER="$4"
GROUP="$5"
MAXFILESIZE="$6"
PAGER="$7"
LOCSCRIPT="$8"

if echo $TTY | grep "[[:digit:]]\+" >/dev/null; then
  PIDFILEDIR="$PIDFILEDEFDIR"
  DAEMONUSER=""
  if [ -n "$USER" ]; then
    DAEMONUSER="--user $USER"
    mkdir -p $PIDFILEDEFDIR/$USER
    chown $USER $PIDFILEDEFDIR/$USER
    PIDFILEDIR="$PIDFILEDEFDIR/$USER"
    if [ -n "$GROUP" ]; then
      DAEMONUSER="$DAEMONUSER.$GROUP"
    fi
  fi
  unset found
  for file in $FILE; do
    if [ -f "$file" ] || [ -L "$file" ]; then
      # check if file is readable by the given user
      if su --shell=$SHELL --command="head -n 1 $file" $USER > /dev/null 2>&1; then
        FILENAME="$TTY-${file//\//_-_}"
	if [ -f "$PIDFILEDIR/$FILENAME" ]; then
	  log_progress_msg "$file (already running)"
	else
          if [ -x "$LOCSCRIPT" ]; then
            . $LOCSCRIPT $file
          fi
          if [ -x "$LOGPAGER" ]; then
	    RET=0
	    (ulimit -S -v $(( $MAXFILESIZE / 1000 * 2 + 10000 ))
            openvt -f -c $TTY -- \
                 daemon --foreground --respawn --attempts=20 --delay=10 \
                         --name=$FILENAME --pidfile=$PIDFILEDIR/$FILENAME \
                         $DAEMONUSER $LOGPAGER -- $PAGER $file $MAXFILESIZE) || RET=$?
	    if [ "$RET" = 2 ]; then
	      log 1 "E: openvt failed. headless system?"
	      exit 1
	    fi
            if [ -f /etc/console.noblank ]; then
              setterm -blank 0 > /dev/tty$TTY
            fi
            [ "$CHVT" == "yes" ] && chvt $TTY
            log_progress_msg "$file"
          else
            log 1 "W: $LOGPAGER is not executeable."
          fi
	fi
      else
        log 1 "W: $file not readable by $USER"
      fi
      found="1"
      break
    fi
    if [ -z "found" ]; then
      log 1 "W: no files in $FILE do exist"
    fi
  done
else
  log 1 "E: illegal tty $TTY."
  exit 1
fi
}

check_pager()
{
  USER="$1"
  shift
  TTY="$1"
  shift
  FILELIST="$@"
  cd $PIDFILEDEFDIR

  PIDFILEDIR="$PIDFILEDEFDIR"
  if [ -n "$USER" ]; then
    PIDFILEDIR="$PIDFILEDEFDIR/$USER"
  fi

  unset found
  CHECKRET=0
  for FILE in $FILELIST; do
    if [ -f "$FILE" ] || [ -L "$FILE" ]; then
      log_progress_msg "$FILE"
      FILENAME="$TTY-${FILE//\//_-_}"
      if daemon --running $USER --name=$FILENAME --pidfile=$PIDFILEDIR/$FILENAME; then
        log_progress_msg "(running)"
      else
        log_progress_msg "(not running)"
        CHECKRET=3
      fi
      found="1"
      break
    fi
  done
  if [ -z "found" ]; then
    log 1 "W: no files in $FILE do exist"
  fi
  return $CHECKRET
}


do_from_config()
{
mkdir -p $PIDFILEDEFDIR
cd $PIDFILEDEFDIR
ACTION="$1"
(
while true; do
  unset tty
  chvt="no"
  unset file
  user="$USERNAME"
  unset group
  group="$USERNAME"
  unset locscript
  pager="$DEFAULTPAGER"
  unset maxfilesize
  maxfilesize="$MAXFILESIZE"
  
  # these variables need to be kept in sync with the ones the are used
  # in the logpager script: Unset them here before parsing config
  unset less_lesssecure
  unset less_opts
  unset less_lesskey
  unset less_term
  unset logpager_path
  COUNTER=""
  ELINE=0
  while read KEY VALUE; do
    case "$KEY" in
      "#" | \#* )
	continue
        ;; # comment
      "" )
        ELINE=1
        break
        ;;
      tty|chvt|file|user|group|pager|locscript|maxfilesize|logpager_*|less_*)
        eval $KEY=\"$VALUE\"
	export $KEY
        COUNTER=".$COUNTER"
        ;;
      *)
        log 1 "ERR: illegal key $KEY"
	exit 1
	;;
    esac
  done
  # do things only if configuration was read
  RET=0
  if [ -n "$COUNTER" ]; then
    case "$ACTION" in
      start) start_pager "$tty" "$chvt" "$file" "$user" "$group" "$maxfilesize" "$pager" "$locscript"
             ;;
      check) check_pager "$user" "$tty" "$file"
      	     RET=$?
             ;;
      *) log 1 "E: illegal action to do_from_config"
         ;;
    esac
  fi
  # break out of loop if eof
  # if we get here without eof, then ELINE==1
  [ "$ELINE" != "1" ] && break
done
) < $CONFIGFILE
return $RET
}

do_from_running()
{
  ACTION="$1"
  cd $PIDFILEDEFDIR
  if [ "$ACTION" = "check" ]; then
    log_action_begin_msg "checking console-log"
  fi
  CHECKRET=0
  for PIDPATH in $(find . -maxdepth 2 -type f); do
    FILENAME=$(echo $PIDPATH | sed -n 's/.*\/\(.*\)/\1/p')
    PIDFILEDIR=$(echo $PIDPATH | sed -n 's/^.*\/\(.*\)\/.*/\1/p')
    if [ -z "$PIDFILEDIR" ]; then
      USER=""
      PIDFILEDIR="$PWD"
    else
      USER="--user $PIDFILEDIR"
      PIDFILEDIR="$PWD/$PIDFILEDIR"
    fi
    OUTPUT="${FILENAME#*-}"
    OUTPUT="${OUTPUT//_-_//}"
    TTY=${FILENAME%%-*}
    RUNNING="no"
    if daemon --running $USER --name=$FILENAME --pidfile=$PIDFILEDIR/$FILENAME; then
      if [ "$ACTION" = "stop" ]; then
        daemon --stop $USER --name=$FILENAME --pidfile=$PIDFILEDIR/$FILENAME
        TERM=vt100 tput clear > /dev/tty$TTY
      fi
      RUNNING="yes"
    else
      CHECKRET=3
    fi
    if [ -d $PIDFILEDIR ]; then
      rmdir --ignore-fail-on-non-empty $PIDFILEDIR
    fi
	  
    # BUGS: This creates weird output if the log file name contains
    # the string "_-_". Go figure.
	  
    log_progress_msg "$OUTPUT"
    if [ "$ACTION" = "check" ]; then
      if [ "$RUNNING" = "no" ]; then
        log_progress_msg "(not running)"
      else
        log_progress_msg "(running)"
      fi
    fi
  done
  if [ "$ACTION" = "check" ]; then
    log_end_msg 0
    return $CHECKRET
  fi
}


case "$1" in
  start)
	log_daemon_msg "Starting $DESC"
        do_from_config start
	log_end_msg 0
	;;
  stop)
	log_daemon_msg "Stopping $DESC"
  	do_from_running stop
	log_end_msg 0
	;;
  reload|force-reload|restart)
        log_daemon_msg "Stopping $DESC for restart"
        do_from_running stop
	log_end_msg 0
	log_daemon_msg "Restarting $DESC"
	do_from_config start
	log_end_msg 0
	;;
  status)
        log_daemon_msg "Checking $DESC processes"
  	do_from_config check
	log_end_msg 0
	;;
  *)
	N=/etc/init.d/$NAME
	echo >&2 "Usage: $N {start|stop|restart|reload|force-reload|status}"
	exit 1
	;;
esac

exit 0