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