]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/msgctl.2
pow.3: Minor tweak to BUGS
[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 .\" %%%LICENSE_START(VERBATIM)
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date. The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein. The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\" %%%LICENSE_END
25 .\"
26 .\" Modified Tue Oct 22 08:11:14 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
27 .\" Modified Sun Feb 18 01:59:29 2001 by Andries E. Brouwer <aeb@cwi.nl>
28 .\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
29 .\" Added notes on CAP_IPC_OWNER requirement
30 .\" Modified, 17 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com>
31 .\" Added notes on CAP_SYS_ADMIN requirement for IPC_SET and IPC_RMID
32 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
33 .\" Language and formatting clean-ups
34 .\" Added msqid_ds and ipc_perm structure definitions
35 .\" 2005-08-02, mtk: Added IPC_INFO, MSG_INFO, MSG_STAT descriptions
36 .\" 2018-03-20, dbueso: Added MSG_STAT_ANY description.
37 .\"
38 .TH MSGCTL 2 2020-04-11 "Linux" "Linux Programmer's Manual"
39 .SH NAME
40 msgctl \- System V message control operations
41 .SH SYNOPSIS
42 .nf
43 .B #include <sys/types.h>
44 .B #include <sys/ipc.h>
45 .B #include <sys/msg.h>
46 .PP
47 .BI "int msgctl(int " msqid ", int " cmd ", struct msqid_ds *" buf );
48 .fi
49 .SH DESCRIPTION
50 .BR msgctl ()
51 performs the control operation specified by
52 .I cmd
53 on the System\ V message queue with identifier
54 .IR msqid .
55 .PP
56 The
57 .I msqid_ds
58 data structure is defined in \fI<sys/msg.h>\fP as follows:
59 .PP
60 .in +4n
61 .EX
62 struct msqid_ds {
63 struct ipc_perm msg_perm; /* Ownership and permissions */
64 time_t msg_stime; /* Time of last msgsnd(2) */
65 time_t msg_rtime; /* Time of last msgrcv(2) */
66 time_t msg_ctime; /* Creation time/time of last
67 modification via msgctl() */
68 unsigned long __msg_cbytes; /* Current number of bytes in
69 queue (nonstandard) */
70 msgqnum_t msg_qnum; /* Current number of messages
71 in queue */
72 msglen_t msg_qbytes; /* Maximum number of bytes
73 allowed in queue */
74 pid_t msg_lspid; /* PID of last msgsnd(2) */
75 pid_t msg_lrpid; /* PID of last msgrcv(2) */
76 };
77 .EE
78 .in
79 .PP
80 The fields of the
81 .I msgid_ds
82 structure are as follows:
83 .TP 11
84 .I msg_perm
85 This is an
86 .I ipc_perm
87 structure (see below) that specifies the access permissions on the message
88 queue.
89 .TP
90 .I msg_qnum
91 Number of messages currently on the message queue.
92 .TP
93 .I msg_qbytes
94 Maximum number of bytes of message text allowed on the message
95 queue.
96 .TP
97 .I msg_lspid
98 ID of the process that performed the last
99 .BR msgsnd (2)
100 system call.
101 .TP
102 .I msg_lrpid
103 ID of the process that performed the last
104 .BR msgrcv (2)
105 system call.
106 .TP
107 .I msg_stime
108 Time of the last
109 .BR msgsnd (2)
110 system call.
111 .TP
112 .I msg_rtime
113 Time of the last
114 .BR msgrcv (2)
115 system call.
116 .TP
117 .I msg_ctime
118 Time of creation of queue or time of last
119 .BR msgctl ()
120 .BR IPC_SET
121 operation.
122 .PP
123 The
124 .I ipc_perm
125 structure is defined as follows
126 (the highlighted fields are settable using
127 .BR IPC_SET ):
128 .PP
129 .in +4n
130 .EX
131 struct ipc_perm {
132 key_t __key; /* Key supplied to msgget(2) */
133 uid_t \fBuid\fP; /* Effective UID of owner */
134 gid_t \fBgid\fP; /* Effective GID of owner */
135 uid_t cuid; /* Effective UID of creator */
136 gid_t cgid; /* Effective GID of creator */
137 unsigned short \fBmode\fP; /* Permissions */
138 unsigned short __seq; /* Sequence number */
139 };
140 .EE
141 .in
142 .PP
143 The least significant 9 bits of the
144 .I mode
145 field of the
146 .I ipc_perm
147 structure define the access permissions for the message queue.
148 The permission bits are as follows:
149 .TS
150 l l.
151 0400 Read by user
152 0200 Write by user
153 0040 Read by group
154 0020 Write by group
155 0004 Read by others
156 0002 Write by others
157 .TE
158 .PP
159 Bits 0100, 0010, and 0001 (the execute bits) are unused by the system.
160 .PP
161 Valid values for
162 .I cmd
163 are:
164 .TP
165 .B IPC_STAT
166 Copy information from the kernel data structure associated with
167 .I msqid
168 into the
169 .I msqid_ds
170 structure pointed to by
171 .IR buf .
172 The caller must have read permission on the message queue.
173 .TP
174 .B IPC_SET
175 Write the values of some members of the
176 .I msqid_ds
177 structure pointed to by
178 .I buf
179 to the kernel data structure associated with this message queue,
180 updating also its
181 .I msg_ctime
182 member.
183 The following members of the structure are updated:
184 .IR msg_qbytes ,
185 .IR msg_perm.uid ,
186 .IR msg_perm.gid ,
187 and (the least significant 9 bits of)
188 .IR msg_perm.mode .
189 The effective UID of the calling process must match the owner
190 .RI ( msg_perm.uid )
191 or creator
192 .RI ( msg_perm.cuid )
193 of the message queue, or the caller must be privileged.
194 Appropriate privilege (Linux: the
195 .B CAP_SYS_RESOURCE
196 capability) is required to raise the
197 .I msg_qbytes
198 value beyond the system parameter
199 .BR MSGMNB .
200 .TP
201 .B IPC_RMID
202 Immediately remove the message queue,
203 awakening all waiting reader and writer processes (with an error
204 return and
205 .I errno
206 set to
207 .BR EIDRM ).
208 The calling process must have appropriate privileges
209 or its effective user ID must be either that of the creator or owner
210 of the message queue.
211 The third argument to
212 .BR msgctl ()
213 is ignored in this case.
214 .TP
215 .BR IPC_INFO " (Linux-specific)"
216 Return information about system-wide message queue limits and
217 parameters in the structure pointed to by
218 .IR buf .
219 This structure is of type
220 .I msginfo
221 (thus, a cast is required),
222 defined in
223 .I <sys/msg.h>
224 if the
225 .B _GNU_SOURCE
226 feature test macro is defined:
227 .IP
228 .in +4n
229 .EX
230 struct msginfo {
231 int msgpool; /* Size in kibibytes of buffer pool
232 used to hold message data;
233 unused within kernel */
234 int msgmap; /* Maximum number of entries in message
235 map; unused within kernel */
236 int msgmax; /* Maximum number of bytes that can be
237 written in a single message */
238 int msgmnb; /* Maximum number of bytes that can be
239 written to queue; used to initialize
240 msg_qbytes during queue creation
241 (msgget(2)) */
242 int msgmni; /* Maximum number of message queues */
243 int msgssz; /* Message segment size;
244 unused within kernel */
245 int msgtql; /* Maximum number of messages on all queues
246 in system; unused within kernel */
247 unsigned short int msgseg;
248 /* Maximum number of segments;
249 unused within kernel */
250 };
251 .EE
252 .in
253 .IP
254 The
255 .IR msgmni ,
256 .IR msgmax ,
257 and
258 .I msgmnb
259 settings can be changed via
260 .I /proc
261 files of the same name; see
262 .BR proc (5)
263 for details.
264 .TP
265 .BR MSG_INFO " (Linux-specific)"
266 Return a
267 .I msginfo
268 structure containing the same information as for
269 .BR IPC_INFO ,
270 except that the following fields are returned with information
271 about system resources consumed by message queues: the
272 .I msgpool
273 field returns the number of message queues that currently exist
274 on the system; the
275 .I msgmap
276 field returns the total number of messages in all queues
277 on the system; and the
278 .I msgtql
279 field returns the total number of bytes in all messages
280 in all queues on the system.
281 .TP
282 .BR MSG_STAT " (Linux-specific)"
283 Return a
284 .I msqid_ds
285 structure as for
286 .BR IPC_STAT .
287 However, the
288 .I msqid
289 argument is not a queue identifier, but instead an index into
290 the kernel's internal array that maintains information about
291 all message queues on the system.
292 .TP
293 .BR MSG_STAT_ANY " (Linux-specific, since Linux 4.17)"
294 Return a
295 .I msqid_ds
296 structure as for
297 .BR MSG_STAT .
298 However,
299 .I msg_perm.mode
300 is not checked for read access for
301 .IR msqid
302 meaning that any user can employ this operation (just as any user may read
303 .IR /proc/sysvipc/msg
304 to obtain the same information).
305 .SH RETURN VALUE
306 On success,
307 .BR IPC_STAT ,
308 .BR IPC_SET ,
309 and
310 .B IPC_RMID
311 return 0.
312 A successful
313 .B IPC_INFO
314 or
315 .B MSG_INFO
316 operation returns the index of the highest used entry in the
317 kernel's internal array recording information about all
318 message queues.
319 (This information can be used with repeated
320 .B MSG_STAT
321 or
322 .B MSG_STAT_ANY
323 operations to obtain information about all queues on the system.)
324 A successful
325 .B MSG_STAT
326 or
327 .B MSG_STAT_ANY
328 operation returns the identifier of the queue whose index was given in
329 .IR msqid .
330 .PP
331 On error, \-1 is returned with
332 .I errno
333 indicating the error.
334 .SH ERRORS
335 On failure,
336 .I errno
337 is set to one of the following:
338 .TP
339 .B EACCES
340 The argument
341 .I cmd
342 is equal to
343 .B IPC_STAT
344 or
345 .BR MSG_STAT ,
346 but the calling process does not have read permission on the message queue
347 .IR msqid ,
348 and does not have the
349 .B CAP_IPC_OWNER
350 capability in the user namespace that governs its IPC namespace.
351 .TP
352 .B EFAULT
353 The argument
354 .I cmd
355 has the value
356 .B IPC_SET
357 or
358 .BR IPC_STAT ,
359 but the address pointed to by
360 .I buf
361 isn't accessible.
362 .TP
363 .B EIDRM
364 The message queue was removed.
365 .TP
366 .B EINVAL
367 Invalid value for
368 .I cmd
369 or
370 .IR msqid .
371 Or: for a
372 .B MSG_STAT
373 operation, the index value specified in
374 .I msqid
375 referred to an array slot that is currently unused.
376 .TP
377 .B EPERM
378 The argument
379 .I cmd
380 has the value
381 .B IPC_SET
382 or
383 .BR IPC_RMID ,
384 but the effective user ID of the calling process is not the creator
385 (as found in
386 .IR msg_perm.cuid )
387 or the owner
388 (as found in
389 .IR msg_perm.uid )
390 of the message queue,
391 and the caller is not privileged (Linux: does not have the
392 .B CAP_SYS_ADMIN
393 capability).
394 .TP
395 .B EPERM
396 An attempt
397 .RB ( IPC_SET )
398 was made to increase
399 .I msg_qbytes
400 beyond the system parameter
401 .BR MSGMNB ,
402 but the caller is not privileged (Linux: does not have the
403 .B CAP_SYS_RESOURCE
404 capability).
405 .SH CONFORMING TO
406 POSIX.1-2001, POSIX.1-2008, SVr4.
407 .\" SVID does not document the EIDRM error condition.
408 .SH NOTES
409 The inclusion of
410 .I <sys/types.h>
411 and
412 .I <sys/ipc.h>
413 isn't required on Linux or by any version of POSIX.
414 However,
415 some old implementations required the inclusion of these header files,
416 and the SVID also documented their inclusion.
417 Applications intended to be portable to such old systems may need
418 to include these header files.
419 .\" Like Linux, the FreeBSD man pages still document
420 .\" the inclusion of these header files.
421 .PP
422 The
423 .BR IPC_INFO ,
424 .B MSG_STAT
425 and
426 .B MSG_INFO
427 operations are used by the
428 .BR ipcs (1)
429 program to provide information on allocated resources.
430 In the future these may modified or moved to a
431 .I /proc
432 filesystem interface.
433 .PP
434 Various fields in the \fIstruct msqid_ds\fP were
435 typed as
436 .I short
437 under Linux 2.2
438 and have become
439 .I long
440 under Linux 2.4.
441 To take advantage of this,
442 a recompilation under glibc-2.1.91 or later should suffice.
443 (The kernel distinguishes old and new calls by an
444 .B IPC_64
445 flag in
446 .IR cmd .)
447 .SH SEE ALSO
448 .BR msgget (2),
449 .BR msgrcv (2),
450 .BR msgsnd (2),
451 .BR capabilities (7),
452 .BR mq_overview (7),
453 .BR sysvipc (7)