xref: /openbsd/lib/libc/sys/msgsnd.2 (revision 76d0caae)
1.\"	$OpenBSD: msgsnd.2,v 1.21 2019/07/18 13:45:03 schwarze Exp $
2.\"	$NetBSD: msgsnd.2,v 1.2 1997/03/27 08:20:36 mikel Exp $
3.\"
4.\" Copyright (c) 1995 Frank van der Linden
5.\" All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. All advertising materials mentioning features or use of this software
16.\"    must display the following acknowledgement:
17.\"      This product includes software developed for the NetBSD Project
18.\"      by Frank van der Linden
19.\" 4. The name of the author may not be used to endorse or promote products
20.\"    derived from this software without specific prior written permission
21.\"
22.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32.\"/
33.Dd $Mdocdate: July 18 2019 $
34.Dt MSGSND 2
35.Os
36.Sh NAME
37.Nm msgsnd
38.Nd send a message to a message queue
39.Sh SYNOPSIS
40.In sys/msg.h
41.Ft int
42.Fn msgsnd "int msqid" "const void *msgp" "size_t msgsz" "int msgflg"
43.Sh DESCRIPTION
44The
45.Fn msgsnd
46function sends a message to the message queue specified by
47.Fa msqid .
48.Fa msgp
49points to a structure containing the message.
50This structure should consist of the following members:
51.Bd -literal -offset indent
52long mtype;    /* message type */
53char mtext[1]; /* body of message */
54.Ed
55.Pp
56.Fa mtype
57is an integer greater than 0 that can be used for selecting messages (see
58.Xr msgrcv 2 ) ;
59.Fa mtext
60is an array of
61.Fa msgsz
62bytes, with a size between 0 and that of the system limit
63.Pq Dv MSGMAX .
64.Pp
65If the number of bytes already on the message queue plus
66.Fa msgsz
67is bigger than the maximum number of bytes on the message queue
68.Po Fa msg_qbytes ,
69 see
70.Xr msgctl 2
71.Pc ,
72or the number of messages on all queues system-wide is already equal to
73the system limit,
74.Fa msgflg
75determines the action of
76.Fn msgsnd .
77If
78.Fa msgflg
79has
80.Dv IPC_NOWAIT
81mask set in it, the call will return immediately.
82If
83.Fa msgflg
84does not have
85.Dv IPC_NOWAIT
86set in it, the call will block until:
87.Bl -bullet
88.It
89The condition which caused the call to block does no longer exist.
90The message will be sent.
91.It
92The message queue is removed, in which case \-1 will be returned, and
93.Va errno
94is set to
95.Er EIDRM .
96.It
97The caller catches a signal.
98The call returns with
99.Va errno
100set to
101.Er EINTR .
102.El
103.Pp
104After a successful call, the data structure associated with the message
105queue is updated in the following way:
106.Bl -bullet
107.It
108.Fa msg_cbytes
109is incremented by the size of the message.
110.It
111.Fa msg_qnum
112is incremented by 1.
113.It
114.Fa msg_lspid
115is set to the pid of the calling process.
116.It
117.Fa msg_stime
118is set to the current time.
119.El
120.Sh RETURN VALUES
121.Rv -std
122.Sh ERRORS
123.Fn msgsnd
124will fail if:
125.Bl -tag -width Er
126.It Bq Er EINVAL
127.Fa msqid
128is not a valid message queue identifier.
129.Pp
130.Fa mtype
131is less than 1.
132.Pp
133.Fa msgsz
134is greater than
135.Fa msg_qbytes .
136.It Bq Er EACCES
137The calling process does not have write access to the message queue.
138.It Bq Er EAGAIN
139There was no space for this message either on the queue, or in the whole
140system, and
141.Dv IPC_NOWAIT
142was set in
143.Fa msgflg .
144.It Bq Er EFAULT
145.Fa msgp
146points to an invalid address.
147.It Bq Er EINTR
148The system call was interrupted by the delivery of a signal.
149.It Bq Er EIDRM
150The message queue was removed while
151.Fn msgsnd
152was waiting for a resource to become available in order to deliver the
153message.
154.El
155.Sh SEE ALSO
156.Xr msgctl 2 ,
157.Xr msgget 2 ,
158.Xr msgrcv 2
159.Sh STANDARDS
160The
161.Fn msgsnd
162function conforms to the X/Open System Interfaces option of
163.St -p1003.1-2008 .
164.Sh HISTORY
165Message queues first appeared in
166.At V.1
167and have been available since
168.Nx 1.0 .
169