File: vserverkillall

package info (click to toggle)
util-vserver 0.30.212-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 6,648 kB
  • ctags: 3,145
  • sloc: ansic: 19,781; sh: 13,258; xml: 1,618; makefile: 364; perl: 85
file content (63 lines) | stat: -rwxr-xr-x 1,752 bytes parent folder | download | duplicates (7)
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
#!/bin/sh

# Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
# based on vserverkillall by Jacques Gelinas
#  
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#  
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#  
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

# This script kills all process it can finds
# Only useful if you are using a security context.
# It does nothing in context 0
USR_LIB_VSERVER=/usr/lib/util-vserver
CTX=`grep ^s_context /proc/self/status | sed s/s_context:// | (read a b; echo $a)`
CTX=`eval expr $CTX + 0`
if [ "$CTX" = 0 ] ; then
	echo Running in security context 0, do nothing
else
	cd /proc
	for SIG in -TERM -TERM -TERM -9
	do
		ONE=0
		for dir in *
		do
			case $dir in
			1)
				;;
			$$)
				;;
			[1-9]*)
				ONE=1
				echo kill $SIG "`$USR_LIB_VSERVER/readlink /proc/$dir/exe`"[$dir]
				kill $SIG $dir
				;;
			*)
				;;
			esac
		done
		if [ "$ONE" = 0 ] ; then
			break
		fi
		sleep 1
	done
	# Kill the fakeinit process. It is shown as process one, but can't
	# be killed this way
	INITPID=`cat /proc/self/status | grep initpid: | (read a b; expr $b)`
	if [ "$INITPID" != "0" ] ; then
		echo kill init, pid $INITPID
		kill -9 $INITPID
	fi
fi