File: audit-functions

package info (click to toggle)
audit 1%3A3.0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 6,916 kB
  • sloc: ansic: 57,158; sh: 5,100; python: 2,938; makefile: 1,494; sed: 32
file content (52 lines) | stat: -rw-r--r-- 990 bytes parent folder | download
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
# -*-Shell-script-*-

# Make sure umask is sane
umask 022

#/usr/libexec/audit/audit-functions

# killproc {program} [-signal]
killproc ()
{
	local daemon="$1"
	local sig=
	[ -n "${2:-}" ] && sig=$2

	# This matches src/auditd.c
	local pid_file="/var/run/auditd.pid"
	local pid_dir=$(dirname $pid_file)

	if [ ! -d "$pid_dir" ] ; then
		return 4
	fi

	local pid=
	if [ -f "$pid_file" ] ; then
		# pid file exists, use it
		while : ; do
			read line
			[ -z "$line" ] && break
			for p in $line ; do
			   # pid is numeric and corresponds to a process
			   if [ -z "${p//[0-9]/}" ] && [ -d "/proc/$p" ] ; then
				d=$(cat "/proc/$p/comm")
				if [ "$d" = "$daemon" ] ; then
					pid="$p"
					break
				fi
			   fi
			done
		done < "$pid_file"
	else
		# need to search /proc
		p=$(pidof "$daemon")
		if [ -n "$p" ] ; then
			pid="$p"
		fi
	fi

	# At this point we should have a pid or the process is dead
	if [ -n "$pid" ] && [ -n "$sig" ] ; then
		kill "$sig" "$pid" >/dev/null 2>&1
	fi
}