2 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
7 * Copyright (c) 1983 Regents of the University of California.
8 * All rights reserved. The Berkeley software License Agreement
9 * specifies the terms and conditions for redistribution.
12 #pragma ident "%Z%%M% %I% %E% SMI"
20 * lower fork of tip -- handles passive side
21 * reading from the remote host
24 static sigjmp_buf sigbuf
;
27 * TIPOUT wait state routine --
28 * sent by TIPIN when it wants to posses the remote host
34 (void) write(repdes
[1], &ccc
, 1);
35 (void) read(fildes
[0], &ccc
, 1);
36 siglongjmp(sigbuf
, 1);
40 * Scripting command interpreter --
41 * accepts script file name over the pipe and acts accordingly
46 char c
, line
[PATH_MAX
];
50 (void) read(fildes
[0], &c
, 1);
51 while (c
!= '\n' && line
+ sizeof (line
) - pline
> 1) {
53 (void) read(fildes
[0], &c
, 1);
56 if (boolean(value(SCRIPT
)) && fscript
!= NULL
)
57 (void) fclose(fscript
);
59 boolean(value(SCRIPT
)) = FALSE
;
62 if ((fscript
= fopen(line
, "a")) == NULL
)
66 boolean(value(SCRIPT
)) = TRUE
;
69 (void) write(repdes
[1], &reply
, 1);
70 siglongjmp(sigbuf
, 1);
77 if (boolean(value(SCRIPT
)) && fscript
!= NULL
)
78 (void) fclose(fscript
);
86 boolean(value(BEAUTIFY
)) = !boolean(value(BEAUTIFY
));
87 siglongjmp(sigbuf
, 1);
91 * ****TIPOUT TIPOUT****
99 sigset_t omask
, bmask
, tmask
;
101 (void) signal(SIGINT
, SIG_IGN
);
102 (void) signal(SIGQUIT
, SIG_IGN
);
103 /* attention from TIPIN */
104 (void) signal(SIGEMT
, (sig_handler_t
)intEMT
);
105 /* time to go signal */
106 (void) signal(SIGTERM
, (sig_handler_t
)intTERM
);
107 /* scripting going on signal */
108 (void) signal(SIGIOT
, (sig_handler_t
)intIOT
);
110 (void) signal(SIGHUP
, (sig_handler_t
)intTERM
);
111 /* beautify toggle */
112 (void) signal(SIGSYS
, (sig_handler_t
)intSYS
);
113 (void) sigsetjmp(sigbuf
, 1);
115 (void) sigemptyset(&omask
);
116 (void) sigemptyset(&bmask
);
117 (void) sigaddset(&bmask
, SIGEMT
);
118 (void) sigaddset(&bmask
, SIGTERM
);
119 (void) sigaddset(&bmask
, SIGIOT
);
120 (void) sigaddset(&bmask
, SIGSYS
);
121 (void) sigemptyset(&tmask
);
122 (void) sigaddset(&tmask
, SIGTERM
);
124 cnt
= read(FD
, buf
, BUFSIZ
);
127 * If dialback is specified, ignore the hangup
128 * and clear the hangup condition on the device.
130 if (cnt
== 0 && DB
) {
134 if ((fd
= open(DV
, O_RDWR
)) >= 0) {
141 if ((cnt
< 0 && errno
== EIO
) ||
143 (void) sigprocmask(SIG_BLOCK
, &tmask
, NULL
);
148 (void) sigprocmask(SIG_BLOCK
, &bmask
, &omask
);
150 for (cp
= buf
; cp
< buf
+ cnt
; cp
++)
153 (void) write(1, buf
, cnt
);
154 if (boolean(value(SCRIPT
)) && fscript
!= NULL
) {
155 if (!boolean(value(BEAUTIFY
))) {
156 (void) fwrite(buf
, 1, cnt
, fscript
);
158 for (cp
= buf
; cp
< buf
+ cnt
; cp
++)
159 if ((*cp
>= ' ' && *cp
<= '~')||
160 any(*cp
, value(EXCEPTIONS
)))
166 (void) sigprocmask(SIG_SETMASK
, &omask
, NULL
);