# 2.11BSD#431 - /usr/src/usr.bin/uucp/logent.c

##### Functions

    fioclex           X
    logcls            X
    logent            X
    mlogent           X
    syslog            X

       1: #ifndef lint
       2: static char sccsid[] = "@(#)logent.c	5.6 (Berkeley) 10/9/85";
       3: #endif
       4:
       5: #include "uucp.h"
       6: #ifdef BSD4_2
       7: #include <sys/time.h>
       8: #else
       9: #include <time.h>
      10: #endif
      11: #if defined(USG) || defined(BSD4_2)
      12: #include <fcntl.h>
      13: #endif
      14:
      15: static FILE *Lp = NULL;
      16: static FILE *Sp = NULL;
      17: static Ltried = 0;
      18: static Stried = 0;
      19:
      20: /*LINTLIBRARY*/
      21:
      22: /*
      23:  *	make log entry
      24:  */
      25: logent(text, status)
      26: char *text, *status;
      27: {
      28: #ifdef LOGBYSITE
      29:     char lfile[MAXFULLNAME];
      30:     static char LogRmtname[64];
      31: #endif LOGBYSITE
      32:     if (Rmtname[0] == '\0')
      33:         strcpy(Rmtname, Myname);
      34:     /* Open the log file if necessary */
      35: #ifdef LOGBYSITE
      36:     if (strcmp(Rmtname, LogRmtname)) {
      37:         if (Lp != NULL)
      38:             fclose(Lp);
      39:         Lp = NULL;
      40:         Ltried = 0;
      41:     }
      42: #endif LOGBYSITE
      43:     if (Lp == NULL) {
      44:         if (!Ltried) {
      45:             int savemask;
      46: #ifdef F_SETFL
      47:             int flags;
      48: #endif
      49:             savemask = umask(LOGMASK);
      50: #ifdef LOGBYSITE
      51:             (void) sprintf(lfile, "%s/%s/%s", LOGBYSITE, Progname, Rmtname);
      52:             strcpy(LogRmtname, Rmtname);
      53:             Lp = fopen (lfile, "a");
      54: #else !LOGBYSITE
      55:             Lp = fopen (LOGFILE, "a");
      56: #endif LOGBYSITE
      57:             umask(savemask);
      58: #ifdef F_SETFL
      59:             flags = fcntl(fileno(Lp), F_GETFL, 0);
      60:             fcntl(fileno(Lp), F_SETFL, flags|O_APPEND);
      61: #endif
      62:         }
      63:         Ltried = 1;
      64:         if (Lp == NULL)
      65:             return;
      66:         fioclex(fileno(Lp));
      67:     }
      68:
      69:     /*  make entry in existing temp log file  */
      70:     mlogent(Lp, status, text);
      71: }
      72:
      73: /*
      74:  *	make a log entry
      75:  */
      76:
      77: mlogent(fp, status, text)
      78: char *text, *status;
      79: register FILE *fp;
      80: {
      81:     static pid = 0;
      82:     register struct tm *tp;
      83:     extern struct tm *localtime();
      84:
      85:     if (text == NULL)
      86:         text = "";
      87:     if (status == NULL)
      88:         status = "";
      89:     if (!pid)
      90:         pid = getpid();
      91: #ifdef USG
      92:     time(&Now.time);
      93:     Now.millitm = 0;
      94: #else !USG
      95:     ftime(&Now);
      96: #endif !USG
      97:     tp = localtime(&Now.time);
      98: #ifdef USG
      99:     fprintf(fp, "%s %s (%d/%d-%2.2d:%2.2d-%d) ",
     100: #else !USG
     101:     fprintf(fp, "%s %s (%d/%d-%02d:%02d-%d) ",
     102: #endif !USG
     103:         User, Rmtname, tp->tm_mon + 1, tp->tm_mday,
     104:         tp->tm_hour, tp->tm_min, pid);
     105:     fprintf(fp, "%s (%s)\n", status, text);
     106:
     107:     /* Since it's buffered */
     108: #ifndef F_SETFL
     109:     lseek (fileno(fp), (long)0, 2);
     110: #endif !F_SETFL
     111:     fflush (fp);
     112:     if (Debug) {
     113:         fprintf(stderr, "%s %s ", User, Rmtname);
     114: #ifdef USG
     115:         fprintf(stderr, "(%d/%d-%2.2d:%2.2d-%d) ", tp->tm_mon + 1,
     116:             tp->tm_mday, tp->tm_hour, tp->tm_min, pid);
     117: #else !USG
     118:         fprintf(stderr, "(%d/%d-%02d:%02d-%d) ", tp->tm_mon + 1,
     119:             tp->tm_mday, tp->tm_hour, tp->tm_min, pid);
     120: #endif !USG
     121:         fprintf(stderr, "%s (%s)\n", status, text);
     122:     }
     123: }
     124:
     125: /*
     126:  *	close log file
     127:  */
     128: logcls()
     129: {
     130:     if (Lp != NULL)
     131:         fclose(Lp);
     132:     Lp = NULL;
     133:     Ltried = 0;
     134:
     135:     if (Sp != NULL)
     136:         fclose (Sp);
     137:     Sp = NULL;
     138:     Stried = 0;
     139: }
     140:
     141:
     142: /*
     143:  *	make system log entry
     144:  */
     145: syslog(text)
     146: char *text;
     147: {
     148:     register struct tm *tp;
     149:     extern struct tm *localtime();
     150: #ifdef LOGBYSITE
     151:     char lfile[MAXFULLNAME];
     152:     static char SLogRmtname[64];
     153:
     154:     if (strcmp(Rmtname, SLogRmtname)) {
     155:         if (Sp != NULL)
     156:             fclose(Sp);
     157:         Sp = NULL;
     158:         Stried = 0;
     159:     }
     160: #endif LOGBYSITE
     161:     if (Sp == NULL) {
     162:         if (!Stried) {
     163:             int savemask;
     164: #ifdef F_SETFL
     165:             int flags;
     166: #endif F_SETFL
     167:             savemask = umask(LOGMASK);
     168: #ifdef LOGBYSITE
     169:             (void) sprintf(lfile, "%s/xferstats/%s", LOGBYSITE, Rmtname);
     170:             strcpy(SLogRmtname, Rmtname);
     171:             Sp = fopen (lfile, "a");
     172: #else !LOGBYSITE
     173:             Sp = fopen (SYSLOG, "a");
     174: #endif LOGBYSITE
     175:             umask(savemask);
     176: #ifdef F_SETFL
     177:             flags = fcntl(fileno(Sp), F_GETFL, 0);
     178:             fcntl(fileno(Sp), F_SETFL, flags|O_APPEND);
     179: #endif F_SETFL
     180:
     181:         }
     182:         Stried = 1;
     183:         if (Sp == NULL)
     184:             return;
     185:         fioclex(fileno(Sp));
     186:     }
     187:
     188: #ifdef USG
     189:     time(&Now.time);
     190:     Now.millitm = 0;
     191: #else !USG
     192:     ftime(&Now);
     193: #endif !USG
     194:     tp = localtime(&Now.time);
     195:
     196:     fprintf(Sp, "%s %s ", User, Rmtname);
     197: #ifdef USG
     198:     fprintf(Sp, "(%d/%d-%2.2d:%2.2d) ", tp->tm_mon + 1,
     199:         tp->tm_mday, tp->tm_hour, tp->tm_min);
     200:     fprintf(Sp, "(%ld) %s\n", Now.time, text);
     201: #else !USG
     202:     fprintf(Sp, "(%d/%d-%02d:%02d) ", tp->tm_mon + 1,
     203:         tp->tm_mday, tp->tm_hour, tp->tm_min);
     204:     fprintf(Sp, "(%ld.%02u) %s\n", Now.time, Now.millitm/10, text);
     205: #endif !USG
     206:
     207:     /* Position at end and flush */
     208: #ifndef F_SETFL
     209:     lseek (fileno(Sp), (long)0, 2);
     210: #endif F_SETFL
     211:     fflush (Sp);
     212: }
     213:
     214: /*
     215:  * Arrange to close fd on exec(II).
     216:  * Otherwise unwanted file descriptors are inherited
     217:  * by other programs.  And that may be a security hole.
     218:  */
     219: #ifndef USG
     220: #include <sgtty.h>
     221: #endif
     222:
     223: fioclex(fd)
     224: int fd;
     225: {
     226:     register int ret;
     227:
     228: #if defined(USG) || defined(BSD4_2)
     229:     ret = fcntl(fd, F_SETFD, 1);    /* Steve Bellovin says this does it */
     230: #else
     231:     ret = ioctl(fd, FIOCLEX, STBNULL);
     232: #endif
     233:     if (ret)
     234:         DEBUG(2, "CAN'T FIOCLEX %d\n", fd);
     235: }

#### Defined functions

fioclex defined in line 223; used 6 times

- in line 66, 185
- in /usr/src/usr.bin/uucp/aculib/df2.c line 50
- in /usr/src/usr.bin/uucp/aculib/dn.c line 51
- in /usr/src/usr.bin/uucp/aculib/rvmacs.c line 87
- in /usr/src/usr.bin/uucp/conn.c line 204

logcls defined in line 128; used 4 times

- in /usr/src/usr.bin/uucp/cico.c line 675
- in /usr/src/usr.bin/uucp/uucp.c line 188
- in /usr/src/usr.bin/uucp/uux.c line 456
- in /usr/src/usr.bin/uucp/uuxqt.c line 385

logent defined in line 25; used 204 times

- in /usr/src/usr.bin/uucp/aculib/att2224.c line 19, 31, 44, 59, 65, 76, 82-94(4)
- in /usr/src/usr.bin/uucp/aculib/bsdtcp.c line 32, 41, 48, 80
- in /usr/src/usr.bin/uucp/aculib/cds224.c line 30, 52
- in /usr/src/usr.bin/uucp/aculib/df12.c line 49, 71, 83, 91, 106, 115
- in /usr/src/usr.bin/uucp/aculib/df2.c line 33, 45-47(2), 59, 81, 100
- in /usr/src/usr.bin/uucp/aculib/dn.c line 36, 47-48(2), 59, 79, 97-100(2)
- in /usr/src/usr.bin/uucp/aculib/hys.c line 59, 75, 81, 88, 105, 127, 140, 184
- in /usr/src/usr.bin/uucp/aculib/hys24.c line 47, 69, 75, 87, 95
- in /usr/src/usr.bin/uucp/aculib/hysq.c line 69, 76
- in /usr/src/usr.bin/uucp/aculib/mic.c line 45
- in /usr/src/usr.bin/uucp/aculib/nov.c line 34, 53, 67
- in /usr/src/usr.bin/uucp/aculib/pen.c line 22
- in /usr/src/usr.bin/uucp/aculib/pnet.c line 25
- in /usr/src/usr.bin/uucp/aculib/rvmacs.c line 70, 80, 128, 145-147(2)
- in /usr/src/usr.bin/uucp/aculib/sy.c line 48
- in /usr/src/usr.bin/uucp/aculib/unet.c line 31, 42, 60
- in /usr/src/usr.bin/uucp/aculib/va212.c line 21
- in /usr/src/usr.bin/uucp/aculib/va811.c line 37, 56, 68, 82, 96
- in /usr/src/usr.bin/uucp/aculib/va820.c line 33, 39, 54, 71, 79, 93, 109, 140-142(2)
- in /usr/src/usr.bin/uucp/aculib/vad.c line 28, 50
- in /usr/src/usr.bin/uucp/aculib/vent.c line 19
- in /usr/src/usr.bin/uucp/aculib/vmacs.c line 56-61(2), 70, 80, 91, 108, 140-142(2)
- in /usr/src/usr.bin/uucp/anlwrk.c line 63
- in /usr/src/usr.bin/uucp/cico.c line 203, 212-214(2), 298, 321, 330-332(2), 339, 356-360(4), 376, 395, 421, 436, 464, 475-477(2), 494, 501, 510, 533, 560, 569, 578, 605, 617-619(2), 628-633(2), 730, 749, 878
- in /usr/src/usr.bin/uucp/cntrl.c line 162-164(2), 190, 201, 208, 225, 240, 256, 265, 295, 309, 366, 383, 434-439(2), 465, 485, 523, 540, 588, 600, 609, 624, 631, 674, 682, 688
- in /usr/src/usr.bin/uucp/condevs.c line 188, 230, 304, 350-355(3), 459, 556
- in /usr/src/usr.bin/uucp/conn.c line 47, 148, 242, 276, 285, 432, 441, 626, 809
- in /usr/src/usr.bin/uucp/expfile.c line 125
- in /usr/src/usr.bin/uucp/gename.c line 41
- in /usr/src/usr.bin/uucp/gnxseq.c line 41
- in /usr/src/usr.bin/uucp/pk0.c line 37, 70, 102, 541
- in /usr/src/usr.bin/uucp/pk1.c line 295, 312, 422
- in /usr/src/usr.bin/uucp/systat.c line 126-129(2), 136-139(2)
- in /usr/src/usr.bin/uucp/ulockf.c line 64
- in /usr/src/usr.bin/uucp/uucp.c line 263, 441
- in /usr/src/usr.bin/uucp/uucpname.c line 150
- in /usr/src/usr.bin/uucp/uux.c line 404-407(2), 479
- in /usr/src/usr.bin/uucp/uuxqt.c line 119, 142, 189-191(2), 295, 301, 328, 447, 562, 630, 653, 701, 707

mlogent defined in line 77; used 1 times

- in line 70

syslog defined in line 145; used 6 times

- in /usr/src/usr.bin/uucp/fio.c line 225, 295
- in /usr/src/usr.bin/uucp/gio.c line 135, 189
- in /usr/src/usr.bin/uucp/tio.c line 153, 219

#### Defined variables

sccsid defined in line 2; never used

Last modified: 1987-02-17 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1056 |