]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man2/msgctl.2
ipc.5 --> ipc.7
[thirdparty/man-pages.git] / man2 / msgctl.2
1 .\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it)
2 .\" and Copyright 2004, 2005 Michael Kerrisk <mtk-manpages@gmx.net>
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@gmx.net>
27 .\" Added notes on CAP_IPC_OWNER requirement
28 .\" Modified, 17 Jun 2004, Michael Kerrisk <mtk-manpages@gmx.net>
29 .\" Added notes on CAP_SYS_ADMIN requirement for IPC_SET and IPC_RMID
30 .\" Modified, 11 Nov 2004, Michael Kerrisk <mtk-manpages@gmx.net>
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 2004-11-10 "Linux 2.6.9" "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 <sys/msg.h> 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() */
67 time_t msg_rtime; /* Time of last msgrcv() */
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() */
76 pid_t msg_lrpid; /* PID of last msgrcv() */
77 };
78 .in -4n
79 .fi
80 .PP
81 The
82 .I ipc_perm
83 structure is defined in <sys/ipc.h> 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() */
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 -4n
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 .IR msginfo
158 (thus, a cast is required),
159 defined in
160 .I <sys/msg.h>
161 if the _GNU_SOURCE feature test macro is defined:
162 .nf
163 .in +2n
164
165 struct msginfo {
166 int msgpool; /* Size in bytes of buffer pool used
167 to hold message data; unused */
168 int msgmap; /* Max. # of entries in message
169 map; unused */
170 int msgmax; /* Max. # of bytes that can be
171 written in a single message */
172 int msgmnb; /* Max. # of bytes that can be written to
173 queue; used to initialize msg_qbytes
174 during queue creation (msgget()) */
175 int msgmni; /* Max. # of message queues */
176 int msgssz; /* Message segment size; unused */
177 int msgtql; /* Max. # of messages on all queues
178 in system; unused */
179 unsigned short int msgseg;
180 /* Max. # of segments; unused */
181 };
182
183 .in -2n
184 .fi
185 The
186 .IR msgmni ,
187 .IR msgmax ,
188 and
189 .I msgmnb
190 settings can be changed via
191 .I /proc
192 files of the same name; see
193 .BR proc (5)
194 for details.
195 .TP
196 .BR MSG_INFO " (Linux specific)"
197 Returns a
198 .I msginfo
199 structure containing the same information as for
200 .BR IPC_INFO ,
201 except that the following fields are returned with information
202 about system resources consumed by message queues: the
203 .I msgpool
204 field returns the number of message queues that currently exist
205 on the system; the
206 .I msgmap
207 field returns the total number of messages in all queues
208 on the system; and the
209 .I msgtql
210 field returns the total number of bytes in all messages
211 in all queues on the system.
212 .TP
213 .BR MSG_STAT " (Linux specific)"
214 Returns a
215 .I msqid_ds
216 structure as for
217 .BR IPC_STAT .
218 However, the
219 .I msqid
220 argument is not a queue identifier, but instead an index into
221 the kernel's internal array that maintains information about
222 all message queues on the system.
223 .SH "RETURN VALUE"
224 On success,
225 .BR IPC_STAT ,
226 .BR IPC_SET ,
227 and
228 .BR IPC_RMID
229 return 0.
230 A successful
231 .B IPC_INFO
232 or
233 .B MSG_INFO
234 operation returns the index of the highest used entry in the
235 kernel's internal array recording information about all
236 message queues.
237 (This information can be used with repeated
238 .B MSG_STAT
239 operations to obtain information about all queues on the system.)
240 A successful
241 .B MSG_STAT
242 operation returns the identifier of the queue whose index was given in
243 .IR msqid .
244
245 On error, \-1 is returned with
246 .I errno
247 indicating the error.
248 .SH ERRORS
249 On failure,
250 .I errno
251 is set to one of the following:
252 .TP 11
253 .B EACCES
254 The argument
255 .I cmd
256 is equal to
257 .BR IPC_STAT
258 or
259 .BR MSG_STAT ,
260 but the calling process does not have read permission on the message queue
261 .IR msqid ,
262 and does not have the
263 .B CAP_IPC_OWNER
264 capability.
265 .TP
266 .B EFAULT
267 The argument
268 .I cmd
269 has the value
270 .B IPC_SET
271 or
272 .BR IPC_STAT ,
273 but the address pointed to by
274 .I buf
275 isn't accessible.
276 .TP
277 .B EIDRM
278 The message queue was removed.
279 .TP
280 .B EINVAL
281 Invalid value for
282 .I cmd
283 or
284 .IR msqid .
285 Or: for a
286 .B MSG_STAT
287 operation, the index value specified in
288 .I msqid
289 referred to an array slot that is currently unused.
290 .TP
291 .B EPERM
292 The argument
293 .I cmd
294 has the value
295 .B IPC_SET
296 or
297 .BR IPC_RMID ,
298 but the effective user ID of the calling process is not the creator
299 (as found in
300 .IR msg_perm.cuid )
301 or the owner
302 (as found in
303 .IR msg_perm.uid )
304 of the message queue,
305 and the process is not privileged (Linux: it does not have the
306 .B CAP_SYS_ADMIN
307 capability).
308 .SH NOTES
309 The
310 .BR IPC_INFO ,
311 .BR MSG_STAT
312 and
313 .B MSG_INFO
314 operations are used by the
315 .BR ipcs (8)
316 program to provide information on allocated resources.
317 In the future these may modified or moved to a /proc file system
318 interface.
319
320 Various fields in the \fIstruct msqid_ds\fP were shorts under Linux 2.2
321 and have become longs under Linux 2.4. To take advantage of this,
322 a recompilation under glibc-2.1.91 or later should suffice.
323 (The kernel distinguishes old and new calls by an IPC_64 flag in
324 .IR cmd .)
325 .SH "CONFORMING TO"
326 SVr4, SVID. SVID does not document the EIDRM error condition.
327 .SH "SEE ALSO"
328 .BR msgget (2),
329 .BR msgrcv (2),
330 .BR msgsnd (2),
331 .BR capabilities (7),
332 .BR ipc (7),
333 .BR mq_overview (7)