Annotation of researchv10no/cmd/upas/common/syslog.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * A first-shot at a syslog implementation on v10.  Quite crude.
        !             3:  */
        !             4: 
        !             5: #include <stdio.h>
        !             6: #include <libc.h>
        !             7: #include <errno.h>
        !             8: #include "mail.h"
        !             9: 
        !            10: static char logname[128];
        !            11: static int fd = -1;
        !            12: static char id[67];
        !            13: static int pid;
        !            14: static char machine[64] = "<hostname>";
        !            15: static logmask = -1;
        !            16: 
        !            17: openlog(name, flags, logord)
        !            18:        char *name;
        !            19:        int flags, logord;
        !            20: {
        !            21:        char *cp;
        !            22:        int hnfd;
        !            23: 
        !            24:        /* set up log file */
        !            25:        if ((cp=strrchr(name, '/'))!=NULL)
        !            26:                name = cp+1;
        !            27:        sprintf(logname, "%s%s.log", SMTPQROOT, name);
        !            28:        fd = open(logname, 1);
        !            29:        if (fd<0 && errno==ENOENT)
        !            30:                fd = creat(logname, 0666);
        !            31:        if (fd<0) {
        !            32:                fprintf(stderr, "cannot open log file, %s\n", logname);
        !            33:                close(2);
        !            34:                logmask = -1;
        !            35:                return;
        !            36:        }
        !            37:        strcpy(id, name);
        !            38:        pid = getpid();
        !            39: #ifdef NOTDEF
        !            40: /* real syslog has machine name here */
        !            41:        hnfd = open("/etc/whoami", 0);
        !            42:        if (hnfd > 0) {
        !            43:                char *cp;
        !            44:                read(hnfd, machine, sizeof(machine));
        !            45:                if ((cp = strchr(machine, '\n')) != NULL)
        !            46:                        *cp = '\0';
        !            47:                close(hnfd);
        !            48:        }
        !            49: #endif
        !            50:        logmask = LOG_UPTO(DEFAULT_LOG_LEVEL);
        !            51: }
        !            52: 
        !            53: syslog(level, format, a1, a2, a3, a4, a5, a6, a7, a8 ,a9, a10)
        !            54:        char *format;
        !            55: {
        !            56:        long now=time((long *)0);
        !            57:        char msg[20000], buf[20000];
        !            58: 
        !            59:        if(((1<<level) & logmask) == 0)
        !            60:                return;
        !            61:        
        !            62:        sprintf(msg, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
        !            63: #ifdef NOTDEF
        !            64:        sprintf(buf, "%.15s %s %s[%d]: %s", ctime(&now)+4,
        !            65:                machine, id, pid, msg);
        !            66: #endif
        !            67:        sprintf(buf, "%.15s %s[%d]: %s", ctime(&now)+4,
        !            68:                id, pid, msg);
        !            69:        if (buf[strlen(buf) - 1] != '\n')
        !            70:                strcat(buf, "\n");
        !            71:        lseek(fd, 0L, 2);
        !            72:        write(fd, buf, strlen(buf));
        !            73: }
        !            74: 
        !            75: setlogmask(mask)
        !            76: int mask;
        !            77: {
        !            78:        int old = logmask;
        !            79: 
        !            80:        if (logmask == -1)
        !            81:                return old;
        !            82:        logmask = mask;
        !            83:        return old;
        !            84: }

unix.superglobalmegacorp.com

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