113278Ssam #ifndef lint 2*13282Ssam static char sccsid[] = "@(#)log.c 4.6 (Berkeley) 06/25/83"; 313278Ssam #endif 43693Sroot 513278Ssam #include "tip.h" 63693Sroot 713278Ssam static FILE *flog = NULL; 813278Ssam 93693Sroot /* 103693Sroot * Log file maintenance routines 113693Sroot */ 123693Sroot 133693Sroot logent(group, num, acu, message) 144962Ssam char *group, *num, *acu, *message; 153693Sroot { 163693Sroot char *user, *timestamp; 173693Sroot struct passwd *pwd; 183693Sroot long t; 193693Sroot 203693Sroot if (flog == NULL) 213693Sroot return; 2213278Ssam if (flock(fileno(flog), LOCK_EX) < 0) { 2313278Ssam perror("tip: flock"); 243693Sroot return; 253693Sroot } 263693Sroot if ((user = getlogin()) == NOSTR) 273693Sroot if ((pwd = getpwuid(getuid())) == NOPWD) 283693Sroot user = "???"; 293693Sroot else 303693Sroot user = pwd->pw_name; 313693Sroot t = time(0); 323693Sroot timestamp = ctime(&t); 333693Sroot timestamp[24] = '\0'; 343693Sroot fprintf(flog, "%s (%s) <%s, %s, %s> %s\n", 353693Sroot user, timestamp, group, 363693Sroot #ifdef PRISTINE 373693Sroot "", 383693Sroot #else 393693Sroot num, 403693Sroot #endif 413693Sroot acu, message); 423693Sroot fflush(flog); 4313278Ssam (void) flock(fileno(flog), LOCK_UN); 443693Sroot } 453693Sroot 463693Sroot loginit() 473693Sroot { 4813278Ssam 49*13282Ssam #ifdef ACULOG 5013278Ssam flog = fopen(value(LOG), "a"); 5113278Ssam if (flog == NULL) 523693Sroot fprintf(stderr, "can't open log file\r\n"); 53*13282Ssam #endif 543693Sroot } 55