4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / usr.bin / tip / log.c
CommitLineData
051b1e55 1/*
abfba3de
KB
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
c9686c12 4 *
cb956e54 5 * %sccs.include.redist.c%
051b1e55
DF
6 */
7
05862919 8#ifndef lint
abfba3de 9static char sccsid[] = "@(#)log.c 8.1 (Berkeley) %G%";
c9686c12 10#endif /* not lint */
c65b7b88 11
05862919
SL
12#include "tip.h"
13
65a564bd 14#ifdef ACULOG
05862919 15static FILE *flog = NULL;
c65b7b88
BJ
16
17/*
18 * Log file maintenance routines
19 */
20
21logent(group, num, acu, message)
d8feebc2 22 char *group, *num, *acu, *message;
c65b7b88
BJ
23{
24 char *user, *timestamp;
25 struct passwd *pwd;
26 long t;
27
28 if (flog == NULL)
29 return;
05862919
SL
30 if (flock(fileno(flog), LOCK_EX) < 0) {
31 perror("tip: flock");
c65b7b88
BJ
32 return;
33 }
34 if ((user = getlogin()) == NOSTR)
35 if ((pwd = getpwuid(getuid())) == NOPWD)
36 user = "???";
37 else
38 user = pwd->pw_name;
39 t = time(0);
40 timestamp = ctime(&t);
41 timestamp[24] = '\0';
42 fprintf(flog, "%s (%s) <%s, %s, %s> %s\n",
43 user, timestamp, group,
44#ifdef PRISTINE
45 "",
46#else
47 num,
48#endif
49 acu, message);
65a564bd 50 (void) fflush(flog);
05862919 51 (void) flock(fileno(flog), LOCK_UN);
c65b7b88
BJ
52}
53
54loginit()
55{
05862919
SL
56 flog = fopen(value(LOG), "a");
57 if (flog == NULL)
65a564bd 58 fprintf(stderr, "can't open log file %s.\r\n", value(LOG));
7ca7c81c 59}
65a564bd 60#endif