119810Sdist /* 219810Sdist * Copyright (c) 1983 Regents of the University of California. 319810Sdist * All rights reserved. The Berkeley software License Agreement 419810Sdist * specifies the terms and conditions for redistribution. 519810Sdist */ 619810Sdist 713278Ssam #ifndef lint 8*31012Sbostic static char sccsid[] = "@(#)log.c 5.2 (Berkeley) 05/02/87"; 919810Sdist #endif not lint 103693Sroot 1113278Ssam #include "tip.h" 123693Sroot 13*31012Sbostic #ifdef ACULOG 1413278Ssam static FILE *flog = NULL; 1513278Ssam 163693Sroot /* 173693Sroot * Log file maintenance routines 183693Sroot */ 193693Sroot 203693Sroot logent(group, num, acu, message) 214962Ssam char *group, *num, *acu, *message; 223693Sroot { 233693Sroot char *user, *timestamp; 243693Sroot struct passwd *pwd; 253693Sroot long t; 263693Sroot 273693Sroot if (flog == NULL) 283693Sroot return; 2913278Ssam if (flock(fileno(flog), LOCK_EX) < 0) { 3013278Ssam perror("tip: flock"); 313693Sroot return; 323693Sroot } 333693Sroot if ((user = getlogin()) == NOSTR) 343693Sroot if ((pwd = getpwuid(getuid())) == NOPWD) 353693Sroot user = "???"; 363693Sroot else 373693Sroot user = pwd->pw_name; 383693Sroot t = time(0); 393693Sroot timestamp = ctime(&t); 403693Sroot timestamp[24] = '\0'; 413693Sroot fprintf(flog, "%s (%s) <%s, %s, %s> %s\n", 423693Sroot user, timestamp, group, 433693Sroot #ifdef PRISTINE 443693Sroot "", 453693Sroot #else 463693Sroot num, 473693Sroot #endif 483693Sroot acu, message); 49*31012Sbostic (void) fflush(flog); 5013278Ssam (void) flock(fileno(flog), LOCK_UN); 513693Sroot } 523693Sroot 533693Sroot loginit() 543693Sroot { 5513278Ssam flog = fopen(value(LOG), "a"); 5613278Ssam if (flog == NULL) 57*31012Sbostic fprintf(stderr, "can't open log file %s.\r\n", value(LOG)); 58*31012Sbostic } 5913282Ssam #endif 60