[PATCH 7/6] ipc/sem.c: add a printk_once for semctl(GETNCNT/GETZCNT)

From: Manfred Spraul
Date: Sun May 25 2014 - 14:21:15 EST


The actual Linux implementation for semctl(GETNCNT) and semctl(GETZCNT)
always (since 0.99.10) reported a thread as sleeping on all semaphores
that are listed in the semop() call.
The documented behavior (both in the Linux man page and in the Single Unix
Specification) is that a task should be reported on exactly one semaphore:
The semaphore that caused the thread to got to sleep.

This patch adds a printk_once() that is triggered if a thread hits
the relevant case.

Signed-off-by: Manfred Spraul <manfred@xxxxxxxxxxxxxxxx>
Cc: Davidlohr Bueso <davidlohr.bueso@xxxxxx>
Cc: Michael Kerrisk <mtk.manpages@xxxxxxxxx>
---
ipc/sem.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/ipc/sem.c b/ipc/sem.c
index 9106321..3cc2f7b6 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -1000,6 +1000,18 @@ static int check_qop(struct sem_array *sma, int semnum, struct sem_queue *q,
{
struct sembuf *sop = q->blocking;

+ /*
+ * Linux always (since 0.99.10) reported a task as sleeping on all
+ * semaphores. This violates SUS, therefore it was changed to the
+ * standard compliant behavior.
+ * Give the administrators a chance to notice that an application
+ * might misbehave because it relies on the Linux behavior.
+ */
+ printk_once(KERN_INFO "semctl(GETNCNT/GETZCNT) is since 3.16 Single " \
+ "Unix Specification compliant.\n" \
+ "The task %d triggered the difference, " \
+ "watch for misbehavior.", current->pid);
+
if (sop->sem_num != semnum)
return 0;

--
1.9.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/