Skip to content

Commit

Permalink
ipc/sem.c: add a printk_once for semctl(GETNCNT/GETZCNT)
Browse files Browse the repository at this point in the history
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 pr_info_once() that is triggered if a thread hits the
relevant case.

The code triggers slightly too often, otherwise it would be necessary to
replicate the old code.  As there are no known users of GETNCNT or
GETZCNT, this is done to prevent unnecessary bloat.

The task that triggered is reported with name (tsk->comm) and pid.

Signed-off-by: Manfred Spraul <[email protected]>
Acked-by: Davidlohr Bueso <[email protected]>
Cc: Michael Kerrisk <[email protected]>
Cc: Joe Perches <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
manfred-colorfu authored and torvalds committed Jun 6, 2014
1 parent b220c57 commit 9b44ee2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ipc/sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,17 @@ 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.
*/
pr_info_once("semctl(GETNCNT/GETZCNT) is since 3.16 Single Unix Specification compliant.\n"
"The task %s (%d) triggered the difference, watch for misbehavior.\n",
current->comm, task_pid_nr(current));

if (sop->sem_num != semnum)
return 0;

Expand Down

0 comments on commit 9b44ee2

Please sign in to comment.