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