119810Sdist /* 2*35464Sbostic * Copyright (c) 1983 The Regents of the University of California. 3*35464Sbostic * All rights reserved. 4*35464Sbostic * 5*35464Sbostic * Redistribution and use in source and binary forms are permitted 6*35464Sbostic * provided that the above copyright notice and this paragraph are 7*35464Sbostic * duplicated in all such forms and that any documentation, 8*35464Sbostic * advertising materials, and other materials related to such 9*35464Sbostic * distribution and use acknowledge that the software was developed 10*35464Sbostic * by the University of California, Berkeley. The name of the 11*35464Sbostic * University may not be used to endorse or promote products derived 12*35464Sbostic * from this software without specific prior written permission. 13*35464Sbostic * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14*35464Sbostic * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15*35464Sbostic * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 1619810Sdist */ 1719810Sdist 1813278Ssam #ifndef lint 19*35464Sbostic static char sccsid[] = "@(#)log.c 5.3 (Berkeley) 09/02/88"; 20*35464Sbostic #endif /* not lint */ 213693Sroot 2213278Ssam #include "tip.h" 233693Sroot 2431012Sbostic #ifdef ACULOG 2513278Ssam static FILE *flog = NULL; 2613278Ssam 273693Sroot /* 283693Sroot * Log file maintenance routines 293693Sroot */ 303693Sroot 313693Sroot logent(group, num, acu, message) 324962Ssam char *group, *num, *acu, *message; 333693Sroot { 343693Sroot char *user, *timestamp; 353693Sroot struct passwd *pwd; 363693Sroot long t; 373693Sroot 383693Sroot if (flog == NULL) 393693Sroot return; 4013278Ssam if (flock(fileno(flog), LOCK_EX) < 0) { 4113278Ssam perror("tip: flock"); 423693Sroot return; 433693Sroot } 443693Sroot if ((user = getlogin()) == NOSTR) 453693Sroot if ((pwd = getpwuid(getuid())) == NOPWD) 463693Sroot user = "???"; 473693Sroot else 483693Sroot user = pwd->pw_name; 493693Sroot t = time(0); 503693Sroot timestamp = ctime(&t); 513693Sroot timestamp[24] = '\0'; 523693Sroot fprintf(flog, "%s (%s) <%s, %s, %s> %s\n", 533693Sroot user, timestamp, group, 543693Sroot #ifdef PRISTINE 553693Sroot "", 563693Sroot #else 573693Sroot num, 583693Sroot #endif 593693Sroot acu, message); 6031012Sbostic (void) fflush(flog); 6113278Ssam (void) flock(fileno(flog), LOCK_UN); 623693Sroot } 633693Sroot 643693Sroot loginit() 653693Sroot { 6613278Ssam flog = fopen(value(LOG), "a"); 6713278Ssam if (flog == NULL) 6831012Sbostic fprintf(stderr, "can't open log file %s.\r\n", value(LOG)); 6931012Sbostic } 7013282Ssam #endif 71