POSIX signals
[unix-history] / usr / src / usr.bin / tip / tipout.c
index de7aa7c..e445b97 100644 (file)
@@ -1,6 +1,23 @@
+/*
+ * Copyright (c) 1983 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
 #ifndef lint
 #ifndef lint
-static char sccsid[] = "@(#)tipout.c   4.8 (Berkeley) %G%";
-#endif
+static char sccsid[] = "@(#)tipout.c   5.2 (Berkeley) %G%";
+#endif /* not lint */
 
 #include "tip.h"
 /*
 
 #include "tip.h"
 /*
@@ -80,6 +97,7 @@ tipout()
        char buf[BUFSIZ];
        register char *cp;
        register int cnt;
        char buf[BUFSIZ];
        register char *cp;
        register int cnt;
+       extern int errno;
        int omask;
 
        signal(SIGINT, SIG_IGN);
        int omask;
 
        signal(SIGINT, SIG_IGN);
@@ -92,10 +110,16 @@ tipout()
        (void) setjmp(sigbuf);
        for (omask = 0;; sigsetmask(omask)) {
                cnt = read(FD, buf, BUFSIZ);
        (void) setjmp(sigbuf);
        for (omask = 0;; sigsetmask(omask)) {
                cnt = read(FD, buf, BUFSIZ);
-               if (cnt <= 0)
+               if (cnt <= 0) {
+                       /* lost carrier */
+                       if (cnt < 0 && errno == EIO) {
+                               sigblock(sigmask(SIGTERM));
+                               intTERM();
+                               /*NOTREACHED*/
+                       }
                        continue;
                        continue;
-#define        mask(s) (1 << ((s) - 1))
-#define        ALLSIGS mask(SIGEMT)|mask(SIGTERM)|mask(SIGIOT)|mask(SIGSYS)
+               }
+#define        ALLSIGS sigmask(SIGEMT)|sigmask(SIGTERM)|sigmask(SIGIOT)|sigmask(SIGSYS)
                omask = sigblock(ALLSIGS);
                for (cp = buf; cp < buf + cnt; cp++)
                        *cp &= 0177;
                omask = sigblock(ALLSIGS);
                for (cp = buf; cp < buf + cnt; cp++)
                        *cp &= 0177;