Debian Codegraph @

tests/ts/kill/print_pid

raw
1 #!/bin/bash
2
3 # This file is part of util-linux.
4 #
5 # This file is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This file is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14
15 TS_TOPDIR="${0%/*}/../.."
16 TS_DESC="print_pid"
17
18 . "$TS_TOPDIR/functions.sh"
19 ts_init "$*"
20
21 # make sure we do not use shell built-in command
22 if [ "$TS_USE_SYSTEM_COMMANDS" == "yes" ]; then
23 TS_CMD_KILL="$(which kill)"
24 fi
25
26 ts_check_test_command "$TS_CMD_KILL"
27 ts_check_test_command "$TS_HELPER_SIGRECEIVE"
28
29 . "$TS_SELF/kill_functions.sh"
30
31 all_ok=true
32
33 HELPER_SYMLINK="$(mktemp "${TS_OUTDIR}/prXXXXXXXXXXXXX")"
34 ln -sf "$TS_HELPER_SIGRECEIVE" "$HELPER_SYMLINK"
35
36 "$HELPER_SYMLINK" >> $TS_OUTPUT 2>> $TS_ERRLOG &
37 TEST_PID=$!
38 check_test_sigreceive $TEST_PID
39 [ $? -eq 1 ] || echo "${HELPER_SYMLINK##*/} helper did not start" >> "$TS_OUTPUT"
40
41 KILL_PID=$("$TS_CMD_KILL" -p ${HELPER_SYMLINK##*/} 2>> $TS_OUTPUT 2>> $TS_ERRLOG)
42 if [ $? -ne 0 ]; then
43 echo "kill -p did not work" >> "$TS_OUTPUT"
44 all_ok=false
45 fi
46 if [ "x$TEST_PID" != "x$KILL_PID" ]; then
47 echo "jobs -p $TEST_PID != kill -p $KILL_PID" >> "$TS_OUTPUT"
48 all_ok=false
49 fi
50
51 "$TS_CMD_KILL" -1 $TEST_PID
52 wait $TEST_PID
53 if [ $? -ne 1 ]; then
54 echo "wait $TEST_PID returned ${?}" >> "$TS_OUTPUT"
55 all_ok=false
56 fi
57
58 if $all_ok; then
59 echo 'all ok' >> "$TS_OUTPUT"
60 fi
61 rm -f "$HELPER_SYMLINK"
62
63 ts_finalize