1*19810Sdist /* 2*19810Sdist * Copyright (c) 1983 Regents of the University of California. 3*19810Sdist * All rights reserved. The Berkeley software License Agreement 4*19810Sdist * specifies the terms and conditions for redistribution. 5*19810Sdist */ 6*19810Sdist 713278Ssam #ifndef lint 8*19810Sdist static char sccsid[] = "@(#)log.c 5.1 (Berkeley) 04/30/85"; 9*19810Sdist #endif not lint 103693Sroot 1113278Ssam #include "tip.h" 123693Sroot 1313278Ssam static FILE *flog = NULL; 1413278Ssam 153693Sroot /* 163693Sroot * Log file maintenance routines 173693Sroot */ 183693Sroot 193693Sroot logent(group, num, acu, message) 204962Ssam char *group, *num, *acu, *message; 213693Sroot { 223693Sroot char *user, *timestamp; 233693Sroot struct passwd *pwd; 243693Sroot long t; 253693Sroot 263693Sroot if (flog == NULL) 273693Sroot return; 2813278Ssam if (flock(fileno(flog), LOCK_EX) < 0) { 2913278Ssam perror("tip: flock"); 303693Sroot return; 313693Sroot } 323693Sroot if ((user = getlogin()) == NOSTR) 333693Sroot if ((pwd = getpwuid(getuid())) == NOPWD) 343693Sroot user = "???"; 353693Sroot else 363693Sroot user = pwd->pw_name; 373693Sroot t = time(0); 383693Sroot timestamp = ctime(&t); 393693Sroot timestamp[24] = '\0'; 403693Sroot fprintf(flog, "%s (%s) <%s, %s, %s> %s\n", 413693Sroot user, timestamp, group, 423693Sroot #ifdef PRISTINE 433693Sroot "", 443693Sroot #else 453693Sroot num, 463693Sroot #endif 473693Sroot acu, message); 483693Sroot fflush(flog); 4913278Ssam (void) flock(fileno(flog), LOCK_UN); 503693Sroot } 513693Sroot 523693Sroot loginit() 533693Sroot { 5413278Ssam 5513282Ssam #ifdef ACULOG 5613278Ssam flog = fopen(value(LOG), "a"); 5713278Ssam if (flog == NULL) 583693Sroot fprintf(stderr, "can't open log file\r\n"); 5913282Ssam #endif 603693Sroot } 61