]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
flock: (tests) add test for fd-based locking
authorThomas Weißschuh <thomas@t-8ch.de>
Fri, 14 Apr 2023 07:12:03 +0000 (09:12 +0200)
committerThomas Weißschuh <thomas@t-8ch.de>
Fri, 14 Apr 2023 07:12:42 +0000 (09:12 +0200)
tests/expected/misc/flock-fd [new file with mode: 0644]
tests/ts/misc/flock

diff --git a/tests/expected/misc/flock-fd b/tests/expected/misc/flock-fd
new file mode 100644 (file)
index 0000000..3582111
--- /dev/null
@@ -0,0 +1 @@
+Success
index 9a15aab1d4a24c7175c68fd94adff71ccdb004a7..0c6ac0bec544520f61153c9475d001d1413d2713 100755 (executable)
@@ -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')