diff options
Diffstat (limited to 'fireslay')
-rwxr-xr-x | fireslay | 89 |
1 files changed, 63 insertions, 26 deletions
@@ -1,10 +1,67 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | 2 | ||
3 | if [ "$1" = -q ] | 3 | die() |
4 | then | 4 | { |
5 | exec 2>/dev/null | 5 | printf '%s: Error: %s\n' "$0" "$*" >&2 |
6 | shift | 6 | exit 1 |
7 | fi | 7 | } |
8 | |||
9 | parseopts() | ||
10 | { | ||
11 | while [ $# -gt 0 ] | ||
12 | do | ||
13 | case "$1" in | ||
14 | -q | --quiet ) | ||
15 | exec 2>/dev/null | ||
16 | ;; | ||
17 | -y | --kill-last-process ) | ||
18 | FIRESLAY_KILL_LAST_PROCESS=y | ||
19 | ;; | ||
20 | --) | ||
21 | shift | ||
22 | break | ||
23 | ;; | ||
24 | -* ) | ||
25 | die unknown option | ||
26 | ;; | ||
27 | *) | ||
28 | break | ||
29 | ;; | ||
30 | esac | ||
31 | shift | ||
32 | done | ||
33 | [ $# = 0 ] || die usage | ||
34 | } | ||
35 | |||
36 | main() | ||
37 | { | ||
38 | parseopts "$@" | ||
39 | |||
40 | set -- $(web_content_pids) | ||
41 | |||
42 | ( | ||
43 | case $# in | ||
44 | 0 ) echo "$0: Warning: Not slaying: no Web Content process found." >&2 | ||
45 | exit | ||
46 | ;; | ||
47 | 1 ) if ! [ "$FIRESLAY_KILL_LAST_PROCESS" ] | ||
48 | then | ||
49 | echo "$0: Warning: Not slaying: only one 'Web Content' process. Specify -y to kill it." >&2 | ||
50 | exit | ||
51 | fi | ||
52 | ;; | ||
53 | * ) shift | ||
54 | ;; | ||
55 | esac | ||
56 | set -x | ||
57 | ps $* >&2 | ||
58 | kill $* | ||
59 | ) | ||
60 | |||
61 | r=$? | ||
62 | ps $* >&2 | ||
63 | exit $r | ||
64 | } | ||
8 | 65 | ||
9 | web_content_pids() | 66 | web_content_pids() |
10 | { | 67 | { |
@@ -18,25 +75,5 @@ web_content_pids() | |||
18 | } | 75 | } |
19 | } | 76 | } |
20 | 77 | ||
21 | set -- $(web_content_pids | tac) | 78 | main "$@" |
22 | 79 | ||
23 | case $# in | ||
24 | 0) | ||
25 | echo "$0: Warning: Not slaying: no Web Content process found." >&2 | ||
26 | exit | ||
27 | ;; | ||
28 | 1) | ||
29 | echo "$0: Warning: Not slaying: only one Web Content process found." >&2 | ||
30 | ps $* >&2 | ||
31 | exit | ||
32 | ;; | ||
33 | esac | ||
34 | |||
35 | ( | ||
36 | set -x | ||
37 | ps $1 >&2 | ||
38 | kill $1 | ||
39 | ) | ||
40 | r=$? | ||
41 | ps $* >&2 | ||
42 | exit $r | ||