1 /*
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8 #ifndef lint
9 static char sccsid[] = "@(#)log.c 8.1 (Berkeley) 06/06/93";
10 #endif /* not lint */
11
12 #include "tip.h"
13
14 #ifdef ACULOG
15 static FILE *flog = NULL;
16
17 /*
18 * Log file maintenance routines
19 */
20
logent(group,num,acu,message)21 logent(group, num, acu, message)
22 char *group, *num, *acu, *message;
23 {
24 char *user, *timestamp;
25 struct passwd *pwd;
26 long t;
27
28 if (flog == NULL)
29 return;
30 if (flock(fileno(flog), LOCK_EX) < 0) {
31 perror("tip: flock");
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);
50 (void) fflush(flog);
51 (void) flock(fileno(flog), LOCK_UN);
52 }
53
loginit()54 loginit()
55 {
56 flog = fopen(value(LOG), "a");
57 if (flog == NULL)
58 fprintf(stderr, "can't open log file %s.\r\n", value(LOG));
59 }
60 #endif
61