Annotation of researchv10no/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:                if (_Lf == NULL)
                     38:                        return;
                     39:                (void) chmod(logfile, 0644);
                     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:                if ((_Sf = open(SYSLOG, 1)) < 0) {
                     70:                        if ((_Sf = creat(SYSLOG, 0644)) < 0)
                     71:                                return;
                     72:                        chmod(SYSLOG, 0644);    /* silly? */
                     73:                }
                     74:        }
                     75:        (void) lseek(_Sf, 0L, 2);
                     76:        (void) write(_Sf, sysbuf, sbuflen);
                     77: }
                     78: 
                     79: 
                     80: /*
                     81:  * Close log files before a fork
                     82:  */
                     83: void
                     84: closelog()
                     85: {
                     86:        if (_Sf >= 0) {
                     87:                (void) close(_Sf);
                     88:                _Sf = -1;
                     89:        }
                     90:        if (_Lf) {
                     91:                (void) fclose(_Lf);
                     92:                _Lf = NULL;
                     93:        }
                     94: }
                     95: 
                     96: /*
                     97:  *     millitick()
                     98:  *
                     99:  *     return msec since last time called
                    100:  */
                    101: #ifdef ATTSV
                    102: time_t
                    103: millitick()
                    104: {
                    105:        struct tms      tbuf;
                    106:        time_t  now, rval;
                    107:        static time_t   past;   /* guaranteed 0 first time called */
                    108: 
                    109:        if (past == 0) {
                    110:                past = times(&tbuf);
                    111:                rval = 0;
                    112:        } else {
                    113:                rval = ((now = times(&tbuf)) - past) * 1000 / HZ;
                    114:                past = now;
                    115:        }
                    116:        return(rval);
                    117: }
                    118: 
                    119: #else
                    120: time_t
                    121: millitick()
                    122: {
                    123:        struct timeb    tbuf;
                    124:        static struct timeb     tbuf1;
                    125:        static past;            /* guaranteed 0 first time called */
                    126:        time_t  rval;
                    127: 
                    128:        if (past == 0) {
                    129:                past++;
                    130:                rval = 0;
                    131:                ftime(&tbuf1);
                    132:        } else {
                    133:                ftime(&tbuf);
                    134:                rval = (tbuf.time - tbuf1.time) * 1000
                    135:                        + tbuf.millitm - tbuf1.millitm;
                    136:                tbuf1 = tbuf;
                    137:        }
                    138:        return(rval);
                    139: }
                    140: #endif

unix.superglobalmegacorp.com

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