MQ_SETATTR(2)

πŸ’– mq_setattr(2) β€” the manual page, but make it slay πŸ’–

okay bestie, pull up a chair, we're doing a system call manual page and honestly? it's a short one, we love a short one. this is mq_setattr(2) from the System Calls Manual, and it's giving "small function, big responsibilities." let's get into it. πŸ¦‹


✨ NAME ✨

mq_setattr β€” set message queue attributes (REALTIME)

like... the name literally tells you everything. you're setting attributes. on a message queue. and it's a REALTIME thing, capital letters, very serious, very demure. πŸ’…


πŸ“š LIBRARY πŸ“š

POSIX Real-time Library (librt, -lrt)

so when you link this bad boy you need -lrt, no cap. that's the POSIX Real-time Library, and it's where all the realtime queue girlies hang out. πŸŽ€


🌸 SYNOPSIS 🌸

#include <mqueue.h>

int
mq_setattr(mqd_t mqdes, const struct mq_attr *restrict mqstat,
    struct mq_attr *restrict omqstat);

yes the restrict keywords are there, yes they matter, no we are not removing them. this is the exact signature, character for character, bestie. ⭐


πŸ‘‘ DESCRIPTION πŸ‘‘

so the mq_setattr() system call sets attributes associated with the open message queue description referenced by the message queue descriptor specified by mqdes. (say that five times fast, i dare you 😭)

the message queue attributes corresponding to the following members defined in the mq_attr structure will be set to the specified values upon successful completion of mq_setattr():

  • mq_flags β€” the value of this member is zero or O_NONBLOCK. that's it. that's the whole vibe. it's either 0 or O_NONBLOCK, pick your fighter. 🌈

and now the plot twist: the values of the mq_maxmsg, mq_msgsize, and mq_curmsgs members of the mq_attr structure are ignored by mq_setattr(). like, fully ignored. ghosted. not even read. so don't come in here thinking you can sneak a change past those three, because you cannot, they're literally not looking. πŸ’€


🫢 RETURN VALUES 🫢

upon successful completion, the function returns a value of zero and the attributes of the message queue will have been changed as specified. iconic. no notes. ✨

otherwise? the message queue attributes are unchanged, and the function returns a value of -1 and sets the global variable errno to indicate the error. so nothing got touched, and errno is here to tell you why. she's a messenger, not a hater. 🧚


🚨 ERRORS 🚨

the mq_setattr() system call will fail if:

  • [EBADF] β€” the mqdes argument is not a valid message queue descriptor.

that's the only one listed, bestie. one single error. a minimalist. a queen of efficiency. πŸ‘‘


πŸ”₯ SEE ALSO πŸ”₯

go read those next, they're all part of the same friend group. iykyk. πŸ’œ


πŸ“œ STANDARDS πŸ“œ

the mq_setattr() system call conforms to IEEE Std 1003.1-2004 ("POSIX.1"). certified. compliant. we love a standards-abiding function. 🌟


πŸ•°οΈ HISTORY πŸ•°οΈ

support for POSIX message queues first appeared in FreeBSD 7.0. throwback era, honestly. a little retro moment. πŸŽ€


portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. in the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. the original Standard can be obtained online at http://www.opengroup.org/unix/online.html.

yes we have to include the whole copyright paragraph, bestie. the legal girlies are watching. do not skip it. πŸ™ˆ

and that's the whole page!! this one came from Debian, dated May 17, 2011 β€” a little vintage moment, but she still serves. bye bestie, go set some attributes, you're gonna do amazing. πŸ’–πŸ¦‹βœ¨

πŸ“¦ where this page comes from