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