Debian Codegraph @

upstream/debian-trixie/man2/msgctl.2

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