1: /*
   2:  *	Suck up system messages
   3:  */
   4: 
   5: #include <stdio.h>
   6: #include <sys/param.h>
   7: #include <a.out.h>
   8: 
   9: char    msgbuf[MSGBUFS];
  10: char    *msgbufp;
  11: int sflg;
  12: int of  = -1;
  13: 
  14: struct {
  15:     char    *omsgflg;
  16:     int omindex;
  17:     char    omsgbuf[MSGBUFS];
  18: } omesg;
  19: struct nlist nl[3] = {
  20:     {"_msgbuf"},
  21:     {"_msgbufp"}
  22: };
  23: 
  24: main(argc, argv)
  25: char **argv;
  26: {
  27:     int mem;
  28:     register char *mp, *omp, *mstart;
  29:     int samef;
  30: 
  31:     if (argc>1 && argv[1][0] == '-') {
  32:         sflg++;
  33:         argc--;
  34:         argv++;
  35:     }
  36:     if (sflg)
  37:         of = open("/usr/adm/msgbuf", 2);
  38:     read(of, (char *)&omesg, sizeof(omesg));
  39:     lseek(of, 0L, 0);
  40:     sflg = 0;
  41:     nlist(argc>2? argv[2]:"/unix", nl);
  42:     if (nl[0].n_type==0)
  43:         done("No namelist\n");
  44:     if ((mem = open((argc>1? argv[1]: "/dev/mem"), 0)) < 0)
  45:         done("No mem\n");
  46:     lseek(mem, (long)nl[0].n_value, 0);
  47:     read(mem, msgbuf, MSGBUFS);
  48:     lseek(mem, (long)nl[1].n_value, 0);
  49:     read(mem, (char *)&msgbufp, sizeof(msgbufp));
  50:     if (msgbufp < (char *)nl[0].n_value || msgbufp >= (char *)nl[0].n_value+MSGBUFS)
  51:         done("Namelist mismatch\n");
  52:     msgbufp += msgbuf - (char *)nl[0].n_value;
  53:     mstart = &msgbuf[omesg.omindex];
  54:     omp = &omesg.omsgbuf[msgbufp-msgbuf];
  55:     mp = msgbufp;
  56:     samef = 1;
  57:     do {
  58:         if (*mp++ != *omp++) {
  59:             mstart = msgbufp;
  60:             samef = 0;
  61:             pdate();
  62:             printf("...\n");
  63:             break;
  64:         }
  65:         if (mp == &msgbuf[MSGBUFS])
  66:             mp = msgbuf;
  67:         if (omp == &omesg.omsgbuf[MSGBUFS])
  68:             omp = omesg.omsgbuf;
  69:     } while (mp != mstart);
  70:     if (samef && mstart == msgbufp)
  71:         exit(0);
  72:     mp = mstart;
  73:     do {
  74:         pdate();
  75:         if (*mp)
  76:             putchar(*mp);
  77:         mp++;
  78:         if (mp == &msgbuf[MSGBUFS])
  79:             mp = msgbuf;
  80:     } while (mp != msgbufp);
  81:     done((char *)NULL);
  82: }
  83: 
  84: done(s)
  85: char *s;
  86: {
  87:     register char *p, *q;
  88: 
  89:     if (s && s!=omesg.omsgflg && sflg==0) {
  90:         pdate();
  91:         printf(s);
  92:     }
  93:     omesg.omsgflg = s;
  94:     q = omesg.omsgbuf;
  95:     for (p = msgbuf; p < &msgbuf[MSGBUFS]; )
  96:         *q++ = *p++;
  97:     omesg.omindex = msgbufp - msgbuf;
  98:     write(of, (char *)&omesg, sizeof(omesg));
  99:     exit(s!=NULL);
 100: }
 101: 
 102: pdate()
 103: {
 104:     extern char *ctime();
 105:     static firstime;
 106:     time_t tbuf;
 107: 
 108:     if (firstime==0) {
 109:         firstime++;
 110:         time(&tbuf);
 111:         printf("\n%.12s\n", ctime(&tbuf)+4);
 112:     }
 113: }

Defined functions

done defined in line 84; used 4 times
main defined in line 24; never used
pdate defined in line 102; used 3 times

Defined variables

msgbuf defined in line 9; used 11 times
msgbufp defined in line 10; used 11 times
nl defined in line 19; used 7 times
of defined in line 12; used 4 times
sflg defined in line 11; used 4 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 893
Valid CSS Valid XHTML 1.0 Strict