Bug 138081

Summary: sem_post and sem_destroy fail to report errors
Product: Red Hat Enterprise Linux 3 Reporter: Jared Smith-Mickelson <jaredsm>
Component: glibcAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: Brian Brock <bbrock>
Severity: medium Docs Contact:
Priority: medium    
Version: 3.0CC: drepper, roland
Target Milestone: ---   
Target Release: ---   
Hardware: i686   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-11-05 00:34:49 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
test case to illustrate the bug none

Description Jared Smith-Mickelson 2004-11-04 15:28:59 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; 
SV1; .NET CLR 1.1.4322)

Description of problem:
According to the man page, sem_post should return -1 and set errno to 
ERANGE if after incrementation, the semaphore value would exceed 
SEM_VALUE_MAX.  sem_post instead returns 0 in this case.  Similarly, 
sem_destroy should return -1 and set errno to EBUSY if any threads 
are currently blocked waiting on the semaphore.  It instead returns 0 
in this case.

Version-Release number of selected component (if applicable):
glibc-2.3.2-95.27

How reproducible:
Always

Steps to Reproduce:
1.  cc -lpthread sembug.c -o sembug
2.  ./sembug

Actual Results:  Test 1: sem_post should return -1 and set errno to 
ERANGE if
        after incrementation, the semaphore value would exceed
        SEM_VALUE_MAX.

        failed - return value was 0 not -1

Test 2: sem_destroy should return -1 and set errno to EBUSY if
        any threads are currently blocked waiting on the
        semaphore.

        failed - return value was 0 not -1

Expected Results:  Test 1: sem_post should return -1 and set errno to 
ERANGE if
        after incrementation, the semaphore value would exceed
        SEM_VALUE_MAX.

        passed

Test 2: sem_destroy should return -1 and set errno to EBUSY if
        any threads are currently blocked waiting on the
        semaphore.

        passed


Additional info:

Comment 1 Jared Smith-Mickelson 2004-11-04 15:30:09 UTC
Created attachment 106167 [details]
test case to illustrate the bug

Comment 2 Jakub Jelinek 2004-11-04 20:39:52 UTC
The man page is for LinuxThreads.
NPTL is governed by POSIX and there is no such requirement in
http://www.opengroup.org/onlinepubs/009695399/functions/sem_post.html
(only sem_open must return SEM_FAILED + EINVAL in errno if 4th argument is > SEM_VALUE_MAX).
Similarly,
http://www.opengroup.org/onlinepubs/009695399/functions/sem_destroy.html
doesn't mandate but allows -1/EBUSY in sem_destroy.

Comment 3 Roland McGrath 2004-11-05 00:34:49 UTC
Indeed, no bugs here.