xref: /csrg-svn/usr.bin/tip/log.c (revision 13278)
1 #ifndef lint
2 static char sccsid[] = "@(#)log.c	4.5 (Berkeley) 06/25/83";
3 #endif
4 
5 #ifdef ACULOG
6 #include "tip.h"
7 
8 static	FILE *flog = NULL;
9 
10 /*
11  * Log file maintenance routines
12  */
13 
14 logent(group, num, acu, message)
15 	char *group, *num, *acu, *message;
16 {
17 	char *user, *timestamp;
18 	struct passwd *pwd;
19 	long t;
20 
21 	if (flog == NULL)
22 		return;
23 	if (flock(fileno(flog), LOCK_EX) < 0) {
24 		perror("tip: flock");
25 		return;
26 	}
27 	if ((user = getlogin()) == NOSTR)
28 		if ((pwd = getpwuid(getuid())) == NOPWD)
29 			user = "???";
30 		else
31 			user = pwd->pw_name;
32 	t = time(0);
33 	timestamp = ctime(&t);
34 	timestamp[24] = '\0';
35 	fprintf(flog, "%s (%s) <%s, %s, %s> %s\n",
36 		user, timestamp, group,
37 #ifdef PRISTINE
38 		"",
39 #else
40 		num,
41 #endif
42 		acu, message);
43 	fflush(flog);
44 	(void) flock(fileno(flog), LOCK_UN);
45 }
46 
47 loginit()
48 {
49 
50 	flog = fopen(value(LOG), "a");
51 	if (flog == NULL)
52 		fprintf(stderr, "can't open log file\r\n");
53 }
54 #endif
55