xref: /netbsd-src/lib/libc/sys/msgctl.2 (revision 76dfffe33547c37f8bdd446e3e4ab0f3c16cea4b)
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.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
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
73The
74.Bf -literal
75ipc_perm
76.Ef
77structure used inside the
78.Bf -literal
79shmid_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
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 (MSGMNB from
129.Aq Pa sys/msg.h )
130are silently truncated to that limit.
131
132.It Dv IPC_RMID
133Remove the message queue specified by
134.Fa msqid
135and destroy the data associated with it. Only the super-user or a process
136with an effective uid equal to the
137.Va msg_perm.cuid
138or
139.Va msg_perm.uid
140values in the data structure associated with the queue can do this.
141.El
142
143The permission to read from or write to a message queue (see
144.Xr msgsnd 2
145and
146.Xr msgrcv 2 )
147is determined by the
148.Va msg_perm.mode
149field in the same way as is
150done with files (see
151.Xr chmod 2 ),
152but the effective uid can match either the
153.Va msg_perm.cuid
154field or the
155.Va msg_perm.uid
156field, and the
157effective gid can match either
158.Va msg_perm.cgid
159or
160.Va msg_perm.gid .
161.Sh RETURN VALUES
162Upon successful completion, a value of 0 is returned. Otherwise, -1 is
163returned and the global variable
164.Va errno
165is set to indicate the error.
166.Sh ERRORS
167.Fn msgctl
168will fail if:
169.Bl -tag -width Er
170.It Bq Er EPERM
171.Fa cmd
172is equal to IPC_SET or IPC_RMID and the caller is not the super-user, nor does
173the effective uid match either the
174.Va msg_perm.uid
175or
176.Va msg_perm.cuid
177fields of the data structure associated with the message queue.
178
179An attempt is made to increase the value of
180.Va msg_qbytes
181through IPC_SET
182but the caller is not the super-user.
183.It Bq Er EACCESS
184The command is IPC_STAT
185and the caller has no read permission for this message queue.
186.It Bq Er EINVAL
187.Fa msqid
188is not a valid message queue identifier.
189
190.Va cmd
191is not a valid command.
192.It Bq Er EFAULT
193.Fa buf
194specifies an invalid address.
195.El
196.Sh SEE ALSO
197.Xr msgsnd 2 ,
198.Xr msgrcv 2 ,
199.Xr msgget 2
200.Sh HISTORY
201Message queues appeared in the first release of AT&T Unix System V.
202