summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Yang <liezhi.yang@windriver.com>2011-05-17 09:35:57 -0600
committerRichard Purdie <richard.purdie@linuxfoundation.org>2011-05-18 14:32:45 +0100
commit0424560e5fb00ad5e455af82425143d87a37bcc7 (patch)
tree2f01d74e627985498413a4ec6ec15fa36b41fd76
parent0b175c42d712103e4149d5580c11e1b0d59220ae (diff)
downloadpoky-0424560e5fb00ad5e455af82425143d87a37bcc7.tar.gz
Add pidofproc to ${sysconfdir}/init.d/functions
Add pidofproc to ${sysconfdir}/init.d/functions, this is used for getting the pid of the process. It uses pidof to implement currently, it may also use the pidfile or ps to implement in the future. (From OE-Core rev: 114a11628fb04c30cc96c9fd23db7a7fbc4fd02e) Signed-off-by: Robert Yang <liezhi.yang@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-core/initscripts/initscripts-1.0/functions32
1 files changed, 30 insertions, 2 deletions
diff --git a/meta/recipes-core/initscripts/initscripts-1.0/functions b/meta/recipes-core/initscripts/initscripts-1.0/functions
index ac99e112c7..c1eac3efda 100644
--- a/meta/recipes-core/initscripts/initscripts-1.0/functions
+++ b/meta/recipes-core/initscripts/initscripts-1.0/functions
@@ -3,6 +3,35 @@
3# functions This file contains functions to be used by most or all 3# functions This file contains functions to be used by most or all
4# shell scripts in the /etc/init.d directory. 4# shell scripts in the /etc/init.d directory.
5# 5#
6# NOTE: The pidofproc () doesn't support the process which is a script unless
7# the pidof supports "-x" option. If you want to use it for such a
8# process:
9# 1) If there is no "pidof -x", replace the "pidof $1" with another
10# command like(for core-image-minimal):
11# ps | awk '/'"$1"'/ {print $1}'
12# Or
13# 2) If there is "pidof -x", replace "pidof" with "pidof -x".
14#
15# pidofproc - print the pid of a process
16# $1: the name of the process
17pidofproc () {
18
19 # pidof output null when no program is running, so no "2>/dev/null".
20 pid=`pidof $1`
21 case $? in
22 0)
23 echo $pid
24 return 0
25 ;;
26 127)
27 echo "ERROR: command pidof not found" >&2
28 exit 127
29 ;;
30 *)
31 return $?
32 ;;
33 esac
34}
6 35
7machine_id() { # return the machine ID 36machine_id() { # return the machine ID
8 awk 'BEGIN { FS=": " } /Hardware/ \ 37 awk 'BEGIN { FS=": " } /Hardware/ \
@@ -10,6 +39,5 @@ machine_id() { # return the machine ID
10} 39}
11 40
12killproc() { # kill the named process(es) 41killproc() { # kill the named process(es)
13 pid=`/bin/pidof $1` 42 pid=`pidofproc $1` && kill $pid
14 [ "$pid" != "" ] && kill $pid
15} 43}