blob: 8ba3cc79edba704746025a90b87ff926cc163767 [file]
#!/usr/bin/env bash
# Copyright (C) 2026 Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
#
# 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="close"
. "$TS_TOPDIR"/functions.sh
ts_init "$*"
ts_check_test_command "$TS_CMD_FLOCK"
ts_check_test_command "$TS_HELPER_STRERROR"
LOCK_FILENAME="$TS_OUTDIR"/lock
LOCK_FD=10
# shellcheck disable=SC2093
exec 10<>"$LOCK_FILENAME"
# We expect an EBADF error since the child shouldn't inherit the fd 10
"$TS_CMD_FLOCK" --exclusive --close --fd "$LOCK_FD" --command \
"$TS_CMD_FLOCK --exclusive --nonblock --fd $LOCK_FD true \
>>$TS_OUTPUT 2>>$TS_ERRLOG" >>"$TS_OUTPUT" 2>>"$TS_ERRLOG"
ts_log "exit code: $?"
# This should be successful
"$TS_CMD_FLOCK" --exclusive --fd "$LOCK_FD" --command \
"$TS_CMD_FLOCK --exclusive --nonblock --fd $LOCK_FD true \
>>$TS_OUTPUT 2>>$TS_ERRLOG" >>"$TS_OUTPUT" 2>>"$TS_ERRLOG"
ts_log "exit code: $?"
# Clean up output
sed -i -e "s@$($TS_HELPER_STRERROR EBADF)@EBADF@" "$TS_OUTPUT" "$TS_ERRLOG"
ts_finalize