2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)tipout.c 8.1 (Berkeley) 6/6/93
30 * $FreeBSD: src/usr.bin/tip/tip/tipout.c,v 1.6.2.2 2001/06/02 08:08:24 phk Exp $
38 * lower fork of tip -- handles passive side
39 * reading from the remote host
42 static jmp_buf sigbuf
;
45 * TIPOUT wait state routine --
46 * sent by TIPIN when it wants to posses the remote host
52 write(repdes
[1],&ccc
,1);
53 read(fildes
[0], &ccc
,1);
58 * Scripting command interpreter --
59 * accepts script file name over the pipe and acts accordingly
68 read(fildes
[0], &c
, 1);
69 while (c
!= '\n' && (size_t)(pline
- line
) < sizeof(line
)) {
71 read(fildes
[0], &c
, 1);
74 if (boolean(value(SCRIPT
)) && fscript
!= NULL
)
77 boolean(value(SCRIPT
)) = FALSE
;
80 if ((fscript
= fopen(line
, "a")) == NULL
)
84 boolean(value(SCRIPT
)) = TRUE
;
87 write(repdes
[1], &reply
, 1);
95 if (boolean(value(SCRIPT
)) && fscript
!= NULL
)
104 boolean(value(BEAUTIFY
)) = !boolean(value(BEAUTIFY
));
109 * ****TIPOUT TIPOUT****
119 signal(SIGINT
, SIG_IGN
);
120 signal(SIGQUIT
, SIG_IGN
);
121 signal(SIGEMT
, intEMT
); /* attention from TIPIN */
122 signal(SIGTERM
, intTERM
); /* time to go signal */
123 signal(SIGIOT
, intIOT
); /* scripting going on signal */
124 signal(SIGHUP
, intTERM
); /* for dial-ups */
125 signal(SIGSYS
, intSYS
); /* beautify toggle */
126 (void) setjmp(sigbuf
);
127 for (omask
= 0;; sigsetmask(omask
)) {
128 cnt
= read(FD
, buf
, BUFSIZ
);
131 if (cnt
< 0 && errno
== EIO
) {
132 sigblock(sigmask(SIGTERM
));
135 } else if (cnt
== 0 && errno
== ENOENT
) {
137 kill(getppid(),SIGUSR1
);
138 sigblock(sigmask(SIGTERM
));
141 } else if (cnt
< 0) {
143 kill(getppid(),SIGUSR1
);
144 sigblock(sigmask(SIGTERM
));
150 #define ALLSIGS sigmask(SIGEMT)|sigmask(SIGTERM)|sigmask(SIGIOT)|sigmask(SIGSYS)
151 omask
= sigblock(ALLSIGS
);
152 for (cp
= buf
; cp
< buf
+ cnt
; cp
++)
154 if (write(1, buf
, cnt
) < 0)
156 if (boolean(value(SCRIPT
)) && fscript
!= NULL
) {
157 if (!boolean(value(BEAUTIFY
))) {
158 fwrite(buf
, 1, cnt
, fscript
);
161 for (cp
= buf
; cp
< buf
+ cnt
; cp
++)
162 if ((*cp
>= ' ' && *cp
<= '~') ||
163 any(*cp
, value(EXCEPTIONS
)))