xref: /csrg-svn/usr.bin/tip/log.c (revision 62315)
119810Sdist /*
2*62315Sbostic  * Copyright (c) 1983, 1993
3*62315Sbostic  *	The Regents of the University of California.  All rights reserved.
435464Sbostic  *
542770Sbostic  * %sccs.include.redist.c%
619810Sdist  */
719810Sdist 
813278Ssam #ifndef lint
9*62315Sbostic static char sccsid[] = "@(#)log.c	8.1 (Berkeley) 06/06/93";
1035464Sbostic #endif /* not lint */
113693Sroot 
1213278Ssam #include "tip.h"
133693Sroot 
1431012Sbostic #ifdef ACULOG
1513278Ssam static	FILE *flog = NULL;
1613278Ssam 
173693Sroot /*
183693Sroot  * Log file maintenance routines
193693Sroot  */
203693Sroot 
logent(group,num,acu,message)213693Sroot logent(group, num, acu, message)
224962Ssam 	char *group, *num, *acu, *message;
233693Sroot {
243693Sroot 	char *user, *timestamp;
253693Sroot 	struct passwd *pwd;
263693Sroot 	long t;
273693Sroot 
283693Sroot 	if (flog == NULL)
293693Sroot 		return;
3013278Ssam 	if (flock(fileno(flog), LOCK_EX) < 0) {
3113278Ssam 		perror("tip: flock");
323693Sroot 		return;
333693Sroot 	}
343693Sroot 	if ((user = getlogin()) == NOSTR)
353693Sroot 		if ((pwd = getpwuid(getuid())) == NOPWD)
363693Sroot 			user = "???";
373693Sroot 		else
383693Sroot 			user = pwd->pw_name;
393693Sroot 	t = time(0);
403693Sroot 	timestamp = ctime(&t);
413693Sroot 	timestamp[24] = '\0';
423693Sroot 	fprintf(flog, "%s (%s) <%s, %s, %s> %s\n",
433693Sroot 		user, timestamp, group,
443693Sroot #ifdef PRISTINE
453693Sroot 		"",
463693Sroot #else
473693Sroot 		num,
483693Sroot #endif
493693Sroot 		acu, message);
5031012Sbostic 	(void) fflush(flog);
5113278Ssam 	(void) flock(fileno(flog), LOCK_UN);
523693Sroot }
533693Sroot 
loginit()543693Sroot loginit()
553693Sroot {
5613278Ssam 	flog = fopen(value(LOG), "a");
5713278Ssam 	if (flog == NULL)
5831012Sbostic 		fprintf(stderr, "can't open log file %s.\r\n", value(LOG));
5931012Sbostic }
6013282Ssam #endif
61