OSDN Git Service

4da56574e36cd410520cc900c764d73ccba014cc
[linuxjm/LDP_man-pages.git] / original / 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 2014-02-24 "Linux" "Linux Programmer's Manual"
38 .SH NAME
39 msgctl \- System V 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 System\ V 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_SYS_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 The third argument to
149 .BR msgctl ()
150 is ignored in this case.
151 .TP
152 .BR IPC_INFO " (Linux-specific)"
153 Return 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 Return 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 Return 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
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 caller is not privileged (Linux: does not have the
312 .B CAP_SYS_ADMIN
313 capability).
314 .TP
315 .B EPERM
316 An attempt
317 .RB ( IPC_SET )
318 was made to increase
319 .I msg_qbytes
320 beyond the system parameter
321 .BR MSGMNB ,
322 but the caller is not privileged (Linux: does not have the
323 .B CAP_SYS_RESOURCE
324 capability).
325 .SH CONFORMING TO
326 SVr4, POSIX.1-2001.
327 .\" SVID does not document the EIDRM error condition.
328 .SH NOTES
329 The inclusion of
330 .I <sys/types.h>
331 and
332 .I <sys/ipc.h>
333 isn't required on Linux or by any version of POSIX.
334 However,
335 some old implementations required the inclusion of these header files,
336 and the SVID also documented their inclusion.
337 Applications intended to be portable to such old systems may need
338 to include these header files.
339 .\" Like Linux, the FreeBSD man pages still document
340 .\" the inclusion of these header files.
341
342 The
343 .BR IPC_INFO ,
344 .B MSG_STAT
345 and
346 .B MSG_INFO
347 operations are used by the
348 .BR ipcs (1)
349 program to provide information on allocated resources.
350 In the future these may modified or moved to a
351 .I /proc
352 filesystem interface.
353
354 Various fields in the \fIstruct msqid_ds\fP were
355 typed as
356 .I short
357 under Linux 2.2
358 and have become
359 .I long
360 under Linux 2.4.
361 To take advantage of this,
362 a recompilation under glibc-2.1.91 or later should suffice.
363 (The kernel distinguishes old and new calls by an
364 .B IPC_64
365 flag in
366 .IR cmd .)
367 .SH SEE ALSO
368 .BR msgget (2),
369 .BR msgrcv (2),
370 .BR msgsnd (2),
371 .BR capabilities (7),
372 .BR mq_overview (7),
373 .BR svipc (7)
374 .SH COLOPHON
375 This page is part of release 3.67 of the Linux
376 .I man-pages
377 project.
378 A description of the project,
379 information about reporting bugs,
380 and the latest version of this page,
381 can be found at
382 \%http://www.kernel.org/doc/man\-pages/.