| Summary: | Bug in sysv semaphore waiting processes count | ||
|---|---|---|---|
| Product: | Base System | Reporter: | Ramy M. Hassan <ramy> |
| Component: | misc | Assignee: | Colin Percival <cperciva> |
| Status: | Closed FIXED | ||
| Severity: | Affects Only Me | ||
| Priority: | Normal | ||
| Version: | Unspecified | ||
| Hardware: | Any | ||
| OS: | Any | ||
Responsible Changed From-To: freebsd-bugs->cperciva I think I know how to fix this. State Changed From-To: open->patched Fixed in current, will MFC in 7 days. State Changed From-To: patched->closed MFC done |
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.