|
|
1.1 ! root 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: #ifndef lint ! 8: static char sccsid[] = "@(#)dmesg.c 5.7 (Berkeley) 7/6/89"; ! 9: #endif not lint ! 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 <sys/param.h> ! 20: #include <sys/signal.h> ! 21: #include <sys/file.h> ! 22: #include <sys/vm.h> ! 23: #include <sys/msgbuf.h> ! 24: #include <nlist.h> ! 25: #include <stdio.h> ! 26: #include "pathnames.h" ! 27: ! 28: struct msgbuf msgbuf; ! 29: char *msgbufp; ! 30: int sflg; ! 31: int of = -1; ! 32: ! 33: struct msgbuf omesg; ! 34: struct nlist nl[2] = { ! 35: { "_msgbuf" }, ! 36: { "" } ! 37: }; ! 38: ! 39: main(argc, argv) ! 40: char **argv; ! 41: { ! 42: int mem; ! 43: register char *mp, *omp, *mstart; ! 44: int samef, sawnl, ignore = 0; ! 45: ! 46: if (argc>1 && argv[1][0] == '-') { ! 47: sflg++; ! 48: argc--; ! 49: argv++; ! 50: } ! 51: if (sflg) { ! 52: of = open(_PATH_MSGBUF, O_RDWR | O_CREAT, 0644); ! 53: if (of < 0) ! 54: done("Can't open msgbuf file\n"); ! 55: read(of, (char *)&omesg, sizeof(omesg)); ! 56: lseek(of, 0L, 0); ! 57: } ! 58: sflg = 0; ! 59: nlist(argc>2? argv[2]:_PATH_UNIX, nl); ! 60: if (nl[0].n_type==0) ! 61: done("Can't get kernel namelist\n"); ! 62: if ((mem = open((argc>1? argv[1]: _PATH_KMEM), 0)) < 0) ! 63: done("Can't read kernel memory\n"); ! 64: lseek(mem, (long)nl[0].n_value, 0); ! 65: read(mem, &msgbuf, sizeof (msgbuf)); ! 66: if (msgbuf.msg_magic != MSG_MAGIC) ! 67: done("Magic number wrong (namelist mismatch?)\n"); ! 68: if (msgbuf.msg_bufx >= MSG_BSIZE) ! 69: msgbuf.msg_bufx = 0; ! 70: if (omesg.msg_bufx >= MSG_BSIZE) ! 71: omesg.msg_bufx = 0; ! 72: mstart = &msgbuf.msg_bufc[omesg.msg_bufx]; ! 73: omp = &omesg.msg_bufc[msgbuf.msg_bufx]; ! 74: mp = msgbufp = &msgbuf.msg_bufc[msgbuf.msg_bufx]; ! 75: samef = 1; ! 76: do { ! 77: if (*mp++ != *omp++) { ! 78: mstart = msgbufp; ! 79: samef = 0; ! 80: pdate(); ! 81: printf("...\n"); ! 82: break; ! 83: } ! 84: if (mp >= &msgbuf.msg_bufc[MSG_BSIZE]) ! 85: mp = msgbuf.msg_bufc; ! 86: if (omp >= &omesg.msg_bufc[MSG_BSIZE]) ! 87: omp = omesg.msg_bufc; ! 88: } while (mp != mstart); ! 89: if (samef && omesg.msg_bufx == msgbuf.msg_bufx) ! 90: exit(0); ! 91: mp = mstart; ! 92: pdate(); ! 93: sawnl = 1; ! 94: do { ! 95: if (sawnl && *mp == '<') ! 96: ignore = 1; ! 97: if (*mp && (*mp & 0200) == 0 && !ignore) ! 98: putchar(*mp); ! 99: if (ignore && *mp == '>') ! 100: ignore = 0; ! 101: sawnl = (*mp == '\n'); ! 102: mp++; ! 103: if (mp >= &msgbuf.msg_bufc[MSG_BSIZE]) ! 104: mp = msgbuf.msg_bufc; ! 105: } while (mp != msgbufp); ! 106: done((char *)NULL); ! 107: } ! 108: ! 109: done(s) ! 110: char *s; ! 111: { ! 112: if (s) { ! 113: pdate(); ! 114: printf(s); ! 115: } else if (of != -1) ! 116: write(of, (char *)&msgbuf, sizeof(msgbuf)); ! 117: exit(s!=NULL); ! 118: } ! 119: ! 120: pdate() ! 121: { ! 122: extern char *ctime(); ! 123: static firstime; ! 124: time_t tbuf; ! 125: ! 126: if (firstime==0) { ! 127: firstime++; ! 128: time(&tbuf); ! 129: printf("\n%.12s\n", ctime(&tbuf)+4); ! 130: } ! 131: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.