From: Thomas Weißschuh Date: Fri, 14 Apr 2023 07:12:03 +0000 (+0200) Subject: flock: (tests) add test for fd-based locking X-Git-Tag: v2.39-rc3~28 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=89779c1efc8643bdeea4f94c05f6254d5374ecf9;p=thirdparty%2Futil-linux.git flock: (tests) add test for fd-based locking --- diff --git a/tests/expected/misc/flock-fd b/tests/expected/misc/flock-fd new file mode 100644 index 0000000000..35821117c8 --- /dev/null +++ b/tests/expected/misc/flock-fd @@ -0,0 +1 @@ +Success diff --git a/tests/ts/misc/flock b/tests/ts/misc/flock index 9a15aab1d4..0c6ac0bec5 100755 --- a/tests/ts/misc/flock +++ b/tests/ts/misc/flock @@ -80,6 +80,24 @@ do_lock "--nonblock --exclusive --conflict-exit-code 123" 123 "You will never se ts_finalize_subtest +ts_init_subtest "fd" +cd "$TS_OUTDIR" +rm 4 2> /dev/null +exec 4<>$TS_OUTDIR/lockfile || ts_log "Could not open lockfile" +$TS_CMD_FLOCK --nonblock --exclusive --conflict-exit-code 123 4 \ + >> $TS_OUTPUT 2>> $TS_ERRLOG + +rc="$?" + +if [ "$rc" == "123" ]; then + ts_log "Success" +else + ts_log "Failed [rc=$rc]" +fi +[ -f 4 ] && ts_log "fd file should not exist" +ts_finalize_subtest + + ts_init_subtest "timeout" do_lock "--timeout 5 --conflict-exit-code 5" 0 "After timeout." END=$(date '+%s')