Commit 7cf3b4c6 authored by Rusty Russell's avatar Rusty Russell Committed by Linus Torvalds

[PATCH] semctl SUSv2 compliance

Christopher Yeoh <cyeoh@samba.org>: (Made -p1 compliant by rusty) SUSv2 semctl compliance:

  The semctl call with SETVAL currently does not set sempid (at the
  moment sempid is only set during a successful semop call). An
  explanation from Geoff Clare of the Open Group regarding why sempid
  should be set during the semctl call:

  "The spec isn't very clear, but there is a statement on the semget()
  page which I think justifies the assumption made by the test.  It says
  that upon creation, the data structure associated with each semaphore
  in the set is not initialised, and that the semctl() function with
  SETVAL or SETALL can be used to initialise each semaphore.

  Therefore semctl() with SETVAL has to set sempid to *something*, and
  since sempid contains the "process ID of the last operation", setting
  it to anything other than the pid of the calling process would mean
  that sempid contained misleading information.  It could be argued that
  setting it to zero would not be misleading, but zero cannot be the
  process ID of a process, and so is not a valid value for sempid anyway."

  The following patch changes semctl so when called with SETVAL
  sempid is set to the pid of the calling process:
parent fbce8464
...@@ -644,6 +644,7 @@ int semctl_main(int semid, int semnum, int cmd, int version, union semun arg) ...@@ -644,6 +644,7 @@ int semctl_main(int semid, int semnum, int cmd, int version, union semun arg)
for (un = sma->undo; un; un = un->id_next) for (un = sma->undo; un; un = un->id_next)
un->semadj[semnum] = 0; un->semadj[semnum] = 0;
curr->semval = val; curr->semval = val;
curr->sempid = current->pid;
sma->sem_ctime = CURRENT_TIME; sma->sem_ctime = CURRENT_TIME;
/* maybe some queued-up processes were waiting for this */ /* maybe some queued-up processes were waiting for this */
update_queue(sma); update_queue(sma);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment