Commit | Line | Data |
---|---|---|
051b1e55 | 1 | /* |
c9686c12 KB |
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 the above copyright notice and this paragraph are | |
7 | * duplicated in all such forms and that any documentation, | |
8 | * advertising materials, and other materials related to such | |
9 | * distribution and use acknowledge that the software was developed | |
10 | * by the University of California, Berkeley. The name of the | |
11 | * University may not be used to endorse or promote products derived | |
12 | * from this software without specific prior written permission. | |
13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR | |
14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | |
15 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
051b1e55 DF |
16 | */ |
17 | ||
05862919 | 18 | #ifndef lint |
c9686c12 KB |
19 | static char sccsid[] = "@(#)log.c 5.3 (Berkeley) %G%"; |
20 | #endif /* not lint */ | |
c65b7b88 | 21 | |
05862919 SL |
22 | #include "tip.h" |
23 | ||
65a564bd | 24 | #ifdef ACULOG |
05862919 | 25 | static FILE *flog = NULL; |
c65b7b88 BJ |
26 | |
27 | /* | |
28 | * Log file maintenance routines | |
29 | */ | |
30 | ||
31 | logent(group, num, acu, message) | |
d8feebc2 | 32 | char *group, *num, *acu, *message; |
c65b7b88 BJ |
33 | { |
34 | char *user, *timestamp; | |
35 | struct passwd *pwd; | |
36 | long t; | |
37 | ||
38 | if (flog == NULL) | |
39 | return; | |
05862919 SL |
40 | if (flock(fileno(flog), LOCK_EX) < 0) { |
41 | perror("tip: flock"); | |
c65b7b88 BJ |
42 | return; |
43 | } | |
44 | if ((user = getlogin()) == NOSTR) | |
45 | if ((pwd = getpwuid(getuid())) == NOPWD) | |
46 | user = "???"; | |
47 | else | |
48 | user = pwd->pw_name; | |
49 | t = time(0); | |
50 | timestamp = ctime(&t); | |
51 | timestamp[24] = '\0'; | |
52 | fprintf(flog, "%s (%s) <%s, %s, %s> %s\n", | |
53 | user, timestamp, group, | |
54 | #ifdef PRISTINE | |
55 | "", | |
56 | #else | |
57 | num, | |
58 | #endif | |
59 | acu, message); | |
65a564bd | 60 | (void) fflush(flog); |
05862919 | 61 | (void) flock(fileno(flog), LOCK_UN); |
c65b7b88 BJ |
62 | } |
63 | ||
64 | loginit() | |
65 | { | |
05862919 SL |
66 | flog = fopen(value(LOG), "a"); |
67 | if (flog == NULL) | |
65a564bd | 68 | fprintf(stderr, "can't open log file %s.\r\n", value(LOG)); |
7ca7c81c | 69 | } |
65a564bd | 70 | #endif |