1*8269e767SBrooks Davis.\" $NetBSD: msgctl.2,v 1.1 1995/10/16 23:49:15 jtc Exp $ 2*8269e767SBrooks Davis.\" 3*8269e767SBrooks Davis.\" Copyright (c) 1995 Frank van der Linden 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.\" 3. All advertising materials mentioning features or use of this software 15*8269e767SBrooks Davis.\" must display the following acknowledgement: 16*8269e767SBrooks Davis.\" This product includes software developed for the NetBSD Project 17*8269e767SBrooks Davis.\" by Frank van der Linden 18*8269e767SBrooks Davis.\" 4. The name of the author may not be used to endorse or promote products 19*8269e767SBrooks Davis.\" derived from this software without specific prior written permission 20*8269e767SBrooks Davis.\" 21*8269e767SBrooks Davis.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22*8269e767SBrooks Davis.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23*8269e767SBrooks Davis.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24*8269e767SBrooks Davis.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25*8269e767SBrooks Davis.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26*8269e767SBrooks Davis.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27*8269e767SBrooks Davis.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28*8269e767SBrooks Davis.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29*8269e767SBrooks Davis.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30*8269e767SBrooks Davis.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31*8269e767SBrooks Davis.\"/ 32*8269e767SBrooks Davis.Dd July 9, 2020 33*8269e767SBrooks Davis.Dt MSGCTL 2 34*8269e767SBrooks Davis.Os 35*8269e767SBrooks Davis.Sh NAME 36*8269e767SBrooks Davis.Nm msgctl 37*8269e767SBrooks Davis.Nd message control operations 38*8269e767SBrooks Davis.Sh LIBRARY 39*8269e767SBrooks Davis.Lb libc 40*8269e767SBrooks Davis.Sh SYNOPSIS 41*8269e767SBrooks Davis.In sys/types.h 42*8269e767SBrooks Davis.In sys/ipc.h 43*8269e767SBrooks Davis.In sys/msg.h 44*8269e767SBrooks Davis.Ft int 45*8269e767SBrooks Davis.Fn msgctl "int msqid" "int cmd" "struct msqid_ds *buf" 46*8269e767SBrooks Davis.Sh DESCRIPTION 47*8269e767SBrooks DavisThe 48*8269e767SBrooks Davis.Fn msgctl 49*8269e767SBrooks Davissystem call performs some control operations on the message queue specified 50*8269e767SBrooks Davisby 51*8269e767SBrooks Davis.Fa msqid . 52*8269e767SBrooks Davis.Pp 53*8269e767SBrooks DavisEach message queue has a data structure associated with it, parts of which 54*8269e767SBrooks Davismay be altered by 55*8269e767SBrooks Davis.Fn msgctl 56*8269e767SBrooks Davisand parts of which determine the actions of 57*8269e767SBrooks Davis.Fn msgctl . 58*8269e767SBrooks DavisThe data structure is defined in 59*8269e767SBrooks Davis.In sys/msg.h 60*8269e767SBrooks Davisand contains (amongst others) the following members: 61*8269e767SBrooks Davis.Bd -literal 62*8269e767SBrooks Davisstruct msqid_ds { 63*8269e767SBrooks Davis struct ipc_perm msg_perm; /* msg queue permission bits */ 64*8269e767SBrooks Davis msglen_t msg_cbytes; /* number of bytes in use on the queue */ 65*8269e767SBrooks Davis msgqnum_t msg_qnum; /* number of msgs in the queue */ 66*8269e767SBrooks Davis msglen_t msg_qbytes; /* max # of bytes on the queue */ 67*8269e767SBrooks Davis pid_t msg_lspid; /* pid of last msgsnd() */ 68*8269e767SBrooks Davis pid_t msg_lrpid; /* pid of last msgrcv() */ 69*8269e767SBrooks Davis time_t msg_stime; /* time of last msgsnd() */ 70*8269e767SBrooks Davis time_t msg_rtime; /* time of last msgrcv() */ 71*8269e767SBrooks Davis time_t msg_ctime; /* time of last msgctl() */ 72*8269e767SBrooks Davis}; 73*8269e767SBrooks Davis.Ed 74*8269e767SBrooks Davis.Pp 75*8269e767SBrooks DavisThe 76*8269e767SBrooks Davis.Vt ipc_perm 77*8269e767SBrooks Davisstructure used inside the 78*8269e767SBrooks Davis.Vt msqid_ds 79*8269e767SBrooks Davisstructure is defined in 80*8269e767SBrooks Davis.In sys/ipc.h 81*8269e767SBrooks Davisand looks like this: 82*8269e767SBrooks Davis.Bd -literal 83*8269e767SBrooks Davisstruct ipc_perm { 84*8269e767SBrooks Davis uid_t cuid; /* creator user id */ 85*8269e767SBrooks Davis gid_t cgid; /* creator group id */ 86*8269e767SBrooks Davis uid_t uid; /* user id */ 87*8269e767SBrooks Davis gid_t gid; /* group id */ 88*8269e767SBrooks Davis mode_t mode; /* r/w permission */ 89*8269e767SBrooks Davis unsigned short seq; /* sequence # (to generate unique ipcid) */ 90*8269e767SBrooks Davis key_t key; /* user specified msg/sem/shm key */ 91*8269e767SBrooks Davis}; 92*8269e767SBrooks Davis.Ed 93*8269e767SBrooks Davis.Pp 94*8269e767SBrooks DavisThe operation to be performed by 95*8269e767SBrooks Davis.Fn msgctl 96*8269e767SBrooks Davisis specified in 97*8269e767SBrooks Davis.Fa cmd 98*8269e767SBrooks Davisand is one of: 99*8269e767SBrooks Davis.Bl -tag -width IPC_RMIDX 100*8269e767SBrooks Davis.It Dv IPC_STAT 101*8269e767SBrooks DavisGather information about the message queue and place it in the 102*8269e767SBrooks Davisstructure pointed to by 103*8269e767SBrooks Davis.Fa buf . 104*8269e767SBrooks Davis.It Dv IPC_SET 105*8269e767SBrooks DavisSet the value of the 106*8269e767SBrooks Davis.Va msg_perm.uid , 107*8269e767SBrooks Davis.Va msg_perm.gid , 108*8269e767SBrooks Davis.Va msg_perm.mode 109*8269e767SBrooks Davisand 110*8269e767SBrooks Davis.Va msg_qbytes 111*8269e767SBrooks Davisfields in the structure associated with 112*8269e767SBrooks Davis.Fa msqid . 113*8269e767SBrooks DavisThe values are taken from the corresponding fields in the structure 114*8269e767SBrooks Davispointed to by 115*8269e767SBrooks Davis.Fa buf . 116*8269e767SBrooks DavisThis operation can only be executed by the super-user, or a process that 117*8269e767SBrooks Davishas an effective user id equal to either 118*8269e767SBrooks Davis.Va msg_perm.cuid 119*8269e767SBrooks Davisor 120*8269e767SBrooks Davis.Va msg_perm.uid 121*8269e767SBrooks Davisin the data structure associated with the message queue. 122*8269e767SBrooks DavisThe value of 123*8269e767SBrooks Davis.Va msg_qbytes 124*8269e767SBrooks Daviscan only be increased by the super-user. 125*8269e767SBrooks DavisValues for 126*8269e767SBrooks Davis.Va msg_qbytes 127*8269e767SBrooks Davisthat exceed the system limit (MSGMNB from 128*8269e767SBrooks Davis.In sys/msg.h ) 129*8269e767SBrooks Davisare silently truncated to that limit. 130*8269e767SBrooks Davis.It Dv IPC_RMID 131*8269e767SBrooks DavisRemove the message queue specified by 132*8269e767SBrooks Davis.Fa msqid 133*8269e767SBrooks Davisand destroy the data associated with it. 134*8269e767SBrooks DavisOnly the super-user or a process 135*8269e767SBrooks Daviswith an effective uid equal to the 136*8269e767SBrooks Davis.Va msg_perm.cuid 137*8269e767SBrooks Davisor 138*8269e767SBrooks Davis.Va msg_perm.uid 139*8269e767SBrooks Davisvalues in the data structure associated with the queue can do this. 140*8269e767SBrooks Davis.El 141*8269e767SBrooks Davis.Pp 142*8269e767SBrooks DavisThe permission to read from or write to a message queue (see 143*8269e767SBrooks Davis.Xr msgsnd 2 144*8269e767SBrooks Davisand 145*8269e767SBrooks Davis.Xr msgrcv 2 ) 146*8269e767SBrooks Davisis determined by the 147*8269e767SBrooks Davis.Va msg_perm.mode 148*8269e767SBrooks Davisfield in the same way as is 149*8269e767SBrooks Davisdone with files (see 150*8269e767SBrooks Davis.Xr chmod 2 ) , 151*8269e767SBrooks Davisbut the effective uid can match either the 152*8269e767SBrooks Davis.Va msg_perm.cuid 153*8269e767SBrooks Davisfield or the 154*8269e767SBrooks Davis.Va msg_perm.uid 155*8269e767SBrooks Davisfield, and the 156*8269e767SBrooks Daviseffective gid can match either 157*8269e767SBrooks Davis.Va msg_perm.cgid 158*8269e767SBrooks Davisor 159*8269e767SBrooks Davis.Va msg_perm.gid . 160*8269e767SBrooks Davis.Sh RETURN VALUES 161*8269e767SBrooks Davis.Rv -std msgctl 162*8269e767SBrooks Davis.Sh ERRORS 163*8269e767SBrooks DavisThe 164*8269e767SBrooks Davis.Fn msgctl 165*8269e767SBrooks Davisfunction 166*8269e767SBrooks Daviswill fail if: 167*8269e767SBrooks Davis.Bl -tag -width Er 168*8269e767SBrooks Davis.It Bq Er EPERM 169*8269e767SBrooks DavisThe 170*8269e767SBrooks Davis.Fa cmd 171*8269e767SBrooks Davisargument 172*8269e767SBrooks Davisis equal to IPC_SET or IPC_RMID and the caller is not the super-user, nor does 173*8269e767SBrooks Davisthe effective uid match either the 174*8269e767SBrooks Davis.Va msg_perm.uid 175*8269e767SBrooks Davisor 176*8269e767SBrooks Davis.Va msg_perm.cuid 177*8269e767SBrooks Davisfields of the data structure associated with the message queue. 178*8269e767SBrooks Davis.Pp 179*8269e767SBrooks DavisAn attempt is made to increase the value of 180*8269e767SBrooks Davis.Va msg_qbytes 181*8269e767SBrooks Davisthrough IPC_SET 182*8269e767SBrooks Davisbut the caller is not the super-user. 183*8269e767SBrooks Davis.It Bq Er EACCES 184*8269e767SBrooks DavisThe command is IPC_STAT 185*8269e767SBrooks Davisand the caller has no read permission for this message queue. 186*8269e767SBrooks Davis.It Bq Er EINVAL 187*8269e767SBrooks DavisThe 188*8269e767SBrooks Davis.Fa msqid 189*8269e767SBrooks Davisargument 190*8269e767SBrooks Davisis not a valid message queue identifier. 191*8269e767SBrooks Davis.Pp 192*8269e767SBrooks Davis.Va cmd 193*8269e767SBrooks Davisis not a valid command. 194*8269e767SBrooks Davis.It Bq Er EFAULT 195*8269e767SBrooks DavisThe 196*8269e767SBrooks Davis.Fa buf 197*8269e767SBrooks Davisargument 198*8269e767SBrooks Davisspecifies an invalid address. 199*8269e767SBrooks Davis.El 200*8269e767SBrooks Davis.Sh SEE ALSO 201*8269e767SBrooks Davis.Xr msgget 2 , 202*8269e767SBrooks Davis.Xr msgrcv 2 , 203*8269e767SBrooks Davis.Xr msgsnd 2 204*8269e767SBrooks Davis.Sh HISTORY 205*8269e767SBrooks DavisMessage queues appeared in the first release of 206*8269e767SBrooks Davis.At V . 207