1.\" $OpenBSD: msgctl.2,v 1.11 2000/10/18 05:12:10 aaron Exp $ 2.\" $NetBSD: msgctl.2,v 1.2 1997/03/27 08:20:35 mikel Exp $ 3.\" 4.\" Copyright (c) 1995 Frank van der Linden 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. All advertising materials mentioning features or use of this software 16.\" must display the following acknowledgement: 17.\" This product includes software developed for the NetBSD Project 18.\" by Frank van der Linden 19.\" 4. The name of the author may not be used to endorse or promote products 20.\" derived from this software without specific prior written permission 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32.\"/ 33.Dd August 17, 1995 34.Dt MSGCTL 2 35.Os 36.Sh NAME 37.Nm msgctl 38.Nd message control operations 39.Sh SYNOPSIS 40.Fd #include <sys/types.h> 41.Fd #include <sys/ipc.h> 42.Fd #include <sys/msg.h> 43.Ft int 44.Fn msgctl "int msqid" "int cmd" "struct msqid_ds *buf" 45.Sh DESCRIPTION 46The 47.Fn msgctl 48system call performs some control operations on the message queue specified 49by 50.Fa msqid . 51.Pp 52Each message queue has a data structure associated with it, parts of which 53may be altered by 54.Fn msgctl 55and parts of which determine the actions of 56.Fn msgctl . 57The data structure is defined in 58.Aq Pa sys/msg.h 59and contains (amongst others) the following members: 60.Bd -literal 61struct msqid_ds { 62 struct ipc_perm msg_perm; /* msg queue permission bits */ 63 u_long msg_cbytes; /* # of bytes in use on the queue */ 64 u_long msg_qnum; /* # of msgs in the queue */ 65 u_long msg_qbytes; /* max # of bytes on the queue */ 66 pid_t msg_lspid; /* pid of last msgsnd() */ 67 pid_t msg_lrpid; /* pid of last msgrcv() */ 68 time_t msg_stime; /* time of last msgsnd() */ 69 time_t msg_rtime; /* time of last msgrcv() */ 70 time_t msg_ctime; /* time of last msgctl() */ 71}; 72.Ed 73.Pp 74The 75.Bf -literal 76ipc_perm 77.Ef 78structure used inside the 79.Bf -literal 80shmid_ds 81.Ef 82structure is defined in 83.Aq Pa sys/ipc.h 84and looks like this: 85.Bd -literal 86struct ipc_perm { 87 uid_t cuid; /* creator user id */ 88 gid_t cgid; /* creator group id */ 89 uid_t uid; /* user id */ 90 gid_t gid; /* group id */ 91 mode_t mode; /* permission (9 bits, see chmod(2)) */ 92 u_short seq; /* sequence # (to generate unique id) */ 93 key_t key; /* user specified msg/sem/shm key */ 94}; 95.Ed 96.Pp 97The operation to be performed by 98.Fn msgctl 99is specified in 100.Fa cmd 101and is one of: 102.Bl -tag -width IPC_RMIDX 103.It Dv IPC_STAT 104Gather information about the message queue and place it in the 105structure pointed to by 106.Fa buf . 107.It Dv IPC_SET 108Set the value of the 109.Va msg_perm.uid , 110.Va msg_perm.gid , 111.Va msg_perm.mode 112and 113.Va msg_qbytes 114fields in the structure associated with 115.Fa msqid . 116The values are taken from the corresponding fields in the structure 117pointed to by 118.Fa buf . 119This operation can only be executed by the superuser, or a process that 120has an effective user ID equal to either 121.Va msg_perm.cuid 122or 123.Va msg_perm.uid 124in the data structure associated with the message queue. 125The value of 126.Va msg_qbytes 127can only be increased by the superuser. 128Values for 129.Va msg_qbytes 130that exceed the system limit 131.Pf ( Dv MSGMNB 132from 133.Aq Pa sys/msg.h ) 134are silently truncated to that limit. 135.Pp 136.It Dv IPC_RMID 137Remove the message queue specified by 138.Fa msqid 139and destroy the data associated with it. 140Only the superuser or a process with an effective UID equal to the 141.Va msg_perm.cuid 142or 143.Va msg_perm.uid 144values in the data structure associated with the queue can do this. 145.El 146.Pp 147The permission to read from or write to a message queue (see 148.Xr msgsnd 2 149and 150.Xr msgrcv 2 ) 151is determined by the 152.Va msg_perm.mode 153field in the same way as is 154done with files (see 155.Xr chmod 2 ) , 156but the effective UID can match either the 157.Va msg_perm.cuid 158field or the 159.Va msg_perm.uid 160field, and the 161effective GID can match either 162.Va msg_perm.cgid 163or 164.Va msg_perm.gid . 165.Sh RETURN VALUES 166Upon successful completion, a value of 0 is returned. 167Otherwise, \-1 is returned and the global variable 168.Va errno 169is set to indicate the error. 170.Sh ERRORS 171.Fn msgctl 172will fail if: 173.Bl -tag -width Er 174.It Bq Er EPERM 175.Fa cmd 176is equal to 177.Dv IPC_SET 178or 179.Dv IPC_RMID 180and the caller is not the superuser, nor does 181the effective UID match either the 182.Va msg_perm.uid 183or 184.Va msg_perm.cuid 185fields of the data structure associated with the message queue. 186.Pp 187An attempt is made to increase the value of 188.Va msg_qbytes 189through 190.Dv IPC_SET 191but the caller is not the superuser. 192.It Bq Er EACCES 193The command is 194.Dv IPC_STAT 195and the caller has no read permission for this message queue. 196.It Bq Er EINVAL 197.Fa msqid 198is not a valid message queue identifier. 199.Pp 200.Va cmd 201is not a valid command. 202.It Bq Er EFAULT 203.Fa buf 204specifies an invalid address. 205.El 206.Sh SEE ALSO 207.Xr msgget 2 , 208.Xr msgrcv 2 , 209.Xr msgsnd 2 210.Sh HISTORY 211Message queues appeared in the first release of AT&T Unix System V. 212