|
|
Power 6/32 Unix version 1.21
/*
* This program echoes the output of kernel printf().
* For more information, see kprf(1).
*
* 12/16/85 Initial version
*/
#include <sys/types.h>
#include <sys/socket.h>
#define KPRF
#include <sys/prf.h>
#include <sys/ioctl.h>
#include <stdio.h>
int cflag,
pflag;
char *pgname;
/*
* Print the usage message and exit.
*/
usage()
{
printf ("%s: usage: %s [-cp]\n", pgname, pgname);
printf ("-c\tdirect output to console\n");
printf ("-p\tdirect output to process\n");
exit (1);
}
/*
* Main routine.
*/
main(argc, argv)
int argc;
char *argv[];
{
int i;
int stat;
int fd;
char *cp;
char buf[1024*4]; /* size of message buffer at end of core */
pgname = argv[0];
if (argc == 1)
usage();
while (--argc > 0 && **++argv == '-') {
for (cp = *argv+1; *cp; cp++)
switch (*cp) {
case 'c':
cflag++;
fd = pflag ? KPRF_TRACEC : URGCONS;
break;
case 'p':
pflag++;
fd = cflag ? KPRF_TRACEC : KPRF_TRACE;
break;
default:
usage();
}
}
i = socket(SOCK_STREAM, AF_UNIX, 0);
if (i < 0)
fatal("Cannot create socket");
stat = ioctl(i, SIOCTRACE, (char *) &fd);
if (stat < 0)
fatal("Cannot start trace utilities");
setbuf(stdout, (char *)0);
for (;;) {
stat = read(i, buf, sizeof(buf)-1);
if (stat <= 0)
fatal("EOF or error in read");
buf[stat] = 0;
printf("%s", buf);
}
/*NOTREACHED*/
exit(0); /* should not get here */
}
/*
* A fatal error occured.
* Print the error message and exit.
*/
fatal(msg)
char *msg;
{
fprintf(stderr, "%s: ", pgname);
perror(msg);
exit(1);
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.