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 2004 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 */
31 #pragma ident "%Z%%M% %I% %E% SMI"
37 #include <sys/types.h>
38 #include <sys/stropts.h>
49 struct strbuf
*do_peek();
56 * poll_data - it polls the device, waiting for data
57 * - return BADSPEED it <brk> is received
58 * - return the result of process if data is received
59 * - write a newline if <del> is received
60 * - exit if hangup is received
68 struct sigaction sigact
;
71 debug("in poll_data");
73 if (peek_ptr
!= NULL
) {
74 for(j
=0; j
<peek_ptr
->len
; j
++) peek_ptr
->buf
[j
] &= 0x7F;
75 return(process(0,peek_ptr
));
78 fds
[0].events
= POLLIN
;
80 sigact
.sa_handler
= sigint
;
81 (void)sigemptyset(&sigact
.sa_mask
);
82 (void)sigaddset(&sigact
.sa_mask
, SIGINT
);
83 (void)sigaction(SIGINT
, &sigact
, NULL
);
86 if ((j
= poll(fds
,1,-1)) == -1) {
87 if (interrupt
== BRK
) {
90 if (interrupt
== DEL
) { /* XXX revisit kmd */
95 if (fds
[0].revents
& POLLHUP
) {
96 log( "POLLHUP received, about to exit");
99 if (fds
[0].revents
& POLLIN
) {
100 ptr
= do_peek(fds
[0].fd
, 255);
102 return(process(fds
[0].fd
,ptr
));
110 * process - process the data
111 * - return GOODNAME if it is a non-empty line
112 * - return NONAME if a <CR> is received
113 * - return BADNAME if zero byte is detected
114 * - except the case of GOODNAME, data will be pulled out
119 int fd
, /* fd to read data from if necessary */
120 struct strbuf
*ptr
) /* ptr that holds data in ptr->buf */
125 for (i
= 0; i
< ptr
->len
; i
++) {
126 if (ptr
->buf
[i
] == '\0') {
127 (void) read(fd
, junk
, i
+1);
129 } else if ((ptr
->buf
[i
] == '\n') || (ptr
->buf
[i
] == '\r')) {
131 (void) read(fd
, junk
, ptr
->len
);
137 /* end of input is encountered */
139 debug("in process: EOF encountered");
146 * do_peek - peek at the stream to get the data
147 * - this only called when POLLIN is detected,
148 * - so there should always be something there
149 * - return a ptr to the buf that contains the data
150 * - return NULL if nothing to peek at
154 int fd
; /* fd to do the ioctl on */
155 int n
; /* maxlen of data to peek at */
158 static struct strpeek peek
;
159 register struct strpeek
*peekp
;
160 static char buf
[BUFSIZ
];
168 /* need to ask for ctl info to avoid bug in I_PEEK code */
169 peekp
->ctlbuf
.maxlen
= 1;
170 peekp
->ctlbuf
.buf
= buf
;
171 peekp
->databuf
.maxlen
= n
;
172 peekp
->databuf
.buf
= buf
;
173 ret
= ioctl(fd
, I_PEEK
, &peek
);
175 log("do_peek: I_PEEK failed: %s", errno
);
181 return(&(peekp
->databuf
));
185 * sigint - this is called when SIGINT is caught
197 if (ptr
== NULL
) { /* somebody type <del> */
201 if (ptr
->buf
[0] == '\0') {
202 /* somebody type <brk> or frame error */
203 (void)read(0,junk
,1);