]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/msgctl.2
Clarify that "unused" fields in msginfo structure are
[thirdparty/man-pages.git] / man2 / msgctl.2
1 .\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it)
2 .\" and Copyright 2004, 2005 Michael Kerrisk <mtk.manpages@gmail.com>
3 .\"
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\"
24 .\" Modified Tue Oct 22 08:11:14 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
25 .\" Modified Sun Feb 18 01:59:29 2001 by Andries E. Brouwer <aeb@cwi.nl>
26 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
27 .\" Added notes on CAP_IPC_OWNER requirement
28 .\" Modified, 17 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com>
29 .\" Added notes on CAP_SYS_ADMIN requirement for IPC_SET and IPC_RMID
30 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
31 .\" Language and formatting clean-ups
32 .\" Added msqid_ds and ipc_perm structure definitions
33 .\" 2005-08-02, mtk: Added IPC_INFO, MSG_INFO, MSG_STAT descriptions
34 .\"
35 .TH MSGCTL 2 2008-05-20 "Linux" "Linux Programmer's Manual"
36 .SH NAME
37 msgctl \- message control operations
38 .SH SYNOPSIS
39 .nf
40 .B
41 #include <sys/types.h>
42 .B
43 #include <sys/ipc.h>
44 .B
45 #include <sys/msg.h>
46 .fi
47 .sp
48 .BI "int msgctl(int " msqid ,
49 .BI "int " cmd ,
50 .BI "struct msqid_ds *" buf );
51 .SH DESCRIPTION
52 .BR msgctl ()
53 performs the control operation specified by
54 .I cmd
55 on the message queue with identifier
56 .IR msqid .
57 .PP
58 The
59 .I msqid_ds
60 data structure is defined in \fI<sys/msg.h>\fP as follows:
61 .nf
62 .in +4n
63
64 struct msqid_ds {
65 struct ipc_perm msg_perm; /* Ownership and permissions */
66 time_t msg_stime; /* Time of last msgsnd(2) */
67 time_t msg_rtime; /* Time of last msgrcv(2) */
68 time_t msg_ctime; /* Time of last change */
69 unsigned long __msg_cbytes; /* Current number of bytes in
70 queue (non-standard) */
71 msgqnum_t msg_qnum; /* Current number of messages
72 in queue */
73 msglen_t msg_qbytes; /* Maximum number of bytes
74 allowed in queue */
75 pid_t msg_lspid; /* PID of last msgsnd(2) */
76 pid_t msg_lrpid; /* PID of last msgrcv(2) */
77 };
78 .in
79 .fi
80 .PP
81 The
82 .I ipc_perm
83 structure is defined in \fI<sys/ipc.h>\fP as follows
84 (the highlighted fields are settable using
85 .BR IPC_SET ):
86 .PP
87 .nf
88 .in +4n
89 struct ipc_perm {
90 key_t key; /* Key supplied to msgget(2) */
91 uid_t \fBuid\fP; /* Effective UID of owner */
92 gid_t \fBgid\fP; /* Effective GID of owner */
93 uid_t cuid; /* Effective UID of creator */
94 gid_t cgid; /* Effective GID of creator */
95 unsigned short \fBmode\fP; /* Permissions */
96 unsigned short seq; /* Sequence number */
97 };
98 .in
99 .fi
100 .PP
101 Valid values for
102 .I cmd
103 are:
104 .TP
105 .B IPC_STAT
106 Copy information from the kernel data structure associated with
107 .I msqid
108 into the
109 .I msqid_ds
110 structure pointed to by
111 .IR buf .
112 The caller must have read permission on the message queue.
113 .TP
114 .B IPC_SET
115 Write the values of some members of the
116 .I msqid_ds
117 structure pointed to by
118 .I buf
119 to the kernel data structure associated with this message queue,
120 updating also its
121 .I msg_ctime
122 member.
123 The following members of the structure are updated:
124 .IR msg_qbytes ,
125 .IR msg_perm.uid ,
126 .IR msg_perm.gid ,
127 and (the least significant 9 bits of)
128 .IR msg_perm.mode .
129 The effective UID of the calling process must match the owner
130 .RI ( msg_perm.uid )
131 or creator
132 .RI ( msg_perm.cuid )
133 of the message queue, or the caller must be privileged.
134 Appropriate privilege (Linux: the
135 .B CAP_IPC_RESOURCE
136 capability) is required to raise the
137 .I msg_qbytes
138 value beyond the system parameter
139 .BR MSGMNB .
140 .TP
141 .B IPC_RMID
142 Immediately remove the message queue,
143 awakening all waiting reader and writer processes (with an error
144 return and
145 .I errno
146 set to
147 .BR EIDRM ).
148 The calling process must have appropriate privileges
149 or its effective user ID must be either that of the creator or owner
150 of the message queue.
151 .TP
152 .BR IPC_INFO " (Linux-specific)"
153 Returns information about system-wide message queue limits and
154 parameters in the structure pointed to by
155 .IR buf .
156 This structure is of type
157 .I msginfo
158 (thus, a cast is required),
159 defined in
160 .I <sys/msg.h>
161 if the
162 .B _GNU_SOURCE
163 feature test macro is defined:
164 .nf
165 .in +4n
166
167 struct msginfo {
168 int msgpool; /* Size in kibibytes of buffer pool
169 used to hold message data;
170 unused within kernel */
171 int msgmap; /* Maximum number of entries in message
172 map; unused within kernel */
173 int msgmax; /* Maximum number of bytes that can be
174 written in a single message */
175 int msgmnb; /* Maximum number of bytes that can be
176 written to queue; used to initialize
177 msg_qbytes during queue creation
178 (msgget(2)) */
179 int msgmni; /* Maximum number of message queues */
180 int msgssz; /* Message segment size;
181 unused within kernel */
182 int msgtql; /* Maximum number of messages on all queues
183 in system; unused within kernel */
184 unsigned short int msgseg;
185 /* Maximum number of segments;
186 unused within kernel */
187 };
188
189 .in
190 .fi
191 The
192 .IR msgmni ,
193 .IR msgmax ,
194 and
195 .I msgmnb
196 settings can be changed via
197 .I /proc
198 files of the same name; see
199 .BR proc (5)
200 for details.
201 .TP
202 .BR MSG_INFO " (Linux-specific)"
203 Returns a
204 .I msginfo
205 structure containing the same information as for
206 .BR IPC_INFO ,
207 except that the following fields are returned with information
208 about system resources consumed by message queues: the
209 .I msgpool
210 field returns the number of message queues that currently exist
211 on the system; the
212 .I msgmap
213 field returns the total number of messages in all queues
214 on the system; and the
215 .I msgtql
216 field returns the total number of bytes in all messages
217 in all queues on the system.
218 .TP
219 .BR MSG_STAT " (Linux-specific)"
220 Returns a
221 .I msqid_ds
222 structure as for
223 .BR IPC_STAT .
224 However, the
225 .I msqid
226 argument is not a queue identifier, but instead an index into
227 the kernel's internal array that maintains information about
228 all message queues on the system.
229 .SH "RETURN VALUE"
230 On success,
231 .BR IPC_STAT ,
232 .BR IPC_SET ,
233 and
234 .B IPC_RMID
235 return 0.
236 A successful
237 .B IPC_INFO
238 or
239 .B MSG_INFO
240 operation returns the index of the highest used entry in the
241 kernel's internal array recording information about all
242 message queues.
243 (This information can be used with repeated
244 .B MSG_STAT
245 operations to obtain information about all queues on the system.)
246 A successful
247 .B MSG_STAT
248 operation returns the identifier of the queue whose index was given in
249 .IR msqid .
250
251 On error, \-1 is returned with
252 .I errno
253 indicating the error.
254 .SH ERRORS
255 On failure,
256 .I errno
257 is set to one of the following:
258 .TP 11
259 .B EACCES
260 The argument
261 .I cmd
262 is equal to
263 .B IPC_STAT
264 or
265 .BR MSG_STAT ,
266 but the calling process does not have read permission on the message queue
267 .IR msqid ,
268 and does not have the
269 .B CAP_IPC_OWNER
270 capability.
271 .TP
272 .B EFAULT
273 The argument
274 .I cmd
275 has the value
276 .B IPC_SET
277 or
278 .BR IPC_STAT ,
279 but the address pointed to by
280 .I buf
281 isn't accessible.
282 .TP
283 .B EIDRM
284 The message queue was removed.
285 .TP
286 .B EINVAL
287 Invalid value for
288 .I cmd
289 or
290 .IR msqid .
291 Or: for a
292 .B MSG_STAT
293 operation, the index value specified in
294 .I msqid
295 referred to an array slot that is currently unused.
296 .TP
297 .B EPERM
298 The argument
299 .I cmd
300 has the value
301 .B IPC_SET
302 or
303 .BR IPC_RMID ,
304 but the effective user ID of the calling process is not the creator
305 (as found in
306 .IR msg_perm.cuid )
307 or the owner
308 (as found in
309 .IR msg_perm.uid )
310 of the message queue,
311 and the process is not privileged (Linux: it does not have the
312 .B CAP_SYS_ADMIN
313 capability).
314 .SH "CONFORMING TO"
315 SVr4, POSIX.1-2001.
316 .\" SVID does not document the EIDRM error condition.
317 .SH NOTES
318 The
319 .BR IPC_INFO ,
320 .B MSG_STAT
321 and
322 .B MSG_INFO
323 operations are used by the
324 .BR ipcs (8)
325 program to provide information on allocated resources.
326 In the future these may modified or moved to a /proc file system
327 interface.
328
329 Various fields in the \fIstruct msqid_ds\fP were
330 typed as
331 .I short
332 under Linux 2.2
333 and have become
334 .I long
335 under Linux 2.4.
336 To take advantage of this,
337 a recompilation under glibc-2.1.91 or later should suffice.
338 (The kernel distinguishes old and new calls by an
339 .B IPC_64
340 flag in
341 .IR cmd .)
342 .SH "SEE ALSO"
343 .BR msgget (2),
344 .BR msgrcv (2),
345 .BR msgsnd (2),
346 .BR capabilities (7),
347 .BR mq_overview (7),
348 .BR svipc (7)