xref: /dflybsd-src/lib/libc/sys/msgrcv.2 (revision 3f701e9876cd0189658fbff416435e25fd6d3d4f)
182657471SMarkus Pfeiffer.\"	$NetBSD: msgrcv.2,v 1.1 1995/10/16 23:49:20 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/msgrcv.3,v 1.8.2.7 2003/03/15 15:11:05 trhodes Exp $
3382657471SMarkus Pfeiffer.\"
348e1dfd3aSSascha Wildner.Dd January 4, 2014
3582657471SMarkus Pfeiffer.Dt MSGRCV 2
3682657471SMarkus Pfeiffer.Os
3782657471SMarkus Pfeiffer.Sh NAME
3882657471SMarkus Pfeiffer.Nm msgrcv
3982657471SMarkus Pfeiffer.Nd receive a message from a message queue
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 msgrcv "int msqid" "void *msgp" "size_t msgsz" "long msgtyp" "int msgflg"
4882657471SMarkus Pfeiffer.Sh DESCRIPTION
4982657471SMarkus PfeifferThe
5082657471SMarkus Pfeiffer.Fn msgrcv
5182657471SMarkus Pfeiffersystem call receives a message from the message queue specified in
5282657471SMarkus Pfeiffer.Fa msqid ,
5382657471SMarkus Pfeifferand places it into the structure pointed to by
5482657471SMarkus Pfeiffer.Fa msgp .
5582657471SMarkus PfeifferThis structure should consist of the following members:
5682657471SMarkus Pfeiffer.Bd -literal
5782657471SMarkus Pfeiffer    long mtype;    /* message type */
5882657471SMarkus Pfeiffer    char mtext[1]; /* body of message */
5982657471SMarkus Pfeiffer.Ed
6082657471SMarkus Pfeiffer.Pp
6182657471SMarkus Pfeiffer.Va mtype
6282657471SMarkus Pfeifferis an integer greater than 0 that can be used for selecting messages,
6382657471SMarkus Pfeiffer.Va mtext
6482657471SMarkus Pfeifferis an array of bytes, with a size up to that of the system limit
6582657471SMarkus Pfeiffer.Pf ( Dv MSGMAX ) .
6682657471SMarkus Pfeiffer.Pp
6782657471SMarkus PfeifferThe value of
6882657471SMarkus Pfeiffer.Fa msgtyp
6982657471SMarkus Pfeifferhas one of the following meanings:
7082657471SMarkus Pfeiffer.Bl -bullet
7182657471SMarkus Pfeiffer.It
7282657471SMarkus PfeifferThe
7382657471SMarkus Pfeiffer.Fa msgtyp
7482657471SMarkus Pfeifferargument
75*3f701e98SSascha Wildneris greater than 0.
76*3f701e98SSascha WildnerThe first message of type
7782657471SMarkus Pfeiffer.Fa msgtyp
7882657471SMarkus Pfeifferwill be received.
7982657471SMarkus Pfeiffer.It
8082657471SMarkus PfeifferThe
8182657471SMarkus Pfeiffer.Fa msgtyp
8282657471SMarkus Pfeifferargument
83*3f701e98SSascha Wildneris equal to 0.
84*3f701e98SSascha WildnerThe first message on the queue will be received.
8582657471SMarkus Pfeiffer.It
8682657471SMarkus PfeifferThe
8782657471SMarkus Pfeiffer.Fa msgtyp
8882657471SMarkus Pfeifferargument
89*3f701e98SSascha Wildneris less than 0.
90*3f701e98SSascha WildnerThe first message of the lowest message type that is
9182657471SMarkus Pfeifferless than or equal to the absolute value of
9282657471SMarkus Pfeiffer.Fa msgtyp
9382657471SMarkus Pfeifferwill be received.
9482657471SMarkus Pfeiffer.El
9582657471SMarkus Pfeiffer.Pp
9682657471SMarkus PfeifferThe
9782657471SMarkus Pfeiffer.Fa msgsz
9882657471SMarkus Pfeifferargument
9982657471SMarkus Pfeifferspecifies the maximum length of the requested message.
10082657471SMarkus PfeifferIf the received
10182657471SMarkus Pfeiffermessage has a length greater than
10282657471SMarkus Pfeiffer.Fa msgsz
10382657471SMarkus Pfeifferit will be silently truncated if the
10482657471SMarkus Pfeiffer.Dv MSG_NOERROR
10582657471SMarkus Pfeifferflag is set in
10682657471SMarkus Pfeiffer.Fa msgflg ,
10782657471SMarkus Pfeifferotherwise an error will be returned.
10882657471SMarkus Pfeiffer.Pp
10982657471SMarkus PfeifferIf no matching message is present on the message queue specified by
11082657471SMarkus Pfeiffer.Fa msqid ,
11182657471SMarkus Pfeifferthe behavior of
11282657471SMarkus Pfeiffer.Fn msgrcv
11382657471SMarkus Pfeifferdepends on whether the
11482657471SMarkus Pfeiffer.Dv IPC_NOWAIT
11582657471SMarkus Pfeifferflag is set in
11682657471SMarkus Pfeiffer.Fa msgflg
11782657471SMarkus Pfeifferor not.
11882657471SMarkus PfeifferIf
11982657471SMarkus Pfeiffer.Dv IPC_NOWAIT
12082657471SMarkus Pfeifferis set,
12182657471SMarkus Pfeiffer.Fn msgrcv
12282657471SMarkus Pfeifferwill immediately return a value of -1, and set
12382657471SMarkus Pfeiffer.Va errno
12482657471SMarkus Pfeifferto
12582657471SMarkus Pfeiffer.Er EAGAIN .
12682657471SMarkus PfeifferIf
12782657471SMarkus Pfeiffer.Dv IPC_NOWAIT
12882657471SMarkus Pfeifferis not set, the calling process will be blocked
12982657471SMarkus Pfeifferuntil:
13082657471SMarkus Pfeiffer.Bl -bullet
13182657471SMarkus Pfeiffer.It
13282657471SMarkus PfeifferA message of the requested type becomes available on the message queue.
13382657471SMarkus Pfeiffer.It
13482657471SMarkus PfeifferThe message queue is removed, in which case -1 will be returned, and
13582657471SMarkus Pfeiffer.Va errno
13682657471SMarkus Pfeifferset to
13782657471SMarkus Pfeiffer.Er EINVAL .
13882657471SMarkus Pfeiffer.It
139*3f701e98SSascha WildnerA signal is received and caught.
140*3f701e98SSascha Wildner-1 is returned, and
14182657471SMarkus Pfeiffer.Va errno
14282657471SMarkus Pfeifferset to
14382657471SMarkus Pfeiffer.Er EINTR .
14482657471SMarkus Pfeiffer.El
14582657471SMarkus Pfeiffer.Pp
14682657471SMarkus PfeifferIf a message is successfully received, the data structure associated with
14782657471SMarkus Pfeiffer.Fa msqid
14882657471SMarkus Pfeifferis updated as follows:
14982657471SMarkus Pfeiffer.Bl -bullet
15082657471SMarkus Pfeiffer.It
15182657471SMarkus Pfeiffer.Va msg_cbytes
15282657471SMarkus Pfeifferis decremented by the size of the message.
15382657471SMarkus Pfeiffer.It
15482657471SMarkus Pfeiffer.Va msg_lrpid
15582657471SMarkus Pfeifferis set to the pid of the caller.
15682657471SMarkus Pfeiffer.It
15782657471SMarkus Pfeiffer.Va msg_lrtime
15882657471SMarkus Pfeifferis set to the current time.
15982657471SMarkus Pfeiffer.It
16082657471SMarkus Pfeiffer.Va msg_qnum
16182657471SMarkus Pfeifferis decremented by 1.
16282657471SMarkus Pfeiffer.El
16382657471SMarkus Pfeiffer.Sh RETURN VALUES
16482657471SMarkus PfeifferUpon successful completion,
16582657471SMarkus Pfeiffer.Fn msgrcv
16682657471SMarkus Pfeifferreturns the number of bytes received into the
16782657471SMarkus Pfeiffer.Va mtext
16882657471SMarkus Pfeifferfield of the structure pointed to by
16982657471SMarkus Pfeiffer.Fa msgp .
17082657471SMarkus PfeifferOtherwise, -1 is returned, and
17182657471SMarkus Pfeiffer.Va errno
17282657471SMarkus Pfeifferset to indicate the error.
17382657471SMarkus Pfeiffer.Sh ENVIRONMENT
17482657471SMarkus PfeifferThe XSI Interprocess Communication family of functions is also available
17582657471SMarkus Pfeifferas an implementation in userspace.
17682657471SMarkus PfeifferTo use it, the
17782657471SMarkus Pfeiffer.Xr sysvipcd 8
17882657471SMarkus Pfeifferdaemon has to be running.
17982657471SMarkus Pfeiffer.Pp
18082657471SMarkus PfeifferIf the
18182657471SMarkus Pfeiffer.Ev USR_SYSVIPC
18282657471SMarkus Pfeiffervariable is set in a process' environment, the process and its children
18382657471SMarkus Pfeifferwill use the userspace implementation.
18482657471SMarkus Pfeiffer.Sh ERRORS
18582657471SMarkus PfeifferThe
18682657471SMarkus Pfeiffer.Fn msgrcv
18782657471SMarkus Pfeiffersystem call will fail if:
18882657471SMarkus Pfeiffer.Bl -tag -width Er
18982657471SMarkus Pfeiffer.It Bq Er EINVAL
19082657471SMarkus PfeifferThe
19182657471SMarkus Pfeiffer.Fa msqid
19282657471SMarkus Pfeifferargument
19382657471SMarkus Pfeifferis not a valid message queue identifier.
19482657471SMarkus Pfeiffer.Pp
19582657471SMarkus PfeifferThe message queue was removed while
19682657471SMarkus Pfeiffer.Fn msgrcv
19782657471SMarkus Pfeifferwas waiting for a message of the requested type to become available on it.
19882657471SMarkus Pfeiffer.Pp
19982657471SMarkus PfeifferThe
20082657471SMarkus Pfeiffer.Fa msgsz
20182657471SMarkus Pfeifferargument
20282657471SMarkus Pfeifferis less than 0.
20382657471SMarkus Pfeiffer.It Bq Er E2BIG
20482657471SMarkus PfeifferA matching message was received, but its size was greater than
20582657471SMarkus Pfeiffer.Fa msgsz
20682657471SMarkus Pfeifferand the
20782657471SMarkus Pfeiffer.Dv MSG_NOERROR
20882657471SMarkus Pfeifferflag was not set in
20982657471SMarkus Pfeiffer.Fa msgflg .
21082657471SMarkus Pfeiffer.It Bq Er EACCES
21182657471SMarkus PfeifferThe calling process does not have read access to the message queue.
21282657471SMarkus Pfeiffer.It Bq Er EFAULT
21382657471SMarkus PfeifferThe
21482657471SMarkus Pfeiffer.Fa msgp
21582657471SMarkus Pfeifferargument
21682657471SMarkus Pfeifferpoints to an invalid address.
21782657471SMarkus Pfeiffer.It Bq Er EINTR
21882657471SMarkus PfeifferThe system call was interrupted by the delivery of a signal.
21982657471SMarkus Pfeiffer.It Bq Er EAGAIN
22082657471SMarkus PfeifferThere is no message of the requested type available on the message queue,
22182657471SMarkus Pfeifferand
22282657471SMarkus Pfeiffer.Dv IPC_NOWAIT
22382657471SMarkus Pfeifferis set in
22482657471SMarkus Pfeiffer.Fa msgflg .
22582657471SMarkus Pfeiffer.El
22682657471SMarkus Pfeiffer.Sh SEE ALSO
22782657471SMarkus Pfeiffer.Xr msgctl 2 ,
22882657471SMarkus Pfeiffer.Xr msgget 2 ,
22982657471SMarkus Pfeiffer.Xr msgsnd 2
23082657471SMarkus Pfeiffer.Sh HISTORY
23182657471SMarkus PfeifferMessage queues appeared in the first release of
23282657471SMarkus Pfeiffer.At V .
23382657471SMarkus Pfeiffer.Sh AUTHORS
23482657471SMarkus Pfeiffer.An -nosplit
23582657471SMarkus PfeifferThe
23682657471SMarkus Pfeiffer.Dx
23782657471SMarkus Pfeifferspecific userspace implementation (see
23882657471SMarkus Pfeiffer.Sx ENVIRONMENT )
23982657471SMarkus Pfeifferwas written by
24082657471SMarkus Pfeiffer.An Larisa Grigore .
24182657471SMarkus Pfeiffer.Sh BUGS
24282657471SMarkus Pfeiffer.Nx ,
24382657471SMarkus Pfeiffer.Dx ,
24482657471SMarkus Pfeifferand
24582657471SMarkus Pfeiffer.Fx
24682657471SMarkus Pfeifferdo not define the
24782657471SMarkus Pfeiffer.Er EIDRM
24882657471SMarkus Pfeiffererror value, which should be used in
24982657471SMarkus Pfeifferthe case of a removed message queue, nor the
25082657471SMarkus Pfeiffer.Er ENOMSG
25182657471SMarkus Pfeiffervalue, which
25282657471SMarkus Pfeiffershould be used when no suitable message is available and
25382657471SMarkus Pfeiffer.Dv IPC_NOWAIT
25482657471SMarkus Pfeifferis set.
255