Skip to contentSkip to conversation

ipc,sem: fix semctl(..., GETNCNT)

PATCH New Rik van Riel 1 participant 1 message May 9, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipc,sem: fix semctl(..., GETNCNT)

The semctl GETNCNT returns the number of semops waiting for the specified semaphore to become nonzero. After changeset 9f1bc2c, the semops waiting on just one semaphore are waiting on that semaphore's list.

In order to return the correct count, we have to walk that list too, in addition to the sem_array's list for complex operations.

---
This is the semncnt equivalent of the previous patch.

 ipc/sem.c | 7 +++++++
 1 file changed, 7 insertions(+)
ipc/sem.c +7 -0
index 04b264d..a7e40ed 100644
@@ -796,6 +796,13 @@ static int count_semncnt (struct sem_array * sma, ushort semnum)
 	struct sem_queue * q;
 
 	semncnt = 0;
+	list_for_each_entry(q, &sma->sem_base[semnum].sem_pending, list) {
+		struct sembuf * sops = q->sops;
+		BUG_ON(sops->sem_num != semnum);
+		if ((sops->sem_op < 0) && !(sops->sem_flg & IPC_NOWAIT))
+			semncnt++;
+	}
+
 	list_for_each_entry(q, &sma->sem_pending, list) {
 		struct sembuf * sops = q->sops;
 		int nsops = q->nsops;