Debian Codegraph @

tests/ts/kill/pidfdino

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 # Copyright (C) 2025 Christian Goeschel Ndjomouo <[email protected]>
16
17 TS_TOPDIR="${0%/*}/../.."
18 TS_DESC="pidfdino"
19
20 . "$TS_TOPDIR/functions.sh"
21 ts_init "$*"
22
23 # make sure we do not use shell built-in command
24 if [ "$TS_USE_SYSTEM_COMMANDS" == "yes" ]; then
25 TS_CMD_KILL="$(which kill)"
26 fi
27
28 # The pidfs was only introduced in kernel version 6.9,
29 # which means we cannot get a valid pidfd from earlier versions,
30 # so we can confidently anticipate the test failure.
31 if ts_kernel_ver_lt 6 9; then
32 TS_KNOWN_FAIL="yes"
33 fi
34
35 ts_check_test_command "$TS_CMD_KILL"
36 ts_check_test_command "$TS_HELPER_SIGRECEIVE"
37 ts_check_test_command "$TS_HELPER_KILL_PIDFDINO"
38
39 . "$TS_SELF/kill_functions.sh"
40
41 all_ok=true
42
43 HELPER_SYMLINK="$(mktemp "${TS_OUTDIR}/opXXXXXXXXXXXXX")"
44 ln -sf "$TS_HELPER_SIGRECEIVE" "$HELPER_SYMLINK"
45
46 try_option()
47 {
48 "$HELPER_SYMLINK" >> $TS_OUTPUT 2>> $TS_ERRLOG &
49 TEST_PID=$!
50 TEST_PIDFD_INO=$( "$TS_HELPER_KILL_PIDFDINO" ${TEST_PID} )
51 ts_skip_exitcode_not_supported
52
53 check_test_sigreceive "${TEST_PID}"
54 [ $? -eq 1 ] || echo "${HELPER_SYMLINK##*/} helper did not start" >> "$TS_OUTPUT"
55
56 "$TS_CMD_KILL" "$@" "${TEST_PID}:${TEST_PIDFD_INO}" >> $TS_OUTPUT 2>> $TS_ERRLOG
57 if [ $? -ne 0 ]; then
58 echo "kill $* did not work" >> "$TS_OUTPUT"
59 all_ok=false
60 fi
61 wait $TEST_PID
62 if [ $? -ne 1 ]; then
63 echo "wait $TEST_PID for $* did not work" >> "$TS_OUTPUT"
64 all_ok=false
65 fi
66 }
67
68 try_option -s 1
69 try_option --signal 1
70 try_option --signal HUP
71 try_option --signal SIGHUP
72 try_option -1
73 try_option -HUP
74 try_option -SIGHUP
75
76 if $all_ok; then
77 echo 'all ok' >> "$TS_OUTPUT"
78 fi
79 rm -f "$HELPER_SYMLINK"
80
81 ts_finalize