1: /*
   2:  * Copyright (c) 1980 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #if defined(DOSCCS) && !defined(lint)
   8: static char sccsid[] = "@(#)dmesg.c	5.4.1 (2.11BSD GTE) 1/1/94";
   9: #endif
  10: 
  11: /*
  12:  *	Suck up system messages
  13:  *	dmesg
  14:  *		print current buffer
  15:  *	dmesg -
  16:  *		print and update incremental history
  17:  */
  18: 
  19: #include <stdio.h>
  20: #include <sys/param.h>
  21: #include <nlist.h>
  22: #include <signal.h>
  23: #include <sys/file.h>
  24: #include <sys/vm.h>
  25: #include <sys/msgbuf.h>
  26: 
  27: struct  msgbuf msgbuf;
  28: char    *msgbufp;
  29: int sflg;
  30: int of  = -1;
  31: 
  32: struct  msgbuf omesg;
  33: struct  nlist nl[2] = {
  34:     { "_msgbuf" },
  35:     { "" }
  36: };
  37: 
  38: main(argc, argv)
  39: char **argv;
  40: {
  41:     int mem;
  42:     register char *mp, *omp, *mstart;
  43:     int samef, sawnl, ignore;
  44: #ifdef  pdp11
  45:     char msgb[MSG_BSIZE];
  46: #endif
  47: 
  48:     if (argc>1 && argv[1][0] == '-') {
  49:         sflg++;
  50:         argc--;
  51:         argv++;
  52:     }
  53:     if (sflg) {
  54:         of = open("/usr/adm/msgbuf", O_RDWR | O_CREAT, 0644);
  55:         if (of < 0)
  56:             done("Can't open /usr/adm/msgbuf\n");
  57:         read(of, (char *)&omesg, sizeof(omesg));
  58:         lseek(of, 0L, 0);
  59:     }
  60:     sflg = 0;
  61: #ifdef pdp11
  62:     nlist(argc>2? argv[2]:"/unix", nl);
  63: #else
  64:     nlist(argc>2? argv[2]:"/vmunix", nl);
  65: #endif
  66:     if (nl[0].n_type==0)
  67:         done("Can't get kernel namelist\n");
  68:     if ((mem = open((argc>1? argv[1]: "/dev/mem"), 0)) < 0)
  69:         done("Can't read kernel memory\n");
  70:     lseek(mem, (long)nl[0].n_value, 0);
  71:     read(mem, &msgbuf, sizeof (msgbuf));
  72:     if (msgbuf.msg_magic != MSG_MAGIC)
  73:         done("Magic number wrong (namelist mismatch?)\n");
  74:     if (msgbuf.msg_bufx >= MSG_BSIZE)
  75:         msgbuf.msg_bufx = 0;
  76:     if (omesg.msg_bufx >= MSG_BSIZE)
  77:         omesg.msg_bufx = 0;
  78: #ifdef  pdp11
  79:     msgbuf.msg_bufc = msgb;
  80:     lseek(mem, (long)ctob((long)msgbuf.msg_click), 0);
  81:     read(mem, msgbuf.msg_bufc, MSG_BSIZE);
  82: #endif
  83:     mstart = &msgbuf.msg_bufc[omesg.msg_bufx];
  84:     omp = &omesg.msg_bufc[msgbuf.msg_bufx];
  85:     mp = msgbufp = &msgbuf.msg_bufc[msgbuf.msg_bufx];
  86:     samef = 1;
  87:     do {
  88:         if (*mp++ != *omp++) {
  89:             mstart = msgbufp;
  90:             samef = 0;
  91:             pdate();
  92:             printf("...\n");
  93:             break;
  94:         }
  95:         if (mp >= &msgbuf.msg_bufc[MSG_BSIZE])
  96:             mp = msgbuf.msg_bufc;
  97:         if (omp >= &omesg.msg_bufc[MSG_BSIZE])
  98:             omp = omesg.msg_bufc;
  99:     } while (mp != mstart);
 100:     if (samef && omesg.msg_bufx == msgbuf.msg_bufx)
 101:         exit(0);
 102:     mp = mstart;
 103:     pdate();
 104:     sawnl = 1;
 105:     do {
 106:         if (sawnl && *mp == '<')
 107:             ignore = 1;
 108:         if (*mp && (*mp & 0200) == 0 && !ignore)
 109:             putchar(*mp);
 110:         if (ignore && *mp == '>')
 111:             ignore = 0;
 112:         sawnl = (*mp == '\n');
 113:         mp++;
 114:         if (mp >= &msgbuf.msg_bufc[MSG_BSIZE])
 115:             mp = msgbuf.msg_bufc;
 116:     } while (mp != msgbufp);
 117:     done((char *)NULL);
 118: }
 119: 
 120: done(s)
 121: char *s;
 122: {
 123:     register char *p, *q;
 124: 
 125:     if (s) {
 126:         pdate();
 127:         printf(s);
 128:     } else if (of != -1)
 129:         write(of, (char *)&msgbuf, sizeof(msgbuf));
 130:     exit(s!=NULL);
 131: }
 132: 
 133: pdate()
 134: {
 135:     extern char *ctime();
 136:     static firstime;
 137:     time_t tbuf;
 138: 
 139:     if (firstime==0) {
 140:         firstime++;
 141:         time(&tbuf);
 142:         printf("\n%.12s\n", ctime(&tbuf)+4);
 143:     }
 144: }

Defined functions

done defined in line 120; used 5 times
main defined in line 38; never used
pdate defined in line 133; used 3 times

Defined variables

msgbuf defined in line 27; used 19 times
msgbufp defined in line 28; used 3 times
nl defined in line 33; used 4 times
of defined in line 30; used 6 times
omesg defined in line 32; used 9 times
sccsid defined in line 8; never used
sflg defined in line 29; used 3 times
Last modified: 1994-01-11
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 911
Valid CSS Valid XHTML 1.0 Strict