#!/bin/bash

### BEGIN INIT INFO
# Provides:          ts-sendsigs-omit
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2
# Default-Stop:      
# Short-Description: Specifies TS PIDs to not kill during shutdown
# Description:       These are processes used by TS that should not be killed during shutdown
### END INIT INFO

(
# Stops shutdown from killing any processes which should not be killed before 
# the filesystem is cleanly unmounted.  This includes all *ctls and nbd-client 
# that actually host the root filesystem.  This also includes the tshwctl
# or ts4*00ctl application which feeds the watchdog, and xuartctl so there is
# console output throughout shutdown
omt=0
for I in /proc/[1-9]*; do
     line=""
     if [ -e /$I/cmdline ]; then
          read line junk < $I/cmdline >/dev/null 2>&1
          if [ -n "$line" ]; then case "$line" in
               *nbd-client*)
                    echo -n ${I##*/} > /run/sendsigs.omit.d/nbdclient-$omt
                    ;;
               *nandctl*)
                    echo -n ${I##*/} > /run/sendsigs.omit.d/nandctl-$omt
                    ;;
               *sdctl*)
                    echo -n ${I##*/} > /run/sendsigs.omit.d/sdctl-$omt
                    ;;
               *ts[1-9]*ctl*)
                    echo -n ${I##*/} > /run/sendsigs.omit.d/tsxctl-$omt
                    ;;
               *tshwctl*)
                    echo -n ${I##*/} > /run/sendsigs.omit.d/tshwctl-$omt
                    ;;
               *xuartctl*)
                    echo -n ${I##*/} > /run/sendsigs.omit.d/xuartctl-$omt
                    ;;
          esac; fi
          let omt++
     fi
done
) >/dev/null 2>&1

