1*8269e767SBrooks Davis.\" 2*8269e767SBrooks Davis.\" Copyright (c) 1995 David Hovemeyer <daveho@infocom.com> 3*8269e767SBrooks Davis.\" 4*8269e767SBrooks Davis.\" All rights reserved. 5*8269e767SBrooks Davis.\" 6*8269e767SBrooks Davis.\" Redistribution and use in source and binary forms, with or without 7*8269e767SBrooks Davis.\" modification, are permitted provided that the following conditions 8*8269e767SBrooks Davis.\" are met: 9*8269e767SBrooks Davis.\" 1. Redistributions of source code must retain the above copyright 10*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer. 11*8269e767SBrooks Davis.\" 2. Redistributions in binary form must reproduce the above copyright 12*8269e767SBrooks Davis.\" notice, this list of conditions and the following disclaimer in the 13*8269e767SBrooks Davis.\" documentation and/or other materials provided with the distribution. 14*8269e767SBrooks Davis.\" 15*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 16*8269e767SBrooks Davis.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17*8269e767SBrooks Davis.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18*8269e767SBrooks Davis.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 19*8269e767SBrooks Davis.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20*8269e767SBrooks Davis.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21*8269e767SBrooks Davis.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22*8269e767SBrooks Davis.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23*8269e767SBrooks Davis.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24*8269e767SBrooks Davis.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25*8269e767SBrooks Davis.\" 26*8269e767SBrooks Davis.Dd July 9, 2020 27*8269e767SBrooks Davis.Dt SEMCTL 2 28*8269e767SBrooks Davis.Os 29*8269e767SBrooks Davis.Sh NAME 30*8269e767SBrooks Davis.Nm semctl 31*8269e767SBrooks Davis.Nd control operations on a semaphore set 32*8269e767SBrooks Davis.Sh LIBRARY 33*8269e767SBrooks Davis.Lb libc 34*8269e767SBrooks Davis.Sh SYNOPSIS 35*8269e767SBrooks Davis.In sys/types.h 36*8269e767SBrooks Davis.In sys/ipc.h 37*8269e767SBrooks Davis.In sys/sem.h 38*8269e767SBrooks Davis.Ft int 39*8269e767SBrooks Davis.Fn semctl "int semid" "int semnum" "int cmd" ... 40*8269e767SBrooks Davis.Sh DESCRIPTION 41*8269e767SBrooks DavisThe 42*8269e767SBrooks Davis.Fn semctl 43*8269e767SBrooks Davissystem call 44*8269e767SBrooks Davisperforms the operation indicated by 45*8269e767SBrooks Davis.Fa cmd 46*8269e767SBrooks Davison the semaphore set indicated by 47*8269e767SBrooks Davis.Fa semid . 48*8269e767SBrooks DavisA fourth argument, a 49*8269e767SBrooks Davis.Fa "union semun arg" , 50*8269e767SBrooks Davisis required for certain values of 51*8269e767SBrooks Davis.Fa cmd . 52*8269e767SBrooks DavisFor the commands that use the 53*8269e767SBrooks Davis.Fa arg 54*8269e767SBrooks Davisargument, 55*8269e767SBrooks Davis.Fa "union semun" 56*8269e767SBrooks Davismust be defined as follows: 57*8269e767SBrooks Davis.Bd -literal 58*8269e767SBrooks Davisunion semun { 59*8269e767SBrooks Davis int val; /* value for SETVAL */ 60*8269e767SBrooks Davis struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ 61*8269e767SBrooks Davis u_short *array; /* array for GETALL & SETALL */ 62*8269e767SBrooks Davis}; 63*8269e767SBrooks Davis.Ed 64*8269e767SBrooks DavisNon-portable software may define 65*8269e767SBrooks Davis.Dv _WANT_SEMUN 66*8269e767SBrooks Davisbefore including 67*8269e767SBrooks Davis.Pa sys/sem.h 68*8269e767SBrooks Davisto use the system definition of 69*8269e767SBrooks Davis.Fa "union semun" . 70*8269e767SBrooks Davis.Pp 71*8269e767SBrooks DavisCommands are performed as follows: 72*8269e767SBrooks Davis.\" 73*8269e767SBrooks Davis.\" This section based on Stevens, _Advanced Programming in the UNIX 74*8269e767SBrooks Davis.\" Environment_. 75*8269e767SBrooks Davis.\" 76*8269e767SBrooks Davis.Bl -tag -width IPC_RMIDXXX 77*8269e767SBrooks Davis.It Dv IPC_STAT 78*8269e767SBrooks DavisFetch the semaphore set's 79*8269e767SBrooks Davis.Fa "struct semid_ds" , 80*8269e767SBrooks Davisstoring it in the memory pointed to by 81*8269e767SBrooks Davis.Fa arg.buf . 82*8269e767SBrooks Davis.It Dv IPC_SET 83*8269e767SBrooks DavisChanges the 84*8269e767SBrooks Davis.Fa sem_perm.uid , 85*8269e767SBrooks Davis.Fa sem_perm.gid , 86*8269e767SBrooks Davisand 87*8269e767SBrooks Davis.Fa sem_perm.mode 88*8269e767SBrooks Davismembers of the semaphore set's 89*8269e767SBrooks Davis.Fa "struct semid_ds" 90*8269e767SBrooks Davisto match those of the struct pointed to by 91*8269e767SBrooks Davis.Fa arg.buf . 92*8269e767SBrooks DavisThe calling process's effective uid must 93*8269e767SBrooks Davismatch either 94*8269e767SBrooks Davis.Fa sem_perm.uid 95*8269e767SBrooks Davisor 96*8269e767SBrooks Davis.Fa sem_perm.cuid , 97*8269e767SBrooks Davisor it must have superuser privileges. 98*8269e767SBrooks Davis.It IPC_RMID 99*8269e767SBrooks DavisImmediately removes the semaphore set from the system. 100*8269e767SBrooks DavisThe calling 101*8269e767SBrooks Davisprocess's effective uid must equal the semaphore set's 102*8269e767SBrooks Davis.Fa sem_perm.uid 103*8269e767SBrooks Davisor 104*8269e767SBrooks Davis.Fa sem_perm.cuid , 105*8269e767SBrooks Davisor the process must have superuser privileges. 106*8269e767SBrooks Davis.It Dv GETVAL 107*8269e767SBrooks DavisReturn the value of semaphore number 108*8269e767SBrooks Davis.Fa semnum . 109*8269e767SBrooks Davis.It Dv SETVAL 110*8269e767SBrooks DavisSet the value of semaphore number 111*8269e767SBrooks Davis.Fa semnum 112*8269e767SBrooks Davisto 113*8269e767SBrooks Davis.Fa arg.val . 114*8269e767SBrooks DavisOutstanding adjust on exit values for this semaphore in any process 115*8269e767SBrooks Davisare cleared. 116*8269e767SBrooks Davis.It Dv GETPID 117*8269e767SBrooks DavisReturn the pid of the last process to perform an operation on 118*8269e767SBrooks Davissemaphore number 119*8269e767SBrooks Davis.Fa semnum . 120*8269e767SBrooks Davis.It Dv GETNCNT 121*8269e767SBrooks DavisReturn the number of processes waiting for semaphore number 122*8269e767SBrooks Davis.Fa semnum Ns 's 123*8269e767SBrooks Davisvalue to become greater than its current value. 124*8269e767SBrooks Davis.It Dv GETZCNT 125*8269e767SBrooks DavisReturn the number of processes waiting for semaphore number 126*8269e767SBrooks Davis.Fa semnum Ns 's 127*8269e767SBrooks Davisvalue to become 0. 128*8269e767SBrooks Davis.It Dv GETALL 129*8269e767SBrooks DavisFetch the value of all of the semaphores in the set into the 130*8269e767SBrooks Davisarray pointed to by 131*8269e767SBrooks Davis.Fa arg.array . 132*8269e767SBrooks Davis.It Dv SETALL 133*8269e767SBrooks DavisSet the values of all of the semaphores in the set to the values 134*8269e767SBrooks Davisin the array pointed to by 135*8269e767SBrooks Davis.Fa arg.array . 136*8269e767SBrooks DavisOutstanding adjust on exit values for all semaphores in this set, 137*8269e767SBrooks Davisin any process are cleared. 138*8269e767SBrooks Davis.El 139*8269e767SBrooks Davis.Pp 140*8269e767SBrooks DavisThe 141*8269e767SBrooks Davis.Vt "struct semid_ds" 142*8269e767SBrooks Davisis defined as follows: 143*8269e767SBrooks Davis.\" 144*8269e767SBrooks Davis.\" Taken straight from <sys/sem.h>. 145*8269e767SBrooks Davis.\" 146*8269e767SBrooks Davis.Bd -literal 147*8269e767SBrooks Davisstruct semid_ds { 148*8269e767SBrooks Davis struct ipc_perm sem_perm; /* operation permission struct */ 149*8269e767SBrooks Davis u_short sem_nsems; /* number of sems in set */ 150*8269e767SBrooks Davis time_t sem_otime; /* last operation time */ 151*8269e767SBrooks Davis time_t sem_ctime; /* last change time */ 152*8269e767SBrooks Davis /* Times measured in secs since */ 153*8269e767SBrooks Davis /* 00:00:00 GMT, Jan. 1, 1970 */ 154*8269e767SBrooks Davis}; 155*8269e767SBrooks Davis.Ed 156*8269e767SBrooks Davis.Sh RETURN VALUES 157*8269e767SBrooks DavisOn success, when 158*8269e767SBrooks Davis.Fa cmd 159*8269e767SBrooks Davisis one of 160*8269e767SBrooks Davis.Dv GETVAL , GETPID , GETNCNT 161*8269e767SBrooks Davisor 162*8269e767SBrooks Davis.Dv GETZCNT , 163*8269e767SBrooks Davis.Fn semctl 164*8269e767SBrooks Davisreturns the corresponding value; otherwise, 0 is returned. 165*8269e767SBrooks DavisOn failure, -1 is returned, and 166*8269e767SBrooks Davis.Va errno 167*8269e767SBrooks Davisis set to indicate the error. 168*8269e767SBrooks Davis.Sh ERRORS 169*8269e767SBrooks DavisThe 170*8269e767SBrooks Davis.Fn semctl 171*8269e767SBrooks Davissystem call 172*8269e767SBrooks Daviswill fail if: 173*8269e767SBrooks Davis.Bl -tag -width Er 174*8269e767SBrooks Davis.It Bq Er EINVAL 175*8269e767SBrooks DavisNo semaphore set corresponds to 176*8269e767SBrooks Davis.Fa semid . 177*8269e767SBrooks Davis.It Bq Er EINVAL 178*8269e767SBrooks DavisThe 179*8269e767SBrooks Davis.Fa semnum 180*8269e767SBrooks Davisargument 181*8269e767SBrooks Davisis not in the range of valid semaphores for given semaphore set. 182*8269e767SBrooks Davis.It Bq Er EPERM 183*8269e767SBrooks DavisThe calling process's effective uid does not match the uid of 184*8269e767SBrooks Davisthe semaphore set's owner or creator. 185*8269e767SBrooks Davis.It Bq Er EACCES 186*8269e767SBrooks DavisPermission denied due to mismatch between operation and mode of 187*8269e767SBrooks Davissemaphore set. 188*8269e767SBrooks Davis.It Bq Er ERANGE 189*8269e767SBrooks Davis.Dv SETVAL 190*8269e767SBrooks Davisor 191*8269e767SBrooks Davis.Dv SETALL 192*8269e767SBrooks Davisattempted to set a semaphore outside the allowable range 193*8269e767SBrooks Davis.Bq 0 .. Dv SEMVMX . 194*8269e767SBrooks Davis.El 195*8269e767SBrooks Davis.Sh SEE ALSO 196*8269e767SBrooks Davis.Xr semget 2 , 197*8269e767SBrooks Davis.Xr semop 2 198*8269e767SBrooks Davis.Sh BUGS 199*8269e767SBrooks Davis.Dv SETALL 200*8269e767SBrooks Davismay update some semaphore elements before returning an error. 201