|
|
1.1 ! root 1: /* ! 2: * This program echoes the output of kernel printf(). ! 3: * For more information, see kprf(1). ! 4: * ! 5: * 12/16/85 Initial version ! 6: */ ! 7: ! 8: ! 9: #include <sys/types.h> ! 10: #include <sys/socket.h> ! 11: #define KPRF ! 12: #include <sys/prf.h> ! 13: #include <sys/ioctl.h> ! 14: #include <stdio.h> ! 15: ! 16: ! 17: int cflag, ! 18: pflag; ! 19: ! 20: char *pgname; ! 21: ! 22: ! 23: /* ! 24: * Print the usage message and exit. ! 25: */ ! 26: usage() ! 27: { ! 28: printf ("%s: usage: %s [-cp]\n", pgname, pgname); ! 29: printf ("-c\tdirect output to console\n"); ! 30: printf ("-p\tdirect output to process\n"); ! 31: exit (1); ! 32: } ! 33: ! 34: ! 35: /* ! 36: * Main routine. ! 37: */ ! 38: main(argc, argv) ! 39: int argc; ! 40: char *argv[]; ! 41: { ! 42: int i; ! 43: int stat; ! 44: int fd; ! 45: char *cp; ! 46: char buf[1024*4]; /* size of message buffer at end of core */ ! 47: ! 48: pgname = argv[0]; ! 49: ! 50: if (argc == 1) ! 51: usage(); ! 52: while (--argc > 0 && **++argv == '-') { ! 53: for (cp = *argv+1; *cp; cp++) ! 54: switch (*cp) { ! 55: case 'c': ! 56: cflag++; ! 57: fd = pflag ? KPRF_TRACEC : URGCONS; ! 58: break; ! 59: case 'p': ! 60: pflag++; ! 61: fd = cflag ? KPRF_TRACEC : KPRF_TRACE; ! 62: break; ! 63: default: ! 64: usage(); ! 65: } ! 66: } ! 67: ! 68: i = socket(SOCK_STREAM, AF_UNIX, 0); ! 69: if (i < 0) ! 70: fatal("Cannot create socket"); ! 71: ! 72: stat = ioctl(i, SIOCTRACE, (char *) &fd); ! 73: if (stat < 0) ! 74: fatal("Cannot start trace utilities"); ! 75: ! 76: setbuf(stdout, (char *)0); ! 77: for (;;) { ! 78: stat = read(i, buf, sizeof(buf)-1); ! 79: if (stat <= 0) ! 80: fatal("EOF or error in read"); ! 81: buf[stat] = 0; ! 82: printf("%s", buf); ! 83: } ! 84: ! 85: /*NOTREACHED*/ ! 86: exit(0); /* should not get here */ ! 87: } ! 88: ! 89: ! 90: /* ! 91: * A fatal error occured. ! 92: * Print the error message and exit. ! 93: */ ! 94: fatal(msg) ! 95: char *msg; ! 96: { ! 97: fprintf(stderr, "%s: ", pgname); ! 98: perror(msg); ! 99: exit(1); ! 100: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.