diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 19:33:32 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 19:33:32 +0000 |
commit | 8bb05ac73a5b448b339ce0bc8d396c82c459b47f (patch) | |
tree | 1fdda006866bca20d41cb206767ea5241e36852f /tests/ts/lslocks | |
parent | Adding debian version 2.39.3-11. (diff) | |
download | util-linux-8bb05ac73a5b448b339ce0bc8d396c82c459b47f.tar.xz util-linux-8bb05ac73a5b448b339ce0bc8d396c82c459b47f.zip |
Merging upstream version 2.40.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ts/lslocks')
-rwxr-xr-x | tests/ts/lslocks/lslocks | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/tests/ts/lslocks/lslocks b/tests/ts/lslocks/lslocks new file mode 100755 index 0000000..912fac8 --- /dev/null +++ b/tests/ts/lslocks/lslocks @@ -0,0 +1,117 @@ +#!/bin/bash +# +# Copyright (C) 2023 Masatake YAMATO <yamato@redhat.com> +# +# This file is part of util-linux. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +TS_TOPDIR="${0%/*}/../.." +TS_DESC="flock" + +. "$TS_TOPDIR"/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_CMD_LSLOCKS" +ts_check_test_command "$TS_HELPER_MKFDS" +ts_check_prog "sed" + +ts_cd "$TS_OUTDIR" + +FILE0=util-linux-lslocks-target-file +FILE=${FILE0}--$$ +FD=17 +DFD=18 +COLS=COMMAND,TYPE,SIZE,MODE,START,END +OPTS="--raw --noheadings" +METHODS=( + flock-sh + flock-ex + posix-r- + posix--w + posix-rw + ofd-r- + ofd--w + ofd-rw + lease-w +) + +OFD_METHODS=( + flock-sh + flock-ex + ofd-r- + ofd--w + ofd-rw + lease-w +) + +SLEEP() +{ + # It appears that there is a time lag between locking and its + # visibility in /proc/locks. See the unstbale results of errors I + # observed in https://github.com/util-linux/util-linux/pull/2629. + sleep 1 +} + +DFD=18 +COLS_WITH_HOLDERS=COMMAND,TYPE,SIZE,MODE,START,END,HOLDERS +run_lslocks() +{ + local m=$1 + + { + rm -f "${FILE}" + coproc MKFDS { "$TS_HELPER_MKFDS" make-regular-file $FD file="$FILE" lock=$m; } + if read -r -u "${MKFDS[0]}" PID; then + SLEEP + + "$TS_CMD_LSLOCKS" ${OPTS} --pid "${PID}" -o "${COLS}" + echo "# $m + ${COLS} + ${OPTS}": $? + "$TS_CMD_LSLOCKS" ${OPTS} --pid "${PID}" -o PATH | sed -e 's#.*\('"$FILE0"'\)--[0-9]\+ *$#\1#' + echo "# $m + PATH + ${OPTS}": ${PIPESTATUS[0]} + echo DONE >&"${MKFDS[1]}" + fi + } > "$TS_OUTPUT" 2>&1 + + wait "${MKFDS_PID}" +} + +run_lslocks_with_co_holders() +{ + local m=$1 + + { + rm -f "${FILE}" + coproc MKFDS { "$TS_HELPER_MKFDS" make-regular-file $FD file="$FILE" lock=$m dupfd=$DFD; } + SLEEP + if read -r -u "${MKFDS[0]}" PID; then + "$TS_CMD_LSLOCKS" ${OPTS} --pid "${PID}" -o "${COLS_WITH_HOLDERS}" | sed -e "s/${PID},/1,/g" + echo "# $m + ${COLS_WITH_HOLDERS} + ${OPTS}": ${PIPESTATUS[0]} + echo DONE >&"${MKFDS[1]}" + fi + } > "$TS_OUTPUT" 2>&1 + + wait "${MKFDS_PID}" +} + +for m in "${METHODS[@]}"; do + ts_init_subtest "$m" + run_lslocks "$m" + ts_finalize_subtest +done + +for m in "${OFD_METHODS[@]}"; do + ts_init_subtest "$m+HOLDERS" + run_lslocks_with_co_holders "$m" + ts_finalize_subtest +done + +ts_finalize |