1.\" $NetBSD: msgctl.2,v 1.1 1995/10/16 23:49:15 jtc 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.\" $FreeBSD$ 33.\"/ 34.Dd July 9, 2020 35.Dt MSGCTL 2 36.Os 37.Sh NAME 38.Nm msgctl 39.Nd message control operations 40.Sh LIBRARY 41.Lb libc 42.Sh SYNOPSIS 43.In sys/types.h 44.In sys/ipc.h 45.In sys/msg.h 46.Ft int 47.Fn msgctl "int msqid" "int cmd" "struct msqid_ds *buf" 48.Sh DESCRIPTION 49The 50.Fn msgctl 51system call performs some control operations on the message queue specified 52by 53.Fa msqid . 54.Pp 55Each message queue has a data structure associated with it, parts of which 56may be altered by 57.Fn msgctl 58and parts of which determine the actions of 59.Fn msgctl . 60The data structure is defined in 61.In sys/msg.h 62and contains (amongst others) the following members: 63.Bd -literal 64struct msqid_ds { 65 struct ipc_perm msg_perm; /* msg queue permission bits */ 66 msglen_t msg_cbytes; /* number of bytes in use on the queue */ 67 msgqnum_t msg_qnum; /* number of msgs in the queue */ 68 msglen_t msg_qbytes; /* max # of bytes on the queue */ 69 pid_t msg_lspid; /* pid of last msgsnd() */ 70 pid_t msg_lrpid; /* pid of last msgrcv() */ 71 time_t msg_stime; /* time of last msgsnd() */ 72 time_t msg_rtime; /* time of last msgrcv() */ 73 time_t msg_ctime; /* time of last msgctl() */ 74}; 75.Ed 76.Pp 77The 78.Vt ipc_perm 79structure used inside the 80.Vt msqid_ds 81structure is defined in 82.In sys/ipc.h 83and looks like this: 84.Bd -literal 85struct ipc_perm { 86 uid_t cuid; /* creator user id */ 87 gid_t cgid; /* creator group id */ 88 uid_t uid; /* user id */ 89 gid_t gid; /* group id */ 90 mode_t mode; /* r/w permission */ 91 unsigned short seq; /* sequence # (to generate unique ipcid) */ 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. 127Values for 128.Va msg_qbytes 129that exceed the system limit (MSGMNB from 130.In sys/msg.h ) 131are silently truncated to that limit. 132.It Dv IPC_RMID 133Remove the message queue specified by 134.Fa msqid 135and destroy the data associated with it. 136Only 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 163.Rv -std msgctl 164.Sh ERRORS 165The 166.Fn msgctl 167function 168will fail if: 169.Bl -tag -width Er 170.It Bq Er EPERM 171The 172.Fa cmd 173argument 174is equal to IPC_SET or IPC_RMID and the caller is not the super-user, nor does 175the effective uid match either the 176.Va msg_perm.uid 177or 178.Va msg_perm.cuid 179fields of the data structure associated with the message queue. 180.Pp 181An attempt is made to increase the value of 182.Va msg_qbytes 183through IPC_SET 184but the caller is not the super-user. 185.It Bq Er EACCES 186The command is IPC_STAT 187and the caller has no read permission for this message queue. 188.It Bq Er EINVAL 189The 190.Fa msqid 191argument 192is not a valid message queue identifier. 193.Pp 194.Va cmd 195is not a valid command. 196.It Bq Er EFAULT 197The 198.Fa buf 199argument 200specifies an invalid address. 201.El 202.Sh SEE ALSO 203.Xr msgget 2 , 204.Xr msgrcv 2 , 205.Xr msgsnd 2 206.Sh HISTORY 207Message queues appeared in the first release of 208.At V . 209