]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/msgctl.2
intro.1, _exit.2, access.2, alarm.2, alloc_hugepages.2, arch_prctl.2, bind.2, chdir...
[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 .\"
37 .TH MSGCTL 2 2012-05-31 "Linux" "Linux Programmer's Manual"
38 .SH NAME
39 msgctl \- message control operations
40 .SH SYNOPSIS
41 .nf
42 .B #include <sys/types.h>
43 .B #include <sys/ipc.h>
44 .B #include <sys/msg.h>
45
46 .BI "int msgctl(int " msqid ", int " cmd ", struct msqid_ds *" buf );
47 .fi
48 .SH DESCRIPTION
49 .BR msgctl ()
50 performs the control operation specified by
51 .I cmd
52 on the message queue with identifier
53 .IR msqid .
54 .PP
55 The
56 .I msqid_ds
57 data structure is defined in \fI<sys/msg.h>\fP as follows:
58 .nf
59 .in +4n
60
61 struct msqid_ds {
62 struct ipc_perm msg_perm; /* Ownership and permissions */
63 time_t msg_stime; /* Time of last msgsnd(2) */
64 time_t msg_rtime; /* Time of last msgrcv(2) */
65 time_t msg_ctime; /* Time of last change */
66 unsigned long __msg_cbytes; /* Current number of bytes in
67 queue (nonstandard) */
68 msgqnum_t msg_qnum; /* Current number of messages
69 in queue */
70 msglen_t msg_qbytes; /* Maximum number of bytes
71 allowed in queue */
72 pid_t msg_lspid; /* PID of last msgsnd(2) */
73 pid_t msg_lrpid; /* PID of last msgrcv(2) */
74 };
75 .in
76 .fi
77 .PP
78 The
79 .I ipc_perm
80 structure is defined as follows
81 (the highlighted fields are settable using
82 .BR IPC_SET ):
83 .PP
84 .nf
85 .in +4n
86 struct ipc_perm {
87 key_t __key; /* Key supplied to msgget(2) */
88 uid_t \fBuid\fP; /* Effective UID of owner */
89 gid_t \fBgid\fP; /* Effective GID of owner */
90 uid_t cuid; /* Effective UID of creator */
91 gid_t cgid; /* Effective GID of creator */
92 unsigned short \fBmode\fP; /* Permissions */
93 unsigned short __seq; /* Sequence number */
94 };
95 .in
96 .fi
97 .PP
98 Valid values for
99 .I cmd
100 are:
101 .TP
102 .B IPC_STAT
103 Copy information from the kernel data structure associated with
104 .I msqid
105 into the
106 .I msqid_ds
107 structure pointed to by
108 .IR buf .
109 The caller must have read permission on the message queue.
110 .TP
111 .B IPC_SET
112 Write the values of some members of the
113 .I msqid_ds
114 structure pointed to by
115 .I buf
116 to the kernel data structure associated with this message queue,
117 updating also its
118 .I msg_ctime
119 member.
120 The following members of the structure are updated:
121 .IR msg_qbytes ,
122 .IR msg_perm.uid ,
123 .IR msg_perm.gid ,
124 and (the least significant 9 bits of)
125 .IR msg_perm.mode .
126 The effective UID of the calling process must match the owner
127 .RI ( msg_perm.uid )
128 or creator
129 .RI ( msg_perm.cuid )
130 of the message queue, or the caller must be privileged.
131 Appropriate privilege (Linux: the
132 .B CAP_IPC_RESOURCE
133 capability) is required to raise the
134 .I msg_qbytes
135 value beyond the system parameter
136 .BR MSGMNB .
137 .TP
138 .B IPC_RMID
139 Immediately remove the message queue,
140 awakening all waiting reader and writer processes (with an error
141 return and
142 .I errno
143 set to
144 .BR EIDRM ).
145 The calling process must have appropriate privileges
146 or its effective user ID must be either that of the creator or owner
147 of the message queue.
148 .TP
149 .BR IPC_INFO " (Linux-specific)"
150 Returns information about system-wide message queue limits and
151 parameters in the structure pointed to by
152 .IR buf .
153 This structure is of type
154 .I msginfo
155 (thus, a cast is required),
156 defined in
157 .I <sys/msg.h>
158 if the
159 .B _GNU_SOURCE
160 feature test macro is defined:
161 .nf
162 .in +4n
163
164 struct msginfo {
165 int msgpool; /* Size in kibibytes of buffer pool
166 used to hold message data;
167 unused within kernel */
168 int msgmap; /* Maximum number of entries in message
169 map; unused within kernel */
170 int msgmax; /* Maximum number of bytes that can be
171 written in a single message */
172 int msgmnb; /* Maximum number of bytes that can be
173 written to queue; used to initialize
174 msg_qbytes during queue creation
175 (msgget(2)) */
176 int msgmni; /* Maximum number of message queues */
177 int msgssz; /* Message segment size;
178 unused within kernel */
179 int msgtql; /* Maximum number of messages on all queues
180 in system; unused within kernel */
181 unsigned short int msgseg;
182 /* Maximum number of segments;
183 unused within kernel */
184 };
185
186 .in
187 .fi
188 The
189 .IR msgmni ,
190 .IR msgmax ,
191 and
192 .I msgmnb
193 settings can be changed via
194 .I /proc
195 files of the same name; see
196 .BR proc (5)
197 for details.
198 .TP
199 .BR MSG_INFO " (Linux-specific)"
200 Returns a
201 .I msginfo
202 structure containing the same information as for
203 .BR IPC_INFO ,
204 except that the following fields are returned with information
205 about system resources consumed by message queues: the
206 .I msgpool
207 field returns the number of message queues that currently exist
208 on the system; the
209 .I msgmap
210 field returns the total number of messages in all queues
211 on the system; and the
212 .I msgtql
213 field returns the total number of bytes in all messages
214 in all queues on the system.
215 .TP
216 .BR MSG_STAT " (Linux-specific)"
217 Returns a
218 .I msqid_ds
219 structure as for
220 .BR IPC_STAT .
221 However, the
222 .I msqid
223 argument is not a queue identifier, but instead an index into
224 the kernel's internal array that maintains information about
225 all message queues on the system.
226 .SH RETURN VALUE
227 On success,
228 .BR IPC_STAT ,
229 .BR IPC_SET ,
230 and
231 .B IPC_RMID
232 return 0.
233 A successful
234 .B IPC_INFO
235 or
236 .B MSG_INFO
237 operation returns the index of the highest used entry in the
238 kernel's internal array recording information about all
239 message queues.
240 (This information can be used with repeated
241 .B MSG_STAT
242 operations to obtain information about all queues on the system.)
243 A successful
244 .B MSG_STAT
245 operation returns the identifier of the queue whose index was given in
246 .IR msqid .
247
248 On error, \-1 is returned with
249 .I errno
250 indicating the error.
251 .SH ERRORS
252 On failure,
253 .I errno
254 is set to one of the following:
255 .TP
256 .B EACCES
257 The argument
258 .I cmd
259 is equal to
260 .B IPC_STAT
261 or
262 .BR MSG_STAT ,
263 but the calling process does not have read permission on the message queue
264 .IR msqid ,
265 and does not have the
266 .B CAP_IPC_OWNER
267 capability.
268 .TP
269 .B EFAULT
270 The argument
271 .I cmd
272 has the value
273 .B IPC_SET
274 or
275 .BR IPC_STAT ,
276 but the address pointed to by
277 .I buf
278 isn't accessible.
279 .TP
280 .B EIDRM
281 The message queue was removed.
282 .TP
283 .B EINVAL
284 Invalid value for
285 .I cmd
286 or
287 .IR msqid .
288 Or: for a
289 .B MSG_STAT
290 operation, the index value specified in
291 .I msqid
292 referred to an array slot that is currently unused.
293 .TP
294 .B EPERM
295 The argument
296 .I cmd
297 has the value
298 .B IPC_SET
299 or
300 .BR IPC_RMID ,
301 but the effective user ID of the calling process is not the creator
302 (as found in
303 .IR msg_perm.cuid )
304 or the owner
305 (as found in
306 .IR msg_perm.uid )
307 of the message queue,
308 and the process is not privileged (Linux: it does not have the
309 .B CAP_SYS_ADMIN
310 capability).
311 .SH CONFORMING TO
312 SVr4, POSIX.1-2001.
313 .\" SVID does not document the EIDRM error condition.
314 .SH NOTES
315 The inclusion of
316 .I <sys/types.h>
317 and
318 .I <sys/ipc.h>
319 isn't required on Linux or by any version of POSIX.
320 However,
321 some old implementations required the inclusion of these header files,
322 and the SVID also documented their inclusion.
323 Applications intended to be portable to such old systems may need
324 to include these header files.
325 .\" Like Linux, the FreeBSD man pages still document
326 .\" the inclusion of these header files.
327
328 The
329 .BR IPC_INFO ,
330 .B MSG_STAT
331 and
332 .B MSG_INFO
333 operations are used by the
334 .BR ipcs (1)
335 program to provide information on allocated resources.
336 In the future these may modified or moved to a /proc file system
337 interface.
338
339 Various fields in the \fIstruct msqid_ds\fP were
340 typed as
341 .I short
342 under Linux 2.2
343 and have become
344 .I long
345 under Linux 2.4.
346 To take advantage of this,
347 a recompilation under glibc-2.1.91 or later should suffice.
348 (The kernel distinguishes old and new calls by an
349 .B IPC_64
350 flag in
351 .IR cmd .)
352 .SH SEE ALSO
353 .BR msgget (2),
354 .BR msgrcv (2),
355 .BR msgsnd (2),
356 .BR capabilities (7),
357 .BR mq_overview (7),
358 .BR svipc (7)