]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/mq_getattr.3
All pages: Remove the 5th argument to .TH
[thirdparty/man-pages.git] / man3 / mq_getattr.3
CommitLineData
c11b1abf 1.\" Copyright (C) 2006 Michael Kerrisk <mtk.manpages@gmail.com>
80a99f39 2.\"
5fbde956 3.\" SPDX-License-Identifier: Linux-man-pages-copyleft
80a99f39 4.\"
45186a5d 5.TH MQ_GETATTR 3 2021-03-22 "Linux man-pages (unreleased)"
80a99f39
MK
6.SH NAME
7mq_getattr, mq_setattr \- get/set message queue attributes
536db98b
AC
8.SH LIBRARY
9Real-time library
8fc3b2cf 10.RI ( librt ", " \-lrt )
80a99f39
MK
11.SH SYNOPSIS
12.nf
13.B #include <mqueue.h>
68e4db0a 14.PP
c9e83f06 15.BI "int mq_getattr(mqd_t " mqdes ", struct mq_attr *" attr );
7369646c
AC
16.BI "int mq_setattr(mqd_t " mqdes ", const struct mq_attr *restrict " newattr ,
17.BI " struct mq_attr *restrict " oldattr );
80a99f39
MK
18.fi
19.SH DESCRIPTION
20.BR mq_getattr ()
21and
22.BR mq_setattr ()
c13182ef 23respectively retrieve and modify attributes of the message queue
d9cb0d7d 24referred to by the message queue descriptor
80a99f39 25.IR mqdes .
847e0d88 26.PP
80a99f39
MK
27.BR mq_getattr ()
28returns an
29.I mq_attr
c13182ef 30structure in the buffer pointed by
28cdb68a 31.IR attr .
80a99f39 32This structure is defined as:
e646a1ba 33.PP
a08ea57c 34.in +4n
e646a1ba 35.EX
80a99f39
MK
36struct mq_attr {
37 long mq_flags; /* Flags: 0 or O_NONBLOCK */
38 long mq_maxmsg; /* Max. # of messages on queue */
39 long mq_msgsize; /* Max. message size (bytes) */
40 long mq_curmsgs; /* # of messages currently in queue */
41};
b8302363 42.EE
a08ea57c 43.in
80a99f39
MK
44.PP
45The
46.I mq_flags
47field contains flags associated with the open message queue description.
d9bfdb9c 48This field is initialized when the queue is created by
fb186734 49.BR mq_open (3).
80a99f39
MK
50The only flag that can appear in this field is
51.BR O_NONBLOCK .
847e0d88 52.PP
c13182ef 53The
80a99f39
MK
54.I mq_maxmsg
55and
56.I mq_msgsize
57fields are set when the message queue is created by
fb186734 58.BR mq_open (3).
80a99f39
MK
59The
60.I mq_maxmsg
c13182ef 61field is an upper limit on the number of messages
80a99f39 62that may be placed on the queue using
fb186734 63.BR mq_send (3).
80a99f39
MK
64The
65.I mq_msgsize
66field is an upper limit on the size of messages
67that may be placed on the queue.
68Both of these fields must have a value greater than zero.
c13182ef
MK
69Two
70.I /proc
71files that place ceilings on the values for these fields are described in
a4e83a44 72.BR mq_overview (7).
847e0d88 73.PP
c13182ef 74The
80a99f39
MK
75.I mq_curmsgs
76field returns the number of messages currently held in the queue.
847e0d88 77.PP
80a99f39 78.BR mq_setattr ()
c13182ef 79sets message queue attributes using information supplied in the
80a99f39
MK
80.I mq_attr
81structure pointed to by
82.IR newattr .
83The only attribute that can be modified is the setting of the
84.B O_NONBLOCK
85flag in
86.IR mq_flags .
87The other fields in
88.I newattr
89are ignored.
90If the
91.I oldattr
92field is not NULL,
93then the buffer that it points to is used to return an
94.I mq_attr
95structure that contains the same information that is returned by
96.BR mq_getattr ().
97.SH RETURN VALUE
98On success
99.BR mq_getattr ()
100and
101.BR mq_setattr ()
102return 0; on error, \-1 is returned, with
c13182ef 103.I errno
80a99f39
MK
104set to indicate the error.
105.SH ERRORS
106.TP
107.B EBADF
d9cb0d7d 108The message queue descriptor specified in
80a99f39
MK
109.I mqdes
110is invalid.
111.TP
112.B EINVAL
94e9d9fe 113.I newattr\->mq_flags
80a99f39
MK
114contained set bits other than
115.BR O_NONBLOCK .
dda654f4 116.SH ATTRIBUTES
b965bcba
PH
117For an explanation of the terms used in this section, see
118.BR attributes (7).
c466875e
MK
119.ad l
120.nh
b965bcba
PH
121.TS
122allbox;
c466875e 123lbx lb lb
b965bcba
PH
124l l l.
125Interface Attribute Value
126T{
127.BR mq_getattr (),
dda654f4 128.BR mq_setattr ()
b965bcba
PH
129T} Thread safety MT-Safe
130.TE
c466875e
MK
131.hy
132.ad
133.sp 1
3113c7f3 134.SH STANDARDS
8a8feb35 135POSIX.1-2001, POSIX.1-2008.
247ac1d3
MK
136.SH NOTES
137On Linux,
138.BR mq_getattr ()
139and
140.BR mq_setattr ()
141are library functions layered on top of the
142.BR mq_getsetattr (2)
143system call.
a14af333 144.SH EXAMPLES
6c1eb6d2
MK
145The program below can be used to show the default
146.I mq_maxmsg
147and
148.I mq_msgsize
149values that are assigned to a message queue that is created with a call to
150.BR mq_open (3)
151in which the
152.I attr
153argument is NULL.
154Here is an example run of the program:
847e0d88 155.PP
6c1eb6d2 156.in +4n
b8302363 157.EX
6c1eb6d2
MK
158$ \fB./a.out /testq\fP
159Maximum # of messages on queue: 10
160Maximum message size: 8192
b8302363 161.EE
6c1eb6d2 162.in
847e0d88 163.PP
6c1eb6d2
MK
164Since Linux 3.5, the following
165.I /proc
166files (described in
167.BR mq_overview (7))
168can be used to control the defaults:
847e0d88 169.PP
6c1eb6d2 170.in +4n
b8302363 171.EX
86d93b3e 172$ \fBuname \-sr\fP
6c1eb6d2
MK
173Linux 3.8.0
174$ \fBcat /proc/sys/fs/mqueue/msg_default\fP
17510
176$ \fBcat /proc/sys/fs/mqueue/msgsize_default\fP
1778192
b8302363 178.EE
6c1eb6d2 179.in
8f9b1587 180.SS Program source
6c1eb6d2 181\&
e7d0bb47 182.EX
6c1eb6d2
MK
183#include <mqueue.h>
184#include <sys/stat.h>
185#include <fcntl.h>
186#include <stdio.h>
187#include <stdlib.h>
188#include <unistd.h>
189
d1a71985 190#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \e
6c1eb6d2
MK
191 } while (0)
192
193int
194main(int argc, char *argv[])
195{
196 mqd_t mqd;
197 struct mq_attr attr;
198
199 if (argc != 2) {
d1a71985 200 fprintf(stderr, "Usage: %s mq\-name\en", argv[0]);
6c1eb6d2
MK
201 exit(EXIT_FAILURE);
202 }
203
204 mqd = mq_open(argv[1], O_CREAT | O_EXCL, S_IRUSR | S_IWUSR, NULL);
205 if (mqd == (mqd_t) \-1)
206 errExit("mq_open");
207
208 if (mq_getattr(mqd, &attr) == \-1)
209 errExit("mq_getattr");
210
d1a71985
MK
211 printf("Maximum # of messages on queue: %ld\en", attr.mq_maxmsg);
212 printf("Maximum message size: %ld\en", attr.mq_msgsize);
6c1eb6d2
MK
213
214 if (mq_unlink(argv[1]) == \-1)
215 errExit("mq_unlink");
216
217 exit(EXIT_SUCCESS);
218}
e7d0bb47 219.EE
47297adb 220.SH SEE ALSO
80a99f39
MK
221.BR mq_close (3),
222.BR mq_notify (3),
223.BR mq_open (3),
224.BR mq_receive (3),
225.BR mq_send (3),
226.BR mq_unlink (3),
227.BR mq_overview (7)