Blame man2/msgctl.2

Packit 7cfc04
.\" Copyright 1993 Giorgio Ciucci (giorgio@crcc.it)
Packit 7cfc04
.\" and Copyright 2004, 2005 Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"
Packit 7cfc04
.\" %%%LICENSE_START(VERBATIM)
Packit 7cfc04
.\" Permission is granted to make and distribute verbatim copies of this
Packit 7cfc04
.\" manual provided the copyright notice and this permission notice are
Packit 7cfc04
.\" preserved on all copies.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Permission is granted to copy and distribute modified versions of this
Packit 7cfc04
.\" manual under the conditions for verbatim copying, provided that the
Packit 7cfc04
.\" entire resulting derived work is distributed under the terms of a
Packit 7cfc04
.\" permission notice identical to this one.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Since the Linux kernel and libraries are constantly changing, this
Packit 7cfc04
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
Packit 7cfc04
.\" responsibility for errors or omissions, or for damages resulting from
Packit 7cfc04
.\" the use of the information contained herein.  The author(s) may not
Packit 7cfc04
.\" have taken the same level of care in the production of this manual,
Packit 7cfc04
.\" which is licensed free of charge, as they might when working
Packit 7cfc04
.\" professionally.
Packit 7cfc04
.\"
Packit 7cfc04
.\" Formatted or processed versions of this manual, if unaccompanied by
Packit 7cfc04
.\" the source, must acknowledge the copyright and authors of this work.
Packit 7cfc04
.\" %%%LICENSE_END
Packit 7cfc04
.\"
Packit 7cfc04
.\" Modified Tue Oct 22 08:11:14 EDT 1996 by Eric S. Raymond <esr@thyrsus.com>
Packit 7cfc04
.\" Modified Sun Feb 18 01:59:29 2001 by Andries E. Brouwer <aeb@cwi.nl>
Packit 7cfc04
.\" Modified, 27 May 2004, Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"     Added notes on CAP_IPC_OWNER requirement
Packit 7cfc04
.\" Modified, 17 Jun 2004, Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"     Added notes on CAP_SYS_ADMIN requirement for IPC_SET and IPC_RMID
Packit 7cfc04
.\" Modified, 11 Nov 2004, Michael Kerrisk <mtk.manpages@gmail.com>
Packit 7cfc04
.\"	Language and formatting clean-ups
Packit 7cfc04
.\"	Added msqid_ds and ipc_perm structure definitions
Packit 7cfc04
.\" 2005-08-02, mtk: Added IPC_INFO, MSG_INFO, MSG_STAT descriptions
Packit 7cfc04
.\"
Packit 7cfc04
.TH MSGCTL 2 2017-09-15 "Linux" "Linux Programmer's Manual"
Packit 7cfc04
.SH NAME
Packit 7cfc04
msgctl \- System V message control operations
Packit 7cfc04
.SH SYNOPSIS
Packit 7cfc04
.nf
Packit 7cfc04
.B #include <sys/types.h>
Packit 7cfc04
.B #include <sys/ipc.h>
Packit 7cfc04
.B #include <sys/msg.h>
Packit 7cfc04
.PP
Packit 7cfc04
.BI "int msgctl(int " msqid ", int " cmd ", struct msqid_ds *" buf );
Packit 7cfc04
.fi
Packit 7cfc04
.SH DESCRIPTION
Packit 7cfc04
.BR msgctl ()
Packit 7cfc04
performs the control operation specified by
Packit 7cfc04
.I cmd
Packit 7cfc04
on the System\ V message queue with identifier
Packit 7cfc04
.IR msqid .
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I msqid_ds
Packit 7cfc04
data structure is defined in \fI<sys/msg.h>\fP as follows:
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
struct msqid_ds {
Packit 7cfc04
    struct ipc_perm msg_perm;     /* Ownership and permissions */
Packit 7cfc04
    time_t          msg_stime;    /* Time of last msgsnd(2) */
Packit 7cfc04
    time_t          msg_rtime;    /* Time of last msgrcv(2) */
Packit 7cfc04
    time_t          msg_ctime;    /* Time of last change */
Packit 7cfc04
    unsigned long   __msg_cbytes; /* Current number of bytes in
Packit 7cfc04
                                     queue (nonstandard) */
Packit 7cfc04
    msgqnum_t       msg_qnum;     /* Current number of messages
Packit 7cfc04
                                     in queue */
Packit 7cfc04
    msglen_t        msg_qbytes;   /* Maximum number of bytes
Packit 7cfc04
                                     allowed in queue */
Packit 7cfc04
    pid_t           msg_lspid;    /* PID of last msgsnd(2) */
Packit 7cfc04
    pid_t           msg_lrpid;    /* PID of last msgrcv(2) */
Packit 7cfc04
};
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.I ipc_perm
Packit 7cfc04
structure is defined as follows
Packit 7cfc04
(the highlighted fields are settable using
Packit 7cfc04
.BR IPC_SET ):
Packit 7cfc04
.PP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
struct ipc_perm {
Packit 7cfc04
    key_t          __key;       /* Key supplied to msgget(2) */
Packit 7cfc04
    uid_t          \fBuid\fP;         /* Effective UID of owner */
Packit 7cfc04
    gid_t          \fBgid\fP;         /* Effective GID of owner */
Packit 7cfc04
    uid_t          cuid;        /* Effective UID of creator */
Packit 7cfc04
    gid_t          cgid;        /* Effective GID of creator */
Packit 7cfc04
    unsigned short \fBmode\fP;        /* Permissions */
Packit 7cfc04
    unsigned short __seq;       /* Sequence number */
Packit 7cfc04
};
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.PP
Packit 7cfc04
Valid values for
Packit 7cfc04
.I cmd
Packit 7cfc04
are:
Packit 7cfc04
.TP
Packit 7cfc04
.B IPC_STAT
Packit 7cfc04
Copy information from the kernel data structure associated with
Packit 7cfc04
.I msqid
Packit 7cfc04
into the
Packit 7cfc04
.I msqid_ds
Packit 7cfc04
structure pointed to by
Packit 7cfc04
.IR buf .
Packit 7cfc04
The caller must have read permission on the message queue.
Packit 7cfc04
.TP
Packit 7cfc04
.B IPC_SET
Packit 7cfc04
Write the values of some members of the
Packit 7cfc04
.I msqid_ds
Packit 7cfc04
structure pointed to by
Packit 7cfc04
.I buf
Packit 7cfc04
to the kernel data structure associated with this message queue,
Packit 7cfc04
updating also its
Packit 7cfc04
.I msg_ctime
Packit 7cfc04
member.
Packit 7cfc04
The following members of the structure are updated:
Packit 7cfc04
.IR msg_qbytes ,
Packit 7cfc04
.IR msg_perm.uid ,
Packit 7cfc04
.IR msg_perm.gid ,
Packit 7cfc04
and (the least significant 9 bits of)
Packit 7cfc04
.IR msg_perm.mode .
Packit 7cfc04
The effective UID of the calling process must match the owner
Packit 7cfc04
.RI ( msg_perm.uid )
Packit 7cfc04
or creator
Packit 7cfc04
.RI ( msg_perm.cuid )
Packit 7cfc04
of the message queue, or the caller must be privileged.
Packit 7cfc04
Appropriate privilege (Linux: the
Packit 7cfc04
.B CAP_SYS_RESOURCE
Packit 7cfc04
capability) is required to raise the
Packit 7cfc04
.I msg_qbytes
Packit 7cfc04
value beyond the system parameter
Packit 7cfc04
.BR MSGMNB .
Packit 7cfc04
.TP
Packit 7cfc04
.B IPC_RMID
Packit 7cfc04
Immediately remove the message queue,
Packit 7cfc04
awakening all waiting reader and writer processes (with an error
Packit 7cfc04
return and
Packit 7cfc04
.I errno
Packit 7cfc04
set to
Packit 7cfc04
.BR EIDRM ).
Packit 7cfc04
The calling process must have appropriate privileges
Packit 7cfc04
or its effective user ID must be either that of the creator or owner
Packit 7cfc04
of the message queue.
Packit 7cfc04
The third argument to
Packit 7cfc04
.BR msgctl ()
Packit 7cfc04
is ignored in this case.
Packit 7cfc04
.TP
Packit 7cfc04
.BR IPC_INFO " (Linux-specific)"
Packit 7cfc04
Return information about system-wide message queue limits and
Packit 7cfc04
parameters in the structure pointed to by
Packit 7cfc04
.IR buf .
Packit 7cfc04
This structure is of type
Packit 7cfc04
.I msginfo
Packit 7cfc04
(thus, a cast is required),
Packit 7cfc04
defined in
Packit 7cfc04
.I <sys/msg.h>
Packit 7cfc04
if the
Packit 7cfc04
.B _GNU_SOURCE
Packit 7cfc04
feature test macro is defined:
Packit 7cfc04
.IP
Packit 7cfc04
.in +4n
Packit 7cfc04
.EX
Packit 7cfc04
struct msginfo {
Packit 7cfc04
    int msgpool; /* Size in kibibytes of buffer pool
Packit 7cfc04
                    used to hold message data;
Packit 7cfc04
                    unused within kernel */
Packit 7cfc04
    int msgmap;  /* Maximum number of entries in message
Packit 7cfc04
                    map; unused within kernel */
Packit 7cfc04
    int msgmax;  /* Maximum number of bytes that can be
Packit 7cfc04
                    written in a single message */
Packit 7cfc04
    int msgmnb;  /* Maximum number of bytes that can be
Packit 7cfc04
                    written to queue; used to initialize
Packit 7cfc04
                    msg_qbytes during queue creation
Packit 7cfc04
                    (msgget(2)) */
Packit 7cfc04
    int msgmni;  /* Maximum number of message queues */
Packit 7cfc04
    int msgssz;  /* Message segment size;
Packit 7cfc04
                    unused within kernel */
Packit 7cfc04
    int msgtql;  /* Maximum number of messages on all queues
Packit 7cfc04
                    in system; unused within kernel */
Packit 7cfc04
    unsigned short int msgseg;
Packit 7cfc04
                 /* Maximum number of segments;
Packit 7cfc04
                    unused within kernel */
Packit 7cfc04
};
Packit 7cfc04
.EE
Packit 7cfc04
.in
Packit 7cfc04
.IP
Packit 7cfc04
The
Packit 7cfc04
.IR msgmni ,
Packit 7cfc04
.IR msgmax ,
Packit 7cfc04
and
Packit 7cfc04
.I msgmnb
Packit 7cfc04
settings can be changed via
Packit 7cfc04
.I /proc
Packit 7cfc04
files of the same name; see
Packit 7cfc04
.BR proc (5)
Packit 7cfc04
for details.
Packit 7cfc04
.TP
Packit 7cfc04
.BR MSG_INFO " (Linux-specific)"
Packit 7cfc04
Return a
Packit 7cfc04
.I msginfo
Packit 7cfc04
structure containing the same information as for
Packit 7cfc04
.BR IPC_INFO ,
Packit 7cfc04
except that the following fields are returned with information
Packit 7cfc04
about system resources consumed by message queues: the
Packit 7cfc04
.I msgpool
Packit 7cfc04
field returns the number of message queues that currently exist
Packit 7cfc04
on the system; the
Packit 7cfc04
.I msgmap
Packit 7cfc04
field returns the total number of messages in all queues
Packit 7cfc04
on the system; and the
Packit 7cfc04
.I msgtql
Packit 7cfc04
field returns the total number of bytes in all messages
Packit 7cfc04
in all queues on the system.
Packit 7cfc04
.TP
Packit 7cfc04
.BR MSG_STAT " (Linux-specific)"
Packit 7cfc04
Return a
Packit 7cfc04
.I msqid_ds
Packit 7cfc04
structure as for
Packit 7cfc04
.BR IPC_STAT .
Packit 7cfc04
However, the
Packit 7cfc04
.I msqid
Packit 7cfc04
argument is not a queue identifier, but instead an index into
Packit 7cfc04
the kernel's internal array that maintains information about
Packit 7cfc04
all message queues on the system.
Packit 7cfc04
.SH RETURN VALUE
Packit 7cfc04
On success,
Packit 7cfc04
.BR IPC_STAT ,
Packit 7cfc04
.BR IPC_SET ,
Packit 7cfc04
and
Packit 7cfc04
.B IPC_RMID
Packit 7cfc04
return 0.
Packit 7cfc04
A successful
Packit 7cfc04
.B IPC_INFO
Packit 7cfc04
or
Packit 7cfc04
.B MSG_INFO
Packit 7cfc04
operation returns the index of the highest used entry in the
Packit 7cfc04
kernel's internal array recording information about all
Packit 7cfc04
message queues.
Packit 7cfc04
(This information can be used with repeated
Packit 7cfc04
.B MSG_STAT
Packit 7cfc04
operations to obtain information about all queues on the system.)
Packit 7cfc04
A successful
Packit 7cfc04
.B MSG_STAT
Packit 7cfc04
operation returns the identifier of the queue whose index was given in
Packit 7cfc04
.IR msqid .
Packit 7cfc04
.PP
Packit 7cfc04
On error, \-1 is returned with
Packit 7cfc04
.I errno
Packit 7cfc04
indicating the error.
Packit 7cfc04
.SH ERRORS
Packit 7cfc04
On failure,
Packit 7cfc04
.I errno
Packit 7cfc04
is set to one of the following:
Packit 7cfc04
.TP
Packit 7cfc04
.B EACCES
Packit 7cfc04
The argument
Packit 7cfc04
.I cmd
Packit 7cfc04
is equal to
Packit 7cfc04
.B IPC_STAT
Packit 7cfc04
or
Packit 7cfc04
.BR MSG_STAT ,
Packit 7cfc04
but the calling process does not have read permission on the message queue
Packit 7cfc04
.IR msqid ,
Packit 7cfc04
and does not have the
Packit 7cfc04
.B CAP_IPC_OWNER
Packit 7cfc04
capability in the user namespace that governs its IPC namespace.
Packit 7cfc04
.TP
Packit 7cfc04
.B EFAULT
Packit 7cfc04
The argument
Packit 7cfc04
.I cmd
Packit 7cfc04
has the value
Packit 7cfc04
.B IPC_SET
Packit 7cfc04
or
Packit 7cfc04
.BR IPC_STAT ,
Packit 7cfc04
but the address pointed to by
Packit 7cfc04
.I buf
Packit 7cfc04
isn't accessible.
Packit 7cfc04
.TP
Packit 7cfc04
.B EIDRM
Packit 7cfc04
The message queue was removed.
Packit 7cfc04
.TP
Packit 7cfc04
.B EINVAL
Packit 7cfc04
Invalid value for
Packit 7cfc04
.I cmd
Packit 7cfc04
or
Packit 7cfc04
.IR msqid .
Packit 7cfc04
Or: for a
Packit 7cfc04
.B MSG_STAT
Packit 7cfc04
operation, the index value specified in
Packit 7cfc04
.I msqid
Packit 7cfc04
referred to an array slot that is currently unused.
Packit 7cfc04
.TP
Packit 7cfc04
.B EPERM
Packit 7cfc04
The argument
Packit 7cfc04
.I cmd
Packit 7cfc04
has the value
Packit 7cfc04
.B IPC_SET
Packit 7cfc04
or
Packit 7cfc04
.BR IPC_RMID ,
Packit 7cfc04
but the effective user ID of the calling process is not the creator
Packit 7cfc04
(as found in
Packit 7cfc04
.IR msg_perm.cuid )
Packit 7cfc04
or the owner
Packit 7cfc04
(as found in
Packit 7cfc04
.IR msg_perm.uid )
Packit 7cfc04
of the message queue,
Packit 7cfc04
and the caller is not privileged (Linux: does not have the
Packit 7cfc04
.B CAP_SYS_ADMIN
Packit 7cfc04
capability).
Packit 7cfc04
.TP
Packit 7cfc04
.B EPERM
Packit 7cfc04
An attempt
Packit 7cfc04
.RB ( IPC_SET )
Packit 7cfc04
was made to increase
Packit 7cfc04
.I msg_qbytes
Packit 7cfc04
beyond the system parameter
Packit 7cfc04
.BR MSGMNB ,
Packit 7cfc04
but the caller is not privileged (Linux: does not have the
Packit 7cfc04
.B CAP_SYS_RESOURCE
Packit 7cfc04
capability).
Packit 7cfc04
.SH CONFORMING TO
Packit 7cfc04
POSIX.1-2001, POSIX.1-2008, SVr4.
Packit 7cfc04
.\" SVID does not document the EIDRM error condition.
Packit 7cfc04
.SH NOTES
Packit 7cfc04
The inclusion of
Packit 7cfc04
.I <sys/types.h>
Packit 7cfc04
and
Packit 7cfc04
.I <sys/ipc.h>
Packit 7cfc04
isn't required on Linux or by any version of POSIX.
Packit 7cfc04
However,
Packit 7cfc04
some old implementations required the inclusion of these header files,
Packit 7cfc04
and the SVID also documented their inclusion.
Packit 7cfc04
Applications intended to be portable to such old systems may need
Packit 7cfc04
to include these header files.
Packit 7cfc04
.\" Like Linux, the FreeBSD man pages still document
Packit 7cfc04
.\" the inclusion of these header files.
Packit 7cfc04
.PP
Packit 7cfc04
The
Packit 7cfc04
.BR IPC_INFO ,
Packit 7cfc04
.B MSG_STAT
Packit 7cfc04
and
Packit 7cfc04
.B MSG_INFO
Packit 7cfc04
operations are used by the
Packit 7cfc04
.BR ipcs (1)
Packit 7cfc04
program to provide information on allocated resources.
Packit 7cfc04
In the future these may modified or moved to a
Packit 7cfc04
.I /proc
Packit 7cfc04
filesystem interface.
Packit 7cfc04
.PP
Packit 7cfc04
Various fields in the \fIstruct msqid_ds\fP were
Packit 7cfc04
typed as
Packit 7cfc04
.I short
Packit 7cfc04
under Linux 2.2
Packit 7cfc04
and have become
Packit 7cfc04
.I long
Packit 7cfc04
under Linux 2.4.
Packit 7cfc04
To take advantage of this,
Packit 7cfc04
a recompilation under glibc-2.1.91 or later should suffice.
Packit 7cfc04
(The kernel distinguishes old and new calls by an
Packit 7cfc04
.B IPC_64
Packit 7cfc04
flag in
Packit 7cfc04
.IR cmd .)
Packit 7cfc04
.SH SEE ALSO
Packit 7cfc04
.BR msgget (2),
Packit 7cfc04
.BR msgrcv (2),
Packit 7cfc04
.BR msgsnd (2),
Packit 7cfc04
.BR capabilities (7),
Packit 7cfc04
.BR mq_overview (7),
Packit 7cfc04
.BR svipc (7)
Packit 7cfc04
.SH COLOPHON
Packit 7cfc04
This page is part of release 4.15 of the Linux
Packit 7cfc04
.I man-pages
Packit 7cfc04
project.
Packit 7cfc04
A description of the project,
Packit 7cfc04
information about reporting bugs,
Packit 7cfc04
and the latest version of this page,
Packit 7cfc04
can be found at
Packit 7cfc04
\%https://www.kernel.org/doc/man\-pages/.