dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / tip / log.c
blobb9d26ebf940a2eb06fb94c92014718700a5fd600
1 /*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
6 /*
7 * Copyright (c) 1983 Regents of the University of California.
8 * All rights reserved. The Berkeley software License Agreement
9 * specifies the terms and conditions for redistribution.
12 #pragma ident "%Z%%M% %I% %E% SMI"
14 #include "tip.h"
16 static FILE *flog = NULL;
19 * Log file maintenance routines
21 void
22 logent(char *group, char *num, char *acu, char *message)
24 char *user, *timestamp;
25 struct passwd *pwd;
26 time_t t;
28 if (flog == NULL)
29 return;
30 #ifndef USG
31 if (flock(fileno(flog), LOCK_EX) < 0) {
32 perror("tip: flock");
33 return;
35 #endif
36 if ((user = getlogin()) == NOSTR)
37 if ((pwd = getpwuid(uid)) == NOPWD)
38 user = "???";
39 else
40 user = pwd->pw_name;
41 t = time(0);
42 timestamp = ctime(&t);
43 timestamp[24] = '\0';
44 (void) fprintf(flog, "%s (%s) <%s, %s, %s> %s\n",
45 user, timestamp, group,
46 #ifdef PRISTINE
47 "",
48 #else
49 num,
50 #endif
51 acu, message);
52 (void) fflush(flog);
53 #ifndef USG
54 (void) flock(fileno(flog), LOCK_UN);
55 #endif
58 void
59 loginit(void)
62 #ifdef ACULOG
63 flog = fopen(value(LOG), "a");
64 if (flog == NULL)
65 (void) fprintf(stderr, "tip: can't open log file %s\r\n",
66 value(LOG));
67 #endif