Annotation of 43BSDReno/usr.bin/tip/log.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1983 The Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that: (1) source distributions retain this entire copyright
                      7:  * notice and comment, and (2) distributions including binaries display
                      8:  * the following acknowledgement:  ``This product includes software
                      9:  * developed by the University of California, Berkeley and its contributors''
                     10:  * in the documentation or other materials provided with the distribution
                     11:  * and in all advertising materials mentioning features or use of this
                     12:  * software. Neither the name of the University nor the names of its
                     13:  * contributors may be used to endorse or promote products derived
                     14:  * from this software without specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #ifndef lint
                     21: static char sccsid[] = "@(#)log.c      5.4 (Berkeley) 6/1/90";
                     22: #endif /* not lint */
                     23: 
                     24: #include "tip.h"
                     25: 
                     26: #ifdef ACULOG
                     27: static FILE *flog = NULL;
                     28: 
                     29: /*
                     30:  * Log file maintenance routines
                     31:  */
                     32: 
                     33: logent(group, num, acu, message)
                     34:        char *group, *num, *acu, *message;
                     35: {
                     36:        char *user, *timestamp;
                     37:        struct passwd *pwd;
                     38:        long t;
                     39: 
                     40:        if (flog == NULL)
                     41:                return;
                     42:        if (flock(fileno(flog), LOCK_EX) < 0) {
                     43:                perror("tip: flock");
                     44:                return;
                     45:        }
                     46:        if ((user = getlogin()) == NOSTR)
                     47:                if ((pwd = getpwuid(getuid())) == NOPWD)
                     48:                        user = "???";
                     49:                else
                     50:                        user = pwd->pw_name;
                     51:        t = time(0);
                     52:        timestamp = ctime(&t);
                     53:        timestamp[24] = '\0';
                     54:        fprintf(flog, "%s (%s) <%s, %s, %s> %s\n",
                     55:                user, timestamp, group,
                     56: #ifdef PRISTINE
                     57:                "",
                     58: #else
                     59:                num,
                     60: #endif
                     61:                acu, message);
                     62:        (void) fflush(flog);
                     63:        (void) flock(fileno(flog), LOCK_UN);
                     64: }
                     65: 
                     66: loginit()
                     67: {
                     68:        flog = fopen(value(LOG), "a");
                     69:        if (flog == NULL)
                     70:                fprintf(stderr, "can't open log file %s.\r\n", value(LOG));
                     71: }
                     72: #endif

unix.superglobalmegacorp.com

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