Пример #1
0
/*
 * ****TIPOUT   TIPOUT****
 */
void
tipout(void)
{
	char buf[BUFSIZ];
	char *cp;
	int cnt;
	int omask;

	signal(SIGINT, SIG_IGN);
	signal(SIGQUIT, SIG_IGN);
	signal(SIGEMT, intEMT);		/* attention from TIPIN */
	signal(SIGTERM, intTERM);	/* time to go signal */
	signal(SIGIOT, intIOT);		/* scripting going on signal */
	signal(SIGHUP, intTERM);	/* for dial-ups */
	signal(SIGSYS, intSYS);		/* beautify toggle */
	(void) setjmp(sigbuf);
	for (omask = 0;; sigsetmask(omask)) {
		cnt = read(FD, buf, BUFSIZ);
		if (cnt <= 0) {
			/* lost carrier */
			if (cnt < 0 && errno == EIO) {
				sigblock(sigmask(SIGTERM));
				intTERM(0);
				/*NOTREACHED*/
			} else if (cnt == 0 && errno == ENOENT) {
				if (getppid() != 1)
					kill(getppid(),SIGUSR1);
				sigblock(sigmask(SIGTERM));
				intTERM(0);
				/*NOTREACHED*/
			} else if (cnt < 0) {
				if (getppid() != 1)
					kill(getppid(),SIGUSR1);
				sigblock(sigmask(SIGTERM));
				intTERM(0);
				/*NOTREACHED*/
			}
			continue;
		}
#define	ALLSIGS	sigmask(SIGEMT)|sigmask(SIGTERM)|sigmask(SIGIOT)|sigmask(SIGSYS)
		omask = sigblock(ALLSIGS);
		for (cp = buf; cp < buf + cnt; cp++)
			*cp &= 0177;
		if (write(1, buf, cnt) < 0)
			exit(1);
		if (boolean(value(SCRIPT)) && fscript != NULL) {
			if (!boolean(value(BEAUTIFY))) {
				fwrite(buf, 1, cnt, fscript);
				continue;
			}
			for (cp = buf; cp < buf + cnt; cp++)
				if ((*cp >= ' ' && *cp <= '~') ||
				    any(*cp, value(EXCEPTIONS)))
					putc(*cp, fscript);
		}
	}
}
Пример #2
0
/*
 * ****TIPOUT   TIPOUT****
 */
void
tipout(void)
{
	char buf[BUFSIZ];
	char *cp;
	ssize_t scnt;
	size_t cnt;
	sigset_t mask, omask;

	signal(SIGINT, SIG_IGN);
	signal(SIGQUIT, SIG_IGN);
	signal(SIGEMT, intEMT);		/* attention from TIPIN */
	signal(SIGTERM, intTERM);	/* time to go signal */
	signal(SIGIOT, intIOT);		/* scripting going on signal */
	signal(SIGHUP, intTERM);	/* for dial-ups */
	signal(SIGSYS, intSYS);		/* beautify toggle */
	(void) setjmp(sigbuf);
	sigprocmask(SIG_BLOCK, NULL, &omask);
	for (;;) {
		sigprocmask(SIG_SETMASK, &omask, NULL);
		scnt = read(FD, buf, BUFSIZ);
		if (scnt <= 0) {
			/* lost carrier */
			if (scnt == 0 ||
			    (scnt < 0 && (errno == EIO || errno == ENXIO))) {
				sigemptyset(&mask);
				sigaddset(&mask, SIGTERM);
				sigprocmask(SIG_BLOCK, &mask, NULL);
				intTERM(SIGHUP);
				/*NOTREACHED*/
			}
			continue;
		}
		cnt = scnt;
		sigemptyset(&mask);
		sigaddset(&mask, SIGEMT);
		sigaddset(&mask, SIGTERM);
		sigaddset(&mask, SIGIOT);
		sigaddset(&mask, SIGSYS);
		sigprocmask(SIG_BLOCK, &mask, NULL);
		for (cp = buf; cp < buf + cnt; cp++)
			*cp &= STRIP_PAR;
		write(STDOUT_FILENO, buf, cnt);
		if (boolean(value(SCRIPT)) && fscript != NULL) {
			if (!boolean(value(BEAUTIFY))) {
				fwrite(buf, 1, cnt, fscript);
			} else {
				for (cp = buf; cp < buf + cnt; cp++)
					if ((*cp >= ' ' && *cp <= '~') ||
					    any(*cp, value(EXCEPTIONS)))
						putc(*cp, fscript);
			}
			for (cp = buf; cp < buf + cnt; cp++) {
				if (!isgraph(*cp)) {
					fflush(fscript);
					break;
				}
			}
		}
	}
}