xref: /dflybsd-src/lib/libc/sys/msgctl.2 (revision 34c6728ee290889398ff2f1305a91f08aa6b0b35)
182657471SMarkus Pfeiffer.\"	$NetBSD: msgctl.2,v 1.1 1995/10/16 23:49:15 jtc Exp $
282657471SMarkus Pfeiffer.\"
382657471SMarkus Pfeiffer.\" Copyright (c) 1995 Frank van der Linden
482657471SMarkus Pfeiffer.\" All rights reserved.
582657471SMarkus Pfeiffer.\"
682657471SMarkus Pfeiffer.\" Redistribution and use in source and binary forms, with or without
782657471SMarkus Pfeiffer.\" modification, are permitted provided that the following conditions
882657471SMarkus Pfeiffer.\" are met:
982657471SMarkus Pfeiffer.\" 1. Redistributions of source code must retain the above copyright
1082657471SMarkus Pfeiffer.\"    notice, this list of conditions and the following disclaimer.
1182657471SMarkus Pfeiffer.\" 2. Redistributions in binary form must reproduce the above copyright
1282657471SMarkus Pfeiffer.\"    notice, this list of conditions and the following disclaimer in the
1382657471SMarkus Pfeiffer.\"    documentation and/or other materials provided with the distribution.
1482657471SMarkus Pfeiffer.\" 3. All advertising materials mentioning features or use of this software
1582657471SMarkus Pfeiffer.\"    must display the following acknowledgement:
1682657471SMarkus Pfeiffer.\"      This product includes software developed for the NetBSD Project
1782657471SMarkus Pfeiffer.\"      by Frank van der Linden
1882657471SMarkus Pfeiffer.\" 4. The name of the author may not be used to endorse or promote products
1982657471SMarkus Pfeiffer.\"    derived from this software without specific prior written permission
2082657471SMarkus Pfeiffer.\"
2182657471SMarkus Pfeiffer.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
2282657471SMarkus Pfeiffer.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2382657471SMarkus Pfeiffer.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2482657471SMarkus Pfeiffer.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2582657471SMarkus Pfeiffer.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2682657471SMarkus Pfeiffer.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2782657471SMarkus Pfeiffer.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2882657471SMarkus Pfeiffer.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2982657471SMarkus Pfeiffer.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
3082657471SMarkus Pfeiffer.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3182657471SMarkus Pfeiffer.\"
3282657471SMarkus Pfeiffer.\" $FreeBSD: src/lib/libc/gen/msgctl.3,v 1.8.2.7 2003/03/13 18:05:37 trhodes Exp $
3382657471SMarkus Pfeiffer.\"
34*34c6728eSMatthew Dillon.Dd September 13, 2019
3582657471SMarkus Pfeiffer.Dt MSGCTL 2
3682657471SMarkus Pfeiffer.Os
3782657471SMarkus Pfeiffer.Sh NAME
3882657471SMarkus Pfeiffer.Nm msgctl
3982657471SMarkus Pfeiffer.Nd message control operations
4082657471SMarkus Pfeiffer.Sh LIBRARY
4182657471SMarkus Pfeiffer.Lb libc
4282657471SMarkus Pfeiffer.Sh SYNOPSIS
4382657471SMarkus Pfeiffer.In sys/types.h
4482657471SMarkus Pfeiffer.In sys/ipc.h
4582657471SMarkus Pfeiffer.In sys/msg.h
4682657471SMarkus Pfeiffer.Ft int
4782657471SMarkus Pfeiffer.Fn msgctl "int msqid" "int cmd" "struct msqid_ds *buf"
4882657471SMarkus Pfeiffer.Sh DESCRIPTION
4982657471SMarkus PfeifferThe
5082657471SMarkus Pfeiffer.Fn msgctl
5182657471SMarkus Pfeiffersystem call performs some control operations on the message queue specified
5282657471SMarkus Pfeifferby
5382657471SMarkus Pfeiffer.Fa msqid .
5482657471SMarkus Pfeiffer.Pp
5582657471SMarkus PfeifferEach message queue has a data structure associated with it, parts of which
5682657471SMarkus Pfeiffermay be altered by
5782657471SMarkus Pfeiffer.Fn msgctl
5882657471SMarkus Pfeifferand parts of which determine the actions of
5982657471SMarkus Pfeiffer.Fn msgctl .
6082657471SMarkus PfeifferThe data structure is defined in
6182657471SMarkus Pfeiffer.In sys/msg.h
6282657471SMarkus Pfeifferand contains (amongst others) the following members:
6382657471SMarkus Pfeiffer.Bd -literal
6482657471SMarkus Pfeifferstruct msqid_ds {
6582657471SMarkus Pfeiffer	struct	ipc_perm msg_perm;	/* msg queue permission bits */
6682657471SMarkus Pfeiffer	struct	msg *msg_first;	/* first message in the queue */
6782657471SMarkus Pfeiffer	struct	msg *msg_last;	/* last message in the queue */
6882657471SMarkus Pfeiffer	u_long	msg_cbytes;	/* number of bytes in use on the queue */
6982657471SMarkus Pfeiffer	u_long	msg_qnum;	/* number of msgs in the queue */
7082657471SMarkus Pfeiffer	u_long	msg_qbytes;	/* max # of bytes on the queue */
7182657471SMarkus Pfeiffer	pid_t	msg_lspid;	/* pid of last msgsnd() */
7282657471SMarkus Pfeiffer	pid_t	msg_lrpid;	/* pid of last msgrcv() */
7382657471SMarkus Pfeiffer	time_t	msg_stime;	/* time of last msgsnd() */
7482657471SMarkus Pfeiffer	long	msg_pad1;
7582657471SMarkus Pfeiffer	time_t	msg_rtime;	/* time of last msgrcv() */
7682657471SMarkus Pfeiffer	long	msg_pad2;
7782657471SMarkus Pfeiffer	time_t	msg_ctime;	/* time of last msgctl() */
7882657471SMarkus Pfeiffer	long	msg_pad3;
7982657471SMarkus Pfeiffer	long	msg_pad4[4];
8082657471SMarkus Pfeiffer};
8182657471SMarkus Pfeiffer.Ed
8282657471SMarkus Pfeiffer.Pp
8382657471SMarkus PfeifferThe
8482657471SMarkus Pfeiffer.Vt ipc_perm
8582657471SMarkus Pfeifferstructure used inside the
86b551e98fSSascha Wildner.Vt msqid_ds
8782657471SMarkus Pfeifferstructure is defined in
8882657471SMarkus Pfeiffer.In sys/ipc.h
8982657471SMarkus Pfeifferand looks like this:
9082657471SMarkus Pfeiffer.Bd -literal
9182657471SMarkus Pfeifferstruct ipc_perm {
92*34c6728eSMatthew Dillon	uid_t	cuid;	/* creator user id */
93*34c6728eSMatthew Dillon	gid_t	cgid;	/* creator group id */
94*34c6728eSMatthew Dillon	uid_t	uid;	/* user id */
95*34c6728eSMatthew Dillon	gid_t	gid;	/* group id */
96*34c6728eSMatthew Dillon	mode_t	mode;	/* r/w permission */
9782657471SMarkus Pfeiffer	ushort	seq;	/* sequence # (to generate unique msg/sem/shm id) */
9882657471SMarkus Pfeiffer	key_t	key;	/* user specified msg/sem/shm key */
9982657471SMarkus Pfeiffer};
10082657471SMarkus Pfeiffer.Ed
10182657471SMarkus Pfeiffer.Pp
10282657471SMarkus PfeifferThe operation to be performed by
10382657471SMarkus Pfeiffer.Fn msgctl
10482657471SMarkus Pfeifferis specified in
10582657471SMarkus Pfeiffer.Fa cmd
10682657471SMarkus Pfeifferand is one of:
1073f701e98SSascha Wildner.Bl -tag -width ".Dv IPC_RMIDX"
10882657471SMarkus Pfeiffer.It Dv IPC_STAT
10982657471SMarkus PfeifferGather information about the message queue and place it in the
11082657471SMarkus Pfeifferstructure pointed to by
11182657471SMarkus Pfeiffer.Fa buf .
11282657471SMarkus Pfeiffer.It Dv IPC_SET
11382657471SMarkus PfeifferSet the value of the
11482657471SMarkus Pfeiffer.Va msg_perm.uid ,
11582657471SMarkus Pfeiffer.Va msg_perm.gid ,
11682657471SMarkus Pfeiffer.Va msg_perm.mode
11782657471SMarkus Pfeifferand
11882657471SMarkus Pfeiffer.Va msg_qbytes
11982657471SMarkus Pfeifferfields in the structure associated with
12082657471SMarkus Pfeiffer.Fa msqid .
12182657471SMarkus PfeifferThe values are taken from the corresponding fields in the structure
12282657471SMarkus Pfeifferpointed to by
12382657471SMarkus Pfeiffer.Fa buf .
12482657471SMarkus PfeifferThis operation can only be executed by the super-user, or a process that
12582657471SMarkus Pfeifferhas an effective user id equal to either
12682657471SMarkus Pfeiffer.Va msg_perm.cuid
12782657471SMarkus Pfeifferor
12882657471SMarkus Pfeiffer.Va msg_perm.uid
12982657471SMarkus Pfeifferin the data structure associated with the message queue.
13082657471SMarkus PfeifferThe value of
13182657471SMarkus Pfeiffer.Va msg_qbytes
13282657471SMarkus Pfeiffercan only be increased by the super-user.
13382657471SMarkus PfeifferValues for
13482657471SMarkus Pfeiffer.Va msg_qbytes
13582657471SMarkus Pfeifferthat exceed the system limit (MSGMNB from
13682657471SMarkus Pfeiffer.In sys/msg.h )
13782657471SMarkus Pfeifferare silently truncated to that limit.
13882657471SMarkus Pfeiffer.It Dv IPC_RMID
13982657471SMarkus PfeifferRemove the message queue specified by
14082657471SMarkus Pfeiffer.Fa msqid
14182657471SMarkus Pfeifferand destroy the data associated with it.
14282657471SMarkus PfeifferOnly the super-user or a process
14382657471SMarkus Pfeifferwith an effective uid equal to the
14482657471SMarkus Pfeiffer.Va msg_perm.cuid
14582657471SMarkus Pfeifferor
14682657471SMarkus Pfeiffer.Va msg_perm.uid
14782657471SMarkus Pfeiffervalues in the data structure associated with the queue can do this.
14882657471SMarkus Pfeiffer.El
14982657471SMarkus Pfeiffer.Pp
15082657471SMarkus PfeifferThe permission to read from or write to a message queue (see
15182657471SMarkus Pfeiffer.Xr msgsnd 2
15282657471SMarkus Pfeifferand
15382657471SMarkus Pfeiffer.Xr msgrcv 2 )
15482657471SMarkus Pfeifferis determined by the
15582657471SMarkus Pfeiffer.Va msg_perm.mode
15682657471SMarkus Pfeifferfield in the same way as is
15782657471SMarkus Pfeifferdone with files (see
15882657471SMarkus Pfeiffer.Xr chmod 2 ) ,
15982657471SMarkus Pfeifferbut the effective uid can match either the
16082657471SMarkus Pfeiffer.Va msg_perm.cuid
16182657471SMarkus Pfeifferfield or the
16282657471SMarkus Pfeiffer.Va msg_perm.uid
16382657471SMarkus Pfeifferfield, and the
16482657471SMarkus Pfeiffereffective gid can match either
16582657471SMarkus Pfeiffer.Va msg_perm.cgid
16682657471SMarkus Pfeifferor
16782657471SMarkus Pfeiffer.Va msg_perm.gid .
16882657471SMarkus Pfeiffer.Sh RETURN VALUES
16982657471SMarkus Pfeiffer.Rv -std msgctl
17082657471SMarkus Pfeiffer.Sh ENVIRONMENT
17182657471SMarkus PfeifferThe XSI Interprocess Communication family of functions is also available
17282657471SMarkus Pfeifferas an implementation in userspace.
17382657471SMarkus PfeifferTo use it, the
17482657471SMarkus Pfeiffer.Xr sysvipcd 8
17582657471SMarkus Pfeifferdaemon has to be running.
17682657471SMarkus Pfeiffer.Pp
17782657471SMarkus PfeifferIf the
17882657471SMarkus Pfeiffer.Ev USR_SYSVIPC
17982657471SMarkus Pfeiffervariable is set in a process' environment, the process and its children
18082657471SMarkus Pfeifferwill use the userspace implementation.
18182657471SMarkus Pfeiffer.Sh ERRORS
18282657471SMarkus PfeifferThe
18382657471SMarkus Pfeiffer.Fn msgctl
18482657471SMarkus Pfeiffersystem call will fail if:
18582657471SMarkus Pfeiffer.Bl -tag -width Er
18682657471SMarkus Pfeiffer.It Bq Er EPERM
18782657471SMarkus PfeifferThe
18882657471SMarkus Pfeiffer.Fa cmd
18982657471SMarkus Pfeifferargument
1903f701e98SSascha Wildneris equal to
1913f701e98SSascha Wildner.Dv IPC_SET
1923f701e98SSascha Wildneror
1933f701e98SSascha Wildner.Dv IPC_RMID
1943f701e98SSascha Wildnerand the caller is not the super-user, nor does
19582657471SMarkus Pfeifferthe effective uid match either the
19682657471SMarkus Pfeiffer.Va msg_perm.uid
19782657471SMarkus Pfeifferor
19882657471SMarkus Pfeiffer.Va msg_perm.cuid
19982657471SMarkus Pfeifferfields of the data structure associated with the message queue.
20082657471SMarkus Pfeiffer.Pp
20182657471SMarkus PfeifferAn attempt is made to increase the value of
20282657471SMarkus Pfeiffer.Va msg_qbytes
2033f701e98SSascha Wildnerthrough
2043f701e98SSascha Wildner.Dv IPC_SET
20582657471SMarkus Pfeifferbut the caller is not the super-user.
20682657471SMarkus Pfeiffer.It Bq Er EACCES
2073f701e98SSascha WildnerThe command is
2083f701e98SSascha Wildner.Dv IPC_STAT
20982657471SMarkus Pfeifferand the caller has no read permission for this message queue.
21082657471SMarkus Pfeiffer.It Bq Er EINVAL
21182657471SMarkus PfeifferThe
21282657471SMarkus Pfeiffer.Fa msqid
21382657471SMarkus Pfeifferargument
21482657471SMarkus Pfeifferis not a valid message queue identifier.
21582657471SMarkus Pfeiffer.Pp
21682657471SMarkus Pfeiffer.Va cmd
21782657471SMarkus Pfeifferis not a valid command.
21882657471SMarkus Pfeiffer.It Bq Er EFAULT
21982657471SMarkus PfeifferThe
22082657471SMarkus Pfeiffer.Fa buf
22182657471SMarkus Pfeifferargument
22282657471SMarkus Pfeifferspecifies an invalid address.
22382657471SMarkus Pfeiffer.El
22482657471SMarkus Pfeiffer.Sh SEE ALSO
22582657471SMarkus Pfeiffer.Xr msgget 2 ,
22682657471SMarkus Pfeiffer.Xr msgrcv 2 ,
22782657471SMarkus Pfeiffer.Xr msgsnd 2
22882657471SMarkus Pfeiffer.Sh HISTORY
22982657471SMarkus PfeifferMessage queues appeared in the first release of
23082657471SMarkus Pfeiffer.At V .
23182657471SMarkus Pfeiffer.Sh AUTHORS
23282657471SMarkus Pfeiffer.An -nosplit
23382657471SMarkus PfeifferThe
23482657471SMarkus Pfeiffer.Dx
23582657471SMarkus Pfeifferspecific userspace implementation (see
23682657471SMarkus Pfeiffer.Sx ENVIRONMENT )
23782657471SMarkus Pfeifferwas written by
23882657471SMarkus Pfeiffer.An Larisa Grigore .
239