4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1997 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
32 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2 */
46 * non-zero: return code of the failed putmsg() system call.
47 * plus errno for caller to check.
48 * NOTE: cannot do TRACE* calls if errno is expected to be returned!
49 * TRACE* uses fprintf and destroys the content of errno.
50 * Save errno before the TRACE* calls.
54 Putmsg (MESG
*mdp
, strbuf_t
*ctlp
, strbuf_t
*datap
, int flags
)
61 fds
.fd
= mdp
->writefd
;
65 (void) poll(&fds
, 1, 1000);
66 if (fds
.revents
& (POLLHUP
| POLLERR
| POLLNVAL
)) {
71 if (!(fds
.revents
& POLLOUT
)) {
76 rtncode
= putmsg (mdp
->writefd
, ctlp
, datap
, flags
);
81 Getmsg (MESG
*mdp
, strbuf_t
*ctlp
, strbuf_t
*datap
, int *flagsp
)
85 rtncode
= getmsg (mdp
->readfd
, ctlp
, datap
, flagsp
);
89 char AuthCode
[HEAD_AUTHCODE_LEN
];
90 static void (*callers_sigpipe_trap
)() = SIG_DFL
;
94 ** Function: static int read3_2( MESG *, char *, int)
95 ** Args: message descriptor
96 ** message buffer (var)
98 ** Return: 0 for sucess, -1 for failure
100 ** This performs a 3.2 HPI style read_fifo on the pipe referanced
101 ** in the message descriptor. If a message is found, it is returned
102 ** in message buffer.
104 int read3_2 ( MESG
* md
, char *msgbuf
, int size
)
108 if (md
->type
== MD_USR_FIFO
)
109 (void) Close (Open(md
->file
, O_RDONLY
, 0));
113 switch (read_fifo(md
->readfd
, msgbuf
, size
))
120 ** The fifo was empty and we have O_NDELAY set,
121 ** or the Spooler closed our FIFO.
122 ** We don't set O_NDELAY in the user process,
123 ** so that should never happen. But be warned
124 ** that we can't tell the difference in some versions
125 ** of the UNIX op. sys.!!
132 if ((type
= stoh(msgbuf
+ HEAD_TYPE
)) < 0 || LAST_MESSAGE
< type
)
138 while (type
== I_QUEUE_CHK
);
140 (void)memcpy (AuthCode
, msgbuf
+ HEAD_AUTHCODE
, HEAD_AUTHCODE_LEN
);
143 ** Get the size from the 3.2 HPI message
144 ** minus the size of the control data
145 ** Copy the actual message
146 ** Reset the message size.
148 size
= stoh(msgbuf
+ HEAD_SIZE
) - EXCESS_3_2_LEN
;
149 memmove(msgbuf
, msgbuf
+ HEAD_SIZE
, size
);
150 (void) htos(msgbuf
+ MESG_SIZE
, size
);
154 int write3_2 ( MESG
* md
, char * msgbuf
, int size
)
156 char tmpbuf
[MSGMAX
+ EXCESS_3_2_LEN
];
160 (void) memmove(tmpbuf
+ HEAD_SIZE
, msgbuf
, size
);
161 (void) htos(tmpbuf
+ HEAD_SIZE
, size
+ EXCESS_3_2_LEN
);
162 (void) memcpy (tmpbuf
+ HEAD_AUTHCODE
, AuthCode
, HEAD_AUTHCODE_LEN
);
164 callers_sigpipe_trap
= signal(SIGPIPE
, SIG_IGN
);
166 rval
= write_fifo(md
->writefd
, tmpbuf
, size
+ EXCESS_3_2_LEN
);
168 (void) signal(SIGPIPE
, callers_sigpipe_trap
);