Bug 64347

Summary: Bug in sysv semaphore waiting processes count
Product: Base System Reporter: Ramy M. Hassan <ramy>
Component: miscAssignee: Colin Percival <cperciva>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   

Description Ramy M. Hassan 2004-03-16 19:20:08 UTC
When a procss is waiting for a semaphore value to be more than zero ( calling semop ) , then receives a signal, the semop() returns -1 and errno is set to EINTR. This is fine, but the problem is that the number of processes waiting for the semaphore is not decremented. So a successive call to semctl(semsetid,semid,GETNCNT,0) will return an incorrect value.

How-To-Repeat: Write a program that intializes a semaphore set to zero , then call semop in a loop 

struct sembuf oplist[] = { { 0 , -1 , 0 } };
while ( semop(semid,oplist,1) < 0 ) {
printf("Number of waiting processes %d \n",semctl(semid,prof,GETNCNT));
}

while the process is waiting on the semaphore , send the process any signal that the process can handle. You will see that the number of waiting processes will increment each time a signal is sent which is incorrect.
Comment 1 Colin Percival freebsd_committer freebsd_triage 2004-03-17 04:22:22 UTC
Responsible Changed
From-To: freebsd-bugs->cperciva

I think I know how to fix this.
Comment 2 Colin Percival freebsd_committer freebsd_triage 2004-03-17 09:38:04 UTC
State Changed
From-To: open->patched

Fixed in current, will MFC in 7 days.
Comment 3 Colin Percival freebsd_committer freebsd_triage 2004-03-24 11:41:40 UTC
State Changed
From-To: patched->closed

MFC done