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