|
|
1.1 ! root 1: #include <sys/types.h> ! 2: #include <stdio.h> ! 3: #include <ipc.h> ! 4: #include <libc.h> ! 5: #include "defs.h" ! 6: ! 7: static char buf[1024]; ! 8: static char logname[128]; ! 9: static int nolog; ! 10: ! 11: openlog(mtpt) ! 12: char *mtpt; ! 13: { ! 14: int fd; ! 15: char *cp; ! 16: ! 17: /* set up log file */ ! 18: if ((cp=strrchr(mtpt, '/'))!=NULL) ! 19: mtpt = cp+1; ! 20: sprintf(logname, "/usr/ipc/log/%s", mtpt); ! 21: fd = open(logname, 1); ! 22: if (fd<0 && errno==ENOENT) ! 23: fd = creat(logname, 0666); ! 24: if (fd<0) { ! 25: fprintf(stderr, "cannot open log file, %s\n", logname); ! 26: nolog=1; ! 27: close(2); ! 28: return; ! 29: } ! 30: dup2(fd, 2); ! 31: close(fd); ! 32: fd = open("/dev/console", 1); ! 33: dup2(fd, 3); ! 34: close(fd); ! 35: } ! 36: ! 37: /* logging events */ ! 38: logevent(format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) ! 39: char *format; ! 40: { ! 41: long now=time((long *)0); ! 42: char msg[1024]; ! 43: ! 44: if(nolog) ! 45: return; ! 46: ! 47: sprintf(msg, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); ! 48: sprintf(buf, "%.15s %s", ctime(&now)+4, msg); ! 49: lseek(2, 0L, 2); ! 50: write(2, buf, strlen(buf)); ! 51: } ! 52: ! 53: /* logging events on both log and console */ ! 54: logconsole(format, a1, a2, a3, a4, a5, a6) ! 55: char *format; ! 56: { ! 57: long now=time((long *)0); ! 58: char msg[1024]; ! 59: int len; ! 60: ! 61: if(nolog) ! 62: return; ! 63: sprintf(msg, format, a1, a2, a3, a4, a5, a6); ! 64: sprintf(buf, "%.15s %s", ctime(&now)+4, msg); ! 65: len = strlen(buf); ! 66: lseek(2, 0L, 2); ! 67: write(2, buf, len); ! 68: write(3, buf, len); ! 69: } ! 70: ! 71: /* log call status */ ! 72: logstatus(msg, ip) ! 73: char *msg; ! 74: ipcinfo *ip; ! 75: { ! 76: long now=time((long *)0); ! 77: ! 78: if(nolog) ! 79: return; ! 80: if(errno){ ! 81: sprintf(buf, "%.15s %s reject %s(%s!%s) from %s %s (%d) %s\n", ! 82: ctime(&now)+4, msg, (ip->flags&IPC_CREAT)?"creat":"open", ! 83: ip->myname, ip->name, ip->machine, ip->user, errno, ! 84: errstr); ! 85: } else { ! 86: sprintf(buf, "%.15s %s accept %s(%s!%s) from %s %s\n", ! 87: ctime(&now)+4, msg, (ip->flags&IPC_CREAT)?"creat":"open", ! 88: ip->myname, ip->name, ip->machine, ip->user); ! 89: } ! 90: lseek(2, 0L, 2); ! 91: write(2, buf, strlen(buf)); ! 92: } ! 93: ! 94: logtime(msg) ! 95: char *msg; ! 96: { ! 97: #include <sys/timeb.h> ! 98: struct timeb tb; ! 99: ! 100: if(nolog) ! 101: return; ! 102: ftime(&tb); ! 103: sprintf(buf, "%d %s", tb.time*1000L + tb.millitm, msg); ! 104: lseek(2, 0L, 2); ! 105: write(2, buf, strlen(buf)); ! 106: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.