msgctl()

NAME

msgctl() - control message operations

SYNOPSIS

#include <sys/msg.h>

int msgctl(int msqid, int cmd, struct msqid_ds *buf)

DESCRIPTION

The msgctl(2) function provides a way to control message queue operations. The arguments are:

msqid
An identifier indicating a particular message queue, returned by msgget(2). The queue has a data structure associated with it; the visible elements of the data structure can be stored in a structure of type msqid_ds (see the description of buf).
cmd
The command to be carried out; msgctl(2) supports three commands (defined in <sys/msg.h>):
IPC_STAT
Store the current data structure information in buf.
IPC_SET
Set the values of the message queue's data structure to those specified in buf. Only the uid, gid, and mode members of msgid_ds.msg_perm can be modified. The process must have the appropriate privileges or an effective user ID equal to the value of msg_perm.cuid or msg_perm.uid in the data structure associated with the queue.

The maximum size of a queue is limited only be the ability of the system to allocate contiguous memory. If you decrease the size of a queue with this call, the change in size does not take effect until the queue contents are small enough to fit in the new size. During the time that the queue is larger than requested, msgsnd(2) calls will block or fail because the queue is full (or rather, overfull).

IPC_RMID
Remove msqid and the associated data structure from the system. The process must have the appropriate privileges or an effective user ID equal to the value of msg_perm.cuid or msg_perm.uid in the data structure associated with the queue.
buf
A pointer to a data structure of type msqid_ds which contains information about the message queue. It is defined in <sys/msg.h>; msgctl(2) only allows you to alter the following members:
struct ipc_perm msg_perm operation permission structure
msglen_t msg_qbytes max. # of bytes allowed on queue

See msgget(2) for a description of all of the visible members of msqid_ds and their default values. The type msglen_t is typedefed in <sys/msg.h>. The ipc_perm structure is defined in <sys/ipc.h>, which is automatically included when you include <sys/msg.h>.

RETURN VALUE

The msgctl(2) call returns 0 on success; on failure, it returns -1 and sets errno to indicate the error.

ERRORS

The msgctl(2) function can fail for these reasons:

[EACCES]
The cmd is IPC_STAT but the calling process doesn't have read permission.
[EINVAL]
Either msqid or cmd isn't valid.
[ENOSPC]
Increasing the message queue would exceed system resources. The message queue will not be damaged if this error is returned.
[EPERM]
If the cmd is IPC_RMID or IPC_SET, the process' effective user ID (which is the same as the user ID) is not equal to the value of msg_perm.cuid or msg_perm.uid in the data structure for the specified msqid.

SEE ALSO

msgget(2)

msgrcv(2)

msgsnd(2)