1 /* 2 * Copyright (c) 1983 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 18 #ifndef lint 19 static char sccsid[] = "@(#)log.c 5.3 (Berkeley) 09/02/88"; 20 #endif /* not lint */ 21 22 #include "tip.h" 23 24 #ifdef ACULOG 25 static FILE *flog = NULL; 26 27 /* 28 * Log file maintenance routines 29 */ 30 31 logent(group, num, acu, message) 32 char *group, *num, *acu, *message; 33 { 34 char *user, *timestamp; 35 struct passwd *pwd; 36 long t; 37 38 if (flog == NULL) 39 return; 40 if (flock(fileno(flog), LOCK_EX) < 0) { 41 perror("tip: flock"); 42 return; 43 } 44 if ((user = getlogin()) == NOSTR) 45 if ((pwd = getpwuid(getuid())) == NOPWD) 46 user = "???"; 47 else 48 user = pwd->pw_name; 49 t = time(0); 50 timestamp = ctime(&t); 51 timestamp[24] = '\0'; 52 fprintf(flog, "%s (%s) <%s, %s, %s> %s\n", 53 user, timestamp, group, 54 #ifdef PRISTINE 55 "", 56 #else 57 num, 58 #endif 59 acu, message); 60 (void) fflush(flog); 61 (void) flock(fileno(flog), LOCK_UN); 62 } 63 64 loginit() 65 { 66 flog = fopen(value(LOG), "a"); 67 if (flog == NULL) 68 fprintf(stderr, "can't open log file %s.\r\n", value(LOG)); 69 } 70 #endif 71