Annotation of 41BSD/cmd/uucp/logent.c, revision 1.1

1.1     ! root        1:        /*  @(#)logent  2.1  5/18/79  13:27:52  */
        !             2: #include "uucp.h"
        !             3: #include <sys/types.h>
        !             4: #include <time.h>
        !             5: 
        !             6: char Slogent[] = "@(#)logent   2.1";
        !             7: 
        !             8: 
        !             9: char Tmplog[MAXFULLNAME] = "";
        !            10: FILE *Lp = NULL;
        !            11: 
        !            12: /*******
        !            13:  *     logent(text, status)    make log entry
        !            14:  *     char *text, *status;
        !            15:  *
        !            16:  *     return code - none
        !            17:  */
        !            18: 
        !            19: logent(text, status)
        !            20: char *text, *status;
        !            21: {
        !            22:        int n;
        !            23:        FILE *fp;
        !            24:        if (Lp != NULL) {
        !            25:                /*  make entry in existing temp log file  */
        !            26:                mlogent(Lp, status, text);
        !            27:                return;
        !            28:        }
        !            29: 
        !            30:        if (ulockf(LOGLOCK, 10l) == 0) {
        !            31:                if ((fp = fopen(LOGFILE, "a")) == NULL) {
        !            32:                        rmlock(LOGLOCK);
        !            33:                }
        !            34:                else {
        !            35:                        mlogent(fp, status, text);
        !            36:                        fclose(fp);
        !            37:                        rmlock(LOGLOCK);
        !            38:                        return;
        !            39:                }
        !            40:        }
        !            41: 
        !            42:        /*  make a temp log file  */
        !            43:        for (n = 0; n < 10; n++) {
        !            44:                sprintf(Tmplog, "%s/LOG.%05d.%1d", LOGDIR, getpid(), n);
        !            45:                if (access(Tmplog, 0) == -1)
        !            46:                        break;
        !            47:        }
        !            48:        if ((Lp = fopen(Tmplog, "w")) == NULL)
        !            49:                return;
        !            50:        chmod(Tmplog, 0222);
        !            51:        setbuf(Lp, NULL);
        !            52:        mlogent(Lp, status, text);
        !            53:        return;
        !            54: }
        !            55: 
        !            56: /***
        !            57:  *     mlogent(fp, status, text)  - make a log entry
        !            58:  */
        !            59: 
        !            60: mlogent(fp, status, text)
        !            61: char *text, *status;
        !            62: FILE *fp;
        !            63: {
        !            64:        static pid = 0;
        !            65:        struct tm *tp;
        !            66:        extern struct tm *localtime();
        !            67:        time_t clock;
        !            68: 
        !            69:        if (!pid)
        !            70:                pid = getpid();
        !            71:        time(&clock);
        !            72:        tp = localtime(&clock);
        !            73:        fprintf(fp, "%s %s ", User, Rmtname);
        !            74:        fprintf(fp, "(%d/%d-%d:%d-%d) ", tp->tm_mon + 1,
        !            75:                tp->tm_mday, tp->tm_hour, tp->tm_min, pid);
        !            76:        fprintf(fp, "%s (%s)\n", status, text);
        !            77:        return;
        !            78: }
        !            79: 
        !            80: /***
        !            81:  *     logcls()        close log file
        !            82:  *
        !            83:  *     return codes:  none
        !            84:  */
        !            85: 
        !            86: logcls()
        !            87: {
        !            88:        if (Lp != NULL) {
        !            89:                fclose(Lp);
        !            90:                chmod(Tmplog, 0666);
        !            91:        }
        !            92:        return;
        !            93: }
        !            94: 
        !            95: 
        !            96: /***
        !            97:  *     syslog(text)    make system log entry
        !            98:  *     char *text;
        !            99:  *
        !           100:  *     return codes - none
        !           101:  */
        !           102: 
        !           103: syslog(text)
        !           104: char *text;
        !           105: {
        !           106:        struct tm *tp;
        !           107:        extern struct tm *localtime();
        !           108:        time_t clock;
        !           109:        FILE *fp;
        !           110: 
        !           111:        time(&clock);
        !           112:        tp = localtime(&clock);
        !           113:        fp = fopen(SYSLOG, "a");
        !           114:        if (fp == NULL)
        !           115:                return;
        !           116:        fprintf(fp, "%s %s ", User, Rmtname);
        !           117:        fprintf(fp, "(%d/%d-%d:%d) ", tp->tm_mon + 1,
        !           118:                tp->tm_mday, tp->tm_hour, tp->tm_min);
        !           119:        fprintf(fp, "%s\n", text);
        !           120:        fclose(fp);
        !           121:        return;
        !           122: }

unix.superglobalmegacorp.com

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