17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
37c478bdstevel@tonic-gate * Use is subject to license terms.
47c478bdstevel@tonic-gate */
58d489c7muffin
67c478bdstevel@tonic-gate/*
77c478bdstevel@tonic-gate * Copyright (c) 1983 Regents of the University of California.
87c478bdstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
97c478bdstevel@tonic-gate * specifies the terms and conditions for redistribution.
107c478bdstevel@tonic-gate */
118d489c7muffin
128d489c7muffin#pragma ident	"%Z%%M%	%I%	%E% SMI"
137c478bdstevel@tonic-gate
147c478bdstevel@tonic-gate#include "tip.h"
157c478bdstevel@tonic-gate
167c478bdstevel@tonic-gatestatic	FILE *flog = NULL;
177c478bdstevel@tonic-gate
187c478bdstevel@tonic-gate/*
197c478bdstevel@tonic-gate * Log file maintenance routines
207c478bdstevel@tonic-gate */
218d489c7muffinvoid
228d489c7muffinlogent(char *group, char *num, char *acu, char *message)
237c478bdstevel@tonic-gate{
247c478bdstevel@tonic-gate	char *user, *timestamp;
257c478bdstevel@tonic-gate	struct passwd *pwd;
267c478bdstevel@tonic-gate	time_t t;
277c478bdstevel@tonic-gate
287c478bdstevel@tonic-gate	if (flog == NULL)
297c478bdstevel@tonic-gate		return;
307c478bdstevel@tonic-gate#ifndef USG
317c478bdstevel@tonic-gate	if (flock(fileno(flog), LOCK_EX) < 0) {
327c478bdstevel@tonic-gate		perror("tip: flock");
337c478bdstevel@tonic-gate		return;
347c478bdstevel@tonic-gate	}
357c478bdstevel@tonic-gate#endif
367c478bdstevel@tonic-gate	if ((user = getlogin()) == NOSTR)
377c478bdstevel@tonic-gate		if ((pwd = getpwuid(uid)) == NOPWD)
387c478bdstevel@tonic-gate			user = "???";
397c478bdstevel@tonic-gate		else
407c478bdstevel@tonic-gate			user = pwd->pw_name;
417c478bdstevel@tonic-gate	t = time(0);
427c478bdstevel@tonic-gate	timestamp = ctime(&t);
437c478bdstevel@tonic-gate	timestamp[24] = '\0';
448d489c7muffin	(void) fprintf(flog, "%s (%s) <%s, %s, %s> %s\n",
458d489c7muffin	    user, timestamp, group,
467c478bdstevel@tonic-gate#ifdef PRISTINE
478d489c7muffin	    "",
487c478bdstevel@tonic-gate#else
498d489c7muffin	    num,
507c478bdstevel@tonic-gate#endif
518d489c7muffin	    acu, message);
528d489c7muffin	(void) fflush(flog);
537c478bdstevel@tonic-gate#ifndef USG
547c478bdstevel@tonic-gate	(void) flock(fileno(flog), LOCK_UN);
557c478bdstevel@tonic-gate#endif
567c478bdstevel@tonic-gate}
577c478bdstevel@tonic-gate
588d489c7muffinvoid
598d489c7muffinloginit(void)
607c478bdstevel@tonic-gate{
617c478bdstevel@tonic-gate
627c478bdstevel@tonic-gate#ifdef ACULOG
637c478bdstevel@tonic-gate	flog = fopen(value(LOG), "a");
647c478bdstevel@tonic-gate	if (flog == NULL)
658d489c7muffin		(void) fprintf(stderr, "tip: can't open log file %s\r\n",
668d489c7muffin		    value(LOG));
677c478bdstevel@tonic-gate#endif
687c478bdstevel@tonic-gate}
69