xref: /titanic_52/usr/src/cmd/tip/log.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*
2  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 /*
6  * Copyright (c) 1983 Regents of the University of California.
7  * All rights reserved. The Berkeley software License Agreement
8  * specifies the terms and conditions for redistribution.
9  */
10 #ident	"%Z%%M%	%I%	%E% SMI"	/* from UCB 4.6 6/25/83 */
11 
12 #include "tip.h"
13 
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 	time_t t;
26 
27 	if (flog == NULL)
28 		return;
29 #ifndef USG
30 	if (flock(fileno(flog), LOCK_EX) < 0) {
31 		perror("tip: flock");
32 		return;
33 	}
34 #endif
35 	if ((user = getlogin()) == NOSTR)
36 		if ((pwd = getpwuid(uid)) == NOPWD)
37 			user = "???";
38 		else
39 			user = pwd->pw_name;
40 	t = time(0);
41 	timestamp = ctime(&t);
42 	timestamp[24] = '\0';
43 	fprintf(flog, "%s (%s) <%s, %s, %s> %s\n",
44 		user, timestamp, group,
45 #ifdef PRISTINE
46 		"",
47 #else
48 		num,
49 #endif
50 		acu, message);
51 	fflush(flog);
52 #ifndef USG
53 	(void) flock(fileno(flog), LOCK_UN);
54 #endif
55 }
56 
57 loginit()
58 {
59 
60 #ifdef ACULOG
61 	flog = fopen(value(LOG), "a");
62 	if (flog == NULL)
63 		fprintf(stderr, "tip: can't open log file %s\r\n", value(LOG));
64 #endif
65 }
66