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