10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
30Sstevel@tonic-gate * Use is subject to license terms.
40Sstevel@tonic-gate */
5*549Smuffin
60Sstevel@tonic-gate /*
70Sstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California.
80Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
90Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
100Sstevel@tonic-gate */
11*549Smuffin
12*549Smuffin #pragma ident "%Z%%M% %I% %E% SMI"
130Sstevel@tonic-gate
140Sstevel@tonic-gate #include "tip.h"
150Sstevel@tonic-gate
160Sstevel@tonic-gate static FILE *flog = NULL;
170Sstevel@tonic-gate
180Sstevel@tonic-gate /*
190Sstevel@tonic-gate * Log file maintenance routines
200Sstevel@tonic-gate */
21*549Smuffin void
logent(char * group,char * num,char * acu,char * message)22*549Smuffin logent(char *group, char *num, char *acu, char *message)
230Sstevel@tonic-gate {
240Sstevel@tonic-gate char *user, *timestamp;
250Sstevel@tonic-gate struct passwd *pwd;
260Sstevel@tonic-gate time_t t;
270Sstevel@tonic-gate
280Sstevel@tonic-gate if (flog == NULL)
290Sstevel@tonic-gate return;
300Sstevel@tonic-gate #ifndef USG
310Sstevel@tonic-gate if (flock(fileno(flog), LOCK_EX) < 0) {
320Sstevel@tonic-gate perror("tip: flock");
330Sstevel@tonic-gate return;
340Sstevel@tonic-gate }
350Sstevel@tonic-gate #endif
360Sstevel@tonic-gate if ((user = getlogin()) == NOSTR)
370Sstevel@tonic-gate if ((pwd = getpwuid(uid)) == NOPWD)
380Sstevel@tonic-gate user = "???";
390Sstevel@tonic-gate else
400Sstevel@tonic-gate user = pwd->pw_name;
410Sstevel@tonic-gate t = time(0);
420Sstevel@tonic-gate timestamp = ctime(&t);
430Sstevel@tonic-gate timestamp[24] = '\0';
44*549Smuffin (void) fprintf(flog, "%s (%s) <%s, %s, %s> %s\n",
45*549Smuffin user, timestamp, group,
460Sstevel@tonic-gate #ifdef PRISTINE
47*549Smuffin "",
480Sstevel@tonic-gate #else
49*549Smuffin num,
500Sstevel@tonic-gate #endif
51*549Smuffin acu, message);
52*549Smuffin (void) fflush(flog);
530Sstevel@tonic-gate #ifndef USG
540Sstevel@tonic-gate (void) flock(fileno(flog), LOCK_UN);
550Sstevel@tonic-gate #endif
560Sstevel@tonic-gate }
570Sstevel@tonic-gate
58*549Smuffin void
loginit(void)59*549Smuffin loginit(void)
600Sstevel@tonic-gate {
610Sstevel@tonic-gate
620Sstevel@tonic-gate #ifdef ACULOG
630Sstevel@tonic-gate flog = fopen(value(LOG), "a");
640Sstevel@tonic-gate if (flog == NULL)
65*549Smuffin (void) fprintf(stderr, "tip: can't open log file %s\r\n",
66*549Smuffin value(LOG));
670Sstevel@tonic-gate #endif
680Sstevel@tonic-gate }
69