Bug 133 - sem_timedwait is not POSIX compliant.
Summary: sem_timedwait is not POSIX compliant.
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: linuxthreads (show other bugs)
Version: 2.3.2
: P2 normal
Target Milestone: ---
Assignee: GOTO Masanori
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-04-26 18:52 UTC by Brian Wagener
Modified: 2019-04-10 12:00 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
Patch to semaphore.c (373 bytes, patch)
2004-04-26 18:57 UTC, Brian Wagener
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brian Wagener 2004-04-26 18:52:08 UTC
The implementation of sem_timedwait which is in semaphore.c, is not POSIX 
compliant in regards to returning errors.  It is supposed to return 0 or -1, and 
put the error in errno, which it doesn't do, but instead returns the error 
directly.  Below is the patch to the latest in CVS.

--- semaphore.c.orig    2004-04-26 14:29:11.000000000 -0400
+++ semaphore.c 2004-04-26 14:30:19.000000000 -0400
@@ -225,7 +225,8 @@
     /* The standard requires that if the function would block and the
        time value is illegal, the function returns with an error.  */
     __pthread_unlock(&sem->__sem_lock);
-    return EINVAL;
+    errno = EINVAL;
+    return -1;
   }

   /* Set up extrication interface */
@@ -263,7 +264,8 @@

        if (was_on_queue) {
          __pthread_set_own_extricate_if(self, 0);
-         return ETIMEDOUT;
+        errno = ETIMEDOUT;
+        return -1;
        }

        /* Eat the outstanding restart() from the signaller */
Comment 1 Brian Wagener 2004-04-26 18:57:01 UTC
Created attachment 68 [details]
Patch to semaphore.c
Comment 2 Jakub Jelinek 2004-04-30 08:53:54 UTC
Fix commited to glibc CVS on 2004-04-29.