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