as ifdef the code, ifdef the variable
[unix-history] / usr / src / sys / kern / subr_prf.c
index 48dedea..4fb91df 100644 (file)
@@ -3,7 +3,7 @@
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
- *     @(#)subr_prf.c  6.7 (Berkeley) %G%
+ *     @(#)subr_prf.c  6.11 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -65,31 +65,54 @@ printf(fmt, x1)
 }
 
 /*
 }
 
 /*
- * Uprintf prints to the current user's terminal
- * and does no watermark checking - (so no verbose messages).
+ * Uprintf prints to the current user's terminal.
+ * It may block if the tty queue is overfull.
+ * Should determine whether current terminal user is related
+ * to this process.
  */
 /*VARARGS1*/
 uprintf(fmt, x1)
        char *fmt;
        unsigned x1;
 {
  */
 /*VARARGS1*/
 uprintf(fmt, x1)
        char *fmt;
        unsigned x1;
 {
+#ifdef notdef
+       register struct proc *p;
+#endif
+       register struct tty *tp;
 
 
-       prf(fmt, &x1, TOTTY, u.u_ttyp);
+       if ((tp = u.u_ttyp) == NULL)
+               return;
+#ifdef notdef
+       if (tp->t_pgrp && (p = pfind(tp->t_pgrp)))
+               if (p->p_uid != u.u_uid)        /* doesn't account for setuid */
+                       return;
+#endif
+       (void)ttycheckoutq(tp, 1);
+       prf(fmt, &x1, TOTTY, tp);
 }
 
 /*
  * tprintf prints on the specified terminal (console if none)
  * and logs the message.  It is designed for error messages from
 }
 
 /*
  * tprintf prints on the specified terminal (console if none)
  * and logs the message.  It is designed for error messages from
- * single-open devices, and may be called from interrupt level.
+ * single-open devices, and may be called from interrupt level
+ * (does not sleep).
  */
 /*VARARGS2*/
  */
 /*VARARGS2*/
-tprintf(ttyp, fmt, x1)
-       struct tty *ttyp;
+tprintf(tp, fmt, x1)
+       register struct tty *tp;
        char *fmt;
        unsigned x1;
 {
        char *fmt;
        unsigned x1;
 {
+       int flags = TOTTY | TOLOG;
+       extern struct tty cons;
 
 
-       prf(fmt, &x1, TOTTY | TOLOG, ttyp);
+       logpri(LOG_INFO);
+       if (tp == (struct tty *)NULL)
+               tp = &cons;
+       if (ttycheckoutq(tp, 0) == 0)
+               flags = TOLOG;
+       prf(fmt, &x1, flags, tp);
+       logwakeup();
 }
 
 /*
 }
 
 /*
@@ -105,9 +128,7 @@ log(level, fmt, x1)
        register s = splhigh();
        extern int log_open;
 
        register s = splhigh();
        extern int log_open;
 
-       putchar('<', TOLOG, (struct tty *)0);
-       printn(level, 10, TOLOG, (struct tty *)0);
-       putchar('>', TOLOG, (struct tty *)0);
+       logpri(level);
        prf(fmt, &x1, TOLOG, (struct tty *)0);
        splx(s);
        if (!log_open)
        prf(fmt, &x1, TOLOG, (struct tty *)0);
        splx(s);
        if (!log_open)
@@ -115,6 +136,15 @@ log(level, fmt, x1)
        logwakeup();
 }
 
        logwakeup();
 }
 
+logpri(level)
+       int level;
+{
+
+       putchar('<', TOLOG, (struct tty *)0);
+       printn(level, 10, TOLOG, (struct tty *)0);
+       putchar('>', TOLOG, (struct tty *)0);
+}
+
 prf(fmt, adx, flags, ttyp)
        register char *fmt;
        register u_int *adx;
 prf(fmt, adx, flags, ttyp)
        register char *fmt;
        register u_int *adx;
@@ -242,7 +272,7 @@ tablefull(tab)
        char *tab;
 {
 
        char *tab;
 {
 
-       log(KERN_FAIL, "%s: table is full\n", tab);
+       log(LOG_ERR, "%s: table is full\n", tab);
 }
 
 /*
 }
 
 /*
@@ -255,7 +285,7 @@ harderr(bp, cp)
 {
 
        printf("%s%d%c: hard error sn%d ", cp,
 {
 
        printf("%s%d%c: hard error sn%d ", cp,
-           dkunit(bp), 'a'+(minor(bp->b_dev)&07), bp->b_blkno);
+           minor(bp->b_dev) >> 3, 'a'+(minor(bp->b_dev)&07), bp->b_blkno);
 }
 
 /*
 }
 
 /*
@@ -268,19 +298,18 @@ putchar(c, flags, tp)
        register int c;
        struct tty *tp;
 {
        register int c;
        struct tty *tp;
 {
-       extern struct tty cons;
 
        if (flags & TOTTY) {
 
        if (flags & TOTTY) {
-               if (tp == (struct tty *)NULL && (flags & TOCONS) == 0)
-                       tp = &cons;
-               if (tp && (tp->t_state & TS_CARR_ON)) {
-                       register s = spl6();
+               register s = spltty();
+
+               if (tp && (tp->t_state & (TS_CARR_ON | TS_ISOPEN)) ==
+                   (TS_CARR_ON | TS_ISOPEN)) {
                        if (c == '\n')
                                (void) ttyoutput('\r', tp);
                        (void) ttyoutput(c, tp);
                        ttstart(tp);
                        if (c == '\n')
                                (void) ttyoutput('\r', tp);
                        (void) ttyoutput(c, tp);
                        ttstart(tp);
-                       splx(s);
                }
                }
+               splx(s);
        }
        if ((flags & TOLOG) && c != '\0' && c != '\r' && c != 0177
 #ifdef vax
        }
        if ((flags & TOLOG) && c != '\0' && c != '\r' && c != 0177
 #ifdef vax