]>
Commit | Line | Data |
---|---|---|
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 |
7 | mq_getattr, mq_setattr \- get/set message queue attributes | |
536db98b AC |
8 | .SH LIBRARY |
9 | Real-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 () | |
21 | and | |
22 | .BR mq_setattr () | |
c13182ef | 23 | respectively retrieve and modify attributes of the message queue |
d9cb0d7d | 24 | referred to by the message queue descriptor |
80a99f39 | 25 | .IR mqdes . |
847e0d88 | 26 | .PP |
80a99f39 MK |
27 | .BR mq_getattr () |
28 | returns an | |
29 | .I mq_attr | |
c13182ef | 30 | structure in the buffer pointed by |
28cdb68a | 31 | .IR attr . |
80a99f39 | 32 | This structure is defined as: |
e646a1ba | 33 | .PP |
a08ea57c | 34 | .in +4n |
e646a1ba | 35 | .EX |
80a99f39 MK |
36 | struct 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 |
45 | The | |
46 | .I mq_flags | |
47 | field contains flags associated with the open message queue description. | |
d9bfdb9c | 48 | This field is initialized when the queue is created by |
fb186734 | 49 | .BR mq_open (3). |
80a99f39 MK |
50 | The only flag that can appear in this field is |
51 | .BR O_NONBLOCK . | |
847e0d88 | 52 | .PP |
c13182ef | 53 | The |
80a99f39 MK |
54 | .I mq_maxmsg |
55 | and | |
56 | .I mq_msgsize | |
57 | fields are set when the message queue is created by | |
fb186734 | 58 | .BR mq_open (3). |
80a99f39 MK |
59 | The |
60 | .I mq_maxmsg | |
c13182ef | 61 | field is an upper limit on the number of messages |
80a99f39 | 62 | that may be placed on the queue using |
fb186734 | 63 | .BR mq_send (3). |
80a99f39 MK |
64 | The |
65 | .I mq_msgsize | |
66 | field is an upper limit on the size of messages | |
67 | that may be placed on the queue. | |
68 | Both of these fields must have a value greater than zero. | |
c13182ef MK |
69 | Two |
70 | .I /proc | |
71 | files that place ceilings on the values for these fields are described in | |
a4e83a44 | 72 | .BR mq_overview (7). |
847e0d88 | 73 | .PP |
c13182ef | 74 | The |
80a99f39 MK |
75 | .I mq_curmsgs |
76 | field returns the number of messages currently held in the queue. | |
847e0d88 | 77 | .PP |
80a99f39 | 78 | .BR mq_setattr () |
c13182ef | 79 | sets message queue attributes using information supplied in the |
80a99f39 MK |
80 | .I mq_attr |
81 | structure pointed to by | |
82 | .IR newattr . | |
83 | The only attribute that can be modified is the setting of the | |
84 | .B O_NONBLOCK | |
85 | flag in | |
86 | .IR mq_flags . | |
87 | The other fields in | |
88 | .I newattr | |
89 | are ignored. | |
90 | If the | |
91 | .I oldattr | |
92 | field is not NULL, | |
93 | then the buffer that it points to is used to return an | |
94 | .I mq_attr | |
95 | structure that contains the same information that is returned by | |
96 | .BR mq_getattr (). | |
97 | .SH RETURN VALUE | |
98 | On success | |
99 | .BR mq_getattr () | |
100 | and | |
101 | .BR mq_setattr () | |
102 | return 0; on error, \-1 is returned, with | |
c13182ef | 103 | .I errno |
80a99f39 MK |
104 | set to indicate the error. |
105 | .SH ERRORS | |
106 | .TP | |
107 | .B EBADF | |
d9cb0d7d | 108 | The message queue descriptor specified in |
80a99f39 MK |
109 | .I mqdes |
110 | is invalid. | |
111 | .TP | |
112 | .B EINVAL | |
94e9d9fe | 113 | .I newattr\->mq_flags |
80a99f39 MK |
114 | contained set bits other than |
115 | .BR O_NONBLOCK . | |
dda654f4 | 116 | .SH ATTRIBUTES |
b965bcba PH |
117 | For 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 |
122 | allbox; | |
c466875e | 123 | lbx lb lb |
b965bcba PH |
124 | l l l. |
125 | Interface Attribute Value | |
126 | T{ | |
127 | .BR mq_getattr (), | |
dda654f4 | 128 | .BR mq_setattr () |
b965bcba PH |
129 | T} Thread safety MT-Safe |
130 | .TE | |
c466875e MK |
131 | .hy |
132 | .ad | |
133 | .sp 1 | |
3113c7f3 | 134 | .SH STANDARDS |
8a8feb35 | 135 | POSIX.1-2001, POSIX.1-2008. |
247ac1d3 MK |
136 | .SH NOTES |
137 | On Linux, | |
138 | .BR mq_getattr () | |
139 | and | |
140 | .BR mq_setattr () | |
141 | are library functions layered on top of the | |
142 | .BR mq_getsetattr (2) | |
143 | system call. | |
a14af333 | 144 | .SH EXAMPLES |
6c1eb6d2 MK |
145 | The program below can be used to show the default |
146 | .I mq_maxmsg | |
147 | and | |
148 | .I mq_msgsize | |
149 | values that are assigned to a message queue that is created with a call to | |
150 | .BR mq_open (3) | |
151 | in which the | |
152 | .I attr | |
153 | argument is NULL. | |
154 | Here 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 |
159 | Maximum # of messages on queue: 10 | |
160 | Maximum message size: 8192 | |
b8302363 | 161 | .EE |
6c1eb6d2 | 162 | .in |
847e0d88 | 163 | .PP |
6c1eb6d2 MK |
164 | Since Linux 3.5, the following |
165 | .I /proc | |
166 | files (described in | |
167 | .BR mq_overview (7)) | |
168 | can be used to control the defaults: | |
847e0d88 | 169 | .PP |
6c1eb6d2 | 170 | .in +4n |
b8302363 | 171 | .EX |
86d93b3e | 172 | $ \fBuname \-sr\fP |
6c1eb6d2 MK |
173 | Linux 3.8.0 |
174 | $ \fBcat /proc/sys/fs/mqueue/msg_default\fP | |
175 | 10 | |
176 | $ \fBcat /proc/sys/fs/mqueue/msgsize_default\fP | |
177 | 8192 | |
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 | ||
193 | int | |
194 | main(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) |