trylock_stream bug (exposed as gpgrt_ftrylockfile)
Testing, HighPublic

Assigned To
Authored By
• gniibe
Wed, Oct 14, 4:49 AM

Description

trylock_stream has a bug, it seems that it never works correctly.

Revisions and Commits

Event Timeline

• gniibe created this task.

Internally, _gpgrt_lock_trylock returns an error code on error, 0 when success.
It seems that trylock_stream (and thus gpgrt_ftrylockfile) should return -1 on error, 0 when success.

Here is a patch:

diff --git a/src/estream.c b/src/estream.c
index ba345ff..301a078 100644
--- a/src/estream.c
+++ b/src/estream.c
@@ -476,7 +476,7 @@ trylock_stream (estream_t _GPGRT__RESTRICT stream)
   if (!stream->intern->samethread)
     {
       dbg_lock_1 ("enter trylock_stream for %p\n", stream);
-      rc = _gpgrt_lock_trylock (&stream->intern->lock)? 0 : -1;
+      rc = _gpgrt_lock_trylock (&stream->intern->lock)? -1 : 0;
       dbg_lock_2 ("leave trylock_stream for %p: rc=%d\n", stream, rc);
     }
   else
• gniibe mentioned this in Unknown Object (Maniphest Task).Mon, Oct 19, 4:07 AM

Right, it should have the same semantics as flockfile:

RETURN VALUE
       The ftrylockfile() function returns zero for success (the lock was obtained), and nonzero for failure.
• gniibe changed the task status from Open to Testing.Thu, Oct 22, 3:48 AM
• gniibe mentioned this in Unknown Object (Maniphest Task).Mon, Oct 26, 3:32 AM