Annotation of researchv8dc/cmd/uucp/logent.c, revision 1.1.1.1

1.1       root        1: /*     /sccs/src/cmd/uucp/s.logent.c
                      2:        logent.c        1.2     8/30/84 17:37:31
                      3: */
                      4: #include "uucp.h"
                      5: VERSION(@(#)logent.c   1.2);
                      6: 
                      7: static FILE    *_Lf = NULL;
                      8: static int     _Sf = -1;
                      9: 
                     10: /*
                     11:  * Make log entry
                     12:  *     text    -> ptr to text string
                     13:  *     status  -> ptr to status string
                     14:  * Returns:
                     15:  *     none
                     16:  */
                     17: void
                     18: logent(text, status)
                     19: register char  *text, *status;
                     20: {
                     21:        static  char    logfile[MAXFULLNAME];
                     22: 
                     23:        if (*Rmtname == NULLCHAR) /* ignore logging if Rmtname is not yet set */
                     24:                return;
                     25:        if (Nstat.t_pid == 0)
                     26:                Nstat.t_pid = getpid();
                     27: 
                     28:        if (_Lf != NULL
                     29:           && strncmp(Rmtname, BASENAME(logfile, '/'), SYSNSIZE) != 0) {
                     30:                fclose(_Lf);
                     31:                _Lf = NULL;
                     32:        }
                     33: 
                     34:        if (_Lf == NULL) {
                     35:                sprintf(logfile, "%s/%s", Logfile, Rmtname);
                     36:                _Lf = fopen(logfile, "a");
                     37:                (void) chmod(logfile, 0644);
                     38:                if (_Lf == NULL)
                     39:                        return;
                     40:                setbuf(_Lf, CNULL);
                     41:        }
                     42:        (void) fseek(_Lf, 0L, 2);
                     43:        (void) fprintf(_Lf, "%s %s %s ", User, Rmtname, Jobid);
                     44:        (void) fprintf(_Lf, "(%s,%d,%d) ", timeStamp(), Nstat.t_pid, Seqn);
                     45:        (void) fprintf(_Lf, "%s (%s)\n", status, text);
                     46:        return;
                     47: }
                     48: 
                     49: 
                     50: /*
                     51:  * Make entry for a conversation (uucico only)
                     52:  *     text    -> pointer to message string
                     53:  * Returns:
                     54:  *     none
                     55:  */
                     56: void
                     57: syslog(text)
                     58: register char  *text;
                     59: {
                     60:        int     sbuflen;
                     61:        char    sysbuf[BUFSIZ];
                     62: 
                     63:        (void) sprintf(sysbuf, "%s!%s %s (%s) (%c,%d,%d) [%s] %s\n",
                     64:                Rmtname, User, Role == SLAVE ? "S" : "M", timeStamp(),
                     65:                Pchar, getpid(), Seqn, Dc, text);
                     66:        sbuflen = strlen(sysbuf);
                     67:        if (_Sf < 0) {
                     68:                errno = 0;
                     69:                _Sf = open(SYSLOG, 1);
                     70:                if (errno == ENOENT) {
                     71:                        _Sf = creat(SYSLOG, 0644);
                     72:                        (void) chmod(SYSLOG, 0644);
                     73:                }
                     74:                if (_Sf < 0)
                     75:                        return;
                     76:        }
                     77:        (void) lseek(_Sf, 0L, 2);
                     78:        (void) write(_Sf, sysbuf, sbuflen);
                     79:        return;
                     80: }
                     81: 
                     82: 
                     83: /*
                     84:  * Close log files before a fork
                     85:  */
                     86: void
                     87: closelog()
                     88: {
                     89:        if (_Sf >= 0) {
                     90:                (void) close(_Sf);
                     91:                _Sf = -1;
                     92:        }
                     93:        if (_Lf) {
                     94:                (void) fclose(_Lf);
                     95:                _Lf = NULL;
                     96:        }
                     97: }
                     98: 
                     99: /*
                    100:  *     millitick()
                    101:  *
                    102:  *     return msec since last time called
                    103:  */
                    104: #ifdef ATTSV
                    105: time_t
                    106: millitick()
                    107: {
                    108:        struct tms      tbuf;
                    109:        time_t  now, rval;
                    110:        static time_t   past;   /* guaranteed 0 first time called */
                    111: 
                    112:        if (past == 0) {
                    113:                past = times(&tbuf);
                    114:                rval = 0;
                    115:        } else {
                    116:                rval = ((now = times(&tbuf)) - past) * 1000 / HZ;
                    117:                past = now;
                    118:        }
                    119:        return(rval);
                    120: }
                    121: 
                    122: #else !ATTSV
                    123: time_t
                    124: millitick()
                    125: {
                    126:        struct timeb    tbuf;
                    127:        static struct timeb     tbuf1;
                    128:        static past;            /* guaranteed 0 first time called */
                    129:        time_t  rval;
                    130: 
                    131:        if (past == 0) {
                    132:                past++;
                    133:                rval = 0;
                    134:                ftime(&tbuf1);
                    135:        } else {
                    136:                ftime(&tbuf);
                    137:                rval = (tbuf.time - tbuf1.time) * 1000
                    138:                        + tbuf.millitm - tbuf1.millitm;
                    139:                tbuf1 = tbuf;
                    140:        }
                    141:        return(rval);
                    142: }
                    143: #endif ATTSV

unix.superglobalmegacorp.com

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