xref: /csrg-svn/usr.bin/tip/log.c (revision 13278)
1*13278Ssam #ifndef lint
2*13278Ssam static char sccsid[] = "@(#)log.c	4.5 (Berkeley) 06/25/83";
3*13278Ssam #endif
43693Sroot 
53693Sroot #ifdef ACULOG
6*13278Ssam #include "tip.h"
73693Sroot 
8*13278Ssam static	FILE *flog = NULL;
9*13278Ssam 
103693Sroot /*
113693Sroot  * Log file maintenance routines
123693Sroot  */
133693Sroot 
143693Sroot logent(group, num, acu, message)
154962Ssam 	char *group, *num, *acu, *message;
163693Sroot {
173693Sroot 	char *user, *timestamp;
183693Sroot 	struct passwd *pwd;
193693Sroot 	long t;
203693Sroot 
213693Sroot 	if (flog == NULL)
223693Sroot 		return;
23*13278Ssam 	if (flock(fileno(flog), LOCK_EX) < 0) {
24*13278Ssam 		perror("tip: flock");
253693Sroot 		return;
263693Sroot 	}
273693Sroot 	if ((user = getlogin()) == NOSTR)
283693Sroot 		if ((pwd = getpwuid(getuid())) == NOPWD)
293693Sroot 			user = "???";
303693Sroot 		else
313693Sroot 			user = pwd->pw_name;
323693Sroot 	t = time(0);
333693Sroot 	timestamp = ctime(&t);
343693Sroot 	timestamp[24] = '\0';
353693Sroot 	fprintf(flog, "%s (%s) <%s, %s, %s> %s\n",
363693Sroot 		user, timestamp, group,
373693Sroot #ifdef PRISTINE
383693Sroot 		"",
393693Sroot #else
403693Sroot 		num,
413693Sroot #endif
423693Sroot 		acu, message);
433693Sroot 	fflush(flog);
44*13278Ssam 	(void) flock(fileno(flog), LOCK_UN);
453693Sroot }
463693Sroot 
473693Sroot loginit()
483693Sroot {
49*13278Ssam 
50*13278Ssam 	flog = fopen(value(LOG), "a");
51*13278Ssam 	if (flog == NULL)
523693Sroot 		fprintf(stderr, "can't open log file\r\n");
533693Sroot }
543693Sroot #endif
55