Annotation of researchv9/ipc/src/mgrs/common/log.c, revision 1.1

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: 
        !            10: openlog(mtpt)
        !            11:        char *mtpt;
        !            12: {
        !            13:        int fd;
        !            14:        char *cp;
        !            15: 
        !            16:        /* set up log file */
        !            17:        if ((cp=strrchr(mtpt, '/'))!=NULL)
        !            18:                mtpt = cp+1;
        !            19:        sprintf(logname, "/usr/ipc/log/%s", mtpt);
        !            20:        fd = open(logname, 1);
        !            21:        if (fd<0 && errno==ENOENT)
        !            22:                fd = creat(logname, 0666);
        !            23:        if (fd<0) {
        !            24:                fprintf(stderr, "cannot open log file, %s\n", logname);
        !            25:                exit(1);
        !            26:        }
        !            27:        dup2(fd, 2);
        !            28:        close(fd);
        !            29: }
        !            30: 
        !            31: /* logging events */
        !            32: logevent(format, a1, a2, a3, a4, a5, a6)
        !            33:        char *format;
        !            34: {
        !            35:        long now=time((long *)0);
        !            36:        char msg[1024];
        !            37:        int fd;
        !            38: 
        !            39:        sprintf(msg, format, a1, a2, a3, a4, a5, a6);
        !            40:        sprintf(buf, "%.15s %s", ctime(&now)+4, msg);
        !            41:        lseek(2, 0L, 2);
        !            42:        write(2, buf, strlen(buf));
        !            43: }
        !            44: 
        !            45: /* logging events on both log and console */
        !            46: logconsole(format, a1, a2, a3, a4, a5, a6)
        !            47:        char *format;
        !            48: {
        !            49:        long now=time((long *)0);
        !            50:        char msg[1024];
        !            51:        int len;
        !            52: 
        !            53:        sprintf(msg, format, a1, a2, a3, a4, a5, a6);
        !            54:        sprintf(buf, "%.15s %s", ctime(&now)+4, msg);
        !            55:        len = strlen(buf);
        !            56:        lseek(2, 0L, 2);
        !            57:        write(2, buf, len);
        !            58:        write(3, buf, len);
        !            59: }
        !            60: 
        !            61: /* logging calls */
        !            62: logcall(msg, ip)
        !            63:        char *msg;
        !            64:        ipcinfo *ip;
        !            65: {
        !            66:        logevent("%s %s(%s!%s) from %s!%s\n", msg, 
        !            67:                (ip->flags&IPC_CREAT)?"creat":"open", ip->myname, ip->name,
        !            68:                ip->machine, ip->user);
        !            69: }
        !            70: 
        !            71: /* log call status */
        !            72: logstatus(ip)
        !            73:        ipcinfo *ip;
        !            74: {
        !            75:        long now=time((long *)0);
        !            76: 
        !            77:        sprintf(buf, "%.15s (%d)%s %s(%s) from %s!%s\n", ctime(&now)+4, errno,
        !            78:                errstr, (ip->flags&IPC_CREAT)?"creat":"open", ip->name,
        !            79:                ip->machine, ip->user);
        !            80:        lseek(2, 0L, 2);
        !            81:        write(2, buf, strlen(buf));
        !            82: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.