p The .Sy semid_ds structure used in the .Dv IPC_SET and .Dv IPC_STAT commands is defined in .Aq Pa sys/sem.h and contains the following members: d -literal struct ipc_perm sem_perm; /* operation permissions */ unsigned short sem_nsems; /* number of sems in set */ time_t sem_otime; /* last operation time */ time_t sem_ctime; /* last change time */ .Ed
p The .Sy ipc_perm structure used inside the .Sy semid_ds structure is defined in .Aq Pa sys/ipc.h and contains the following members: d -literal uid_t cuid; /* creator user id */ gid_t cgid; /* creator group id */ uid_t uid; /* user id */ gid_t gid; /* group id */ mode_t mode; /* permission (lower 9 bits) */ .Ed
p .Fn semctl provides the following operations: l -tag -width IPC_RMIDX t Dv GETVAL Return the value of the semaphore. t Dv SETVAL Set the value of the semaphore to .Fa arg.val , where .Fa arg is the fourth arument to .Fn semctl . t Dv GETPID Return the pid of the last process that did an operation on this semaphore. t Dv GETNCNT Return the number of processes waiting to acquire the semaphore. t Dv GETZCNT Return the number of processes waiting for the value of the semaphore to reach 0. t Dv GETALL Return the values of all the semaphores associated with .Fa semid . t Dv SETALL Set the values of all the semaphores that are associated with the semaphore identifier .Fa semid to the corresponding values in .Fa arg.array , where .Fa arg is the fourth argument to .Fn semctl . t Dv IPC_STAT Gather information about a semaphore and place the information in the structure pointed to by .Fa arg.buf , where .Fa arg is the fourth argument to .Fn semctl . t Dv IPC_SET Set the value of the .Va sem_perm.uid , .Va sem_perm.gid and .Va sem_perm.mode fields in the structure associated with the semaphore. The values are taken from the corresponding fields in the structure pointed to by .Fa arg.buf , there .Fa arg is the fourth argument to .Fn semctl . This operation can only be executed by the super-user, or a process that has an effective user id equal to either .Va sem_perm.cuid or .Va sem_perm.uid in the data structure associated with the message queue. t Dv IPC_RMID Remove the semaphores associated with .Fa semid from the system and destroy the data structures associated with it. Only the super-user or a process with an effective uid equal to the .Va sem_perm.cuid or .Va sem_perm.uid values in the data structure associated with the semaphore can do this. .El
p The permission to read or change a message queue (see .Xr semop 2 ) is determined by the .Va sem_perm.mode field in the same way as is done with files (see .Xr chmod 2 ) , but the effective uid can match either the .Va sem_perm.cuid field or the .Va sem_perm.uid field, and the effective gid can match either .Va sem_perm.cgid or .Va sem_perm.gid . .Sh RETURN VALUES For the .Dv GETVAL , .Dv GETPID , .Dv GETNCNT , and .Dv GETZCNT operations, .Fn semctl returns one of the values described above if successful. All other operations will make .Fn semctl return 0 if no errors occur. Otherwise -1 is returned and .Va errno set to reflect the error. .Sh ERRORS .Fn semctl will fail if: l -tag -width Er t Bq Er EPERM .Fa cmd is equal to .Dv IPC_SET or .Dv IPC_RMID and the caller is not the super-user, nor does the effective uid match either the .Va sem_perm.uid or .Va sem_perm.cuid fields of the data structure associated with the message queue. t Bq Er EACCES The caller has no operation permission for this semaphore. t Bq Er EINVAL .Fa semid is not a valid message semaphore identifier.
p .Va cmd is not a valid command. t Bq Er EFAULT .Fa arg.buf or .Fa arg.array specifies an invalid address. .El .Sh SEE ALSO .Xr semget 2 , .Xr semop 2 .Sh STANDARDS The .Nm system call conforms to .St -xsh5 . .Sh HISTORY Semaphores appeared in the first release of .At V .