2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#include <sys/types.h>
2N/A#include <sys/time.h>
2N/A#include <errno.h>
2N/A#include <stdio.h>
2N/A#include <string.h>
2N/A#include <fcntl.h>
2N/A#include <stdlib.h>
2N/A#include <unistd.h>
2N/A#include <values.h>
2N/A#include <locale.h>
2N/A#include <sys/stat.h>
2N/A#include <strings.h>
2N/A#include <stdarg.h>
2N/A#include <sys/param.h>
2N/A#include <sys/nsctl/nsctl.h>
2N/A
2N/A#include <sys/unistat/spcs_s.h>
2N/A#include <sys/unistat/spcs_s_u.h>
2N/A#include <sys/unistat/spcs_errors.h>
2N/A
2N/A#define MAX_SESSION_LOG (10 * 1024 * 1024) /* allowable log file size */
2N/A
2N/Astatic char sessionlog[] = "/var/adm/ds.log";
2N/Astatic char sessionlog_bak[] = "/var/adm/ds.log.bak";
2N/A
2N/Astatic char *spcstime();
2N/A
2N/Avoid
2N/Aspcs_log(const char *product, spcs_s_info_t *status, const char *format, ...)
2N/A{
2N/A struct stat st;
2N/A FILE *fp = NULL;
2N/A struct flock lk;
2N/A va_list ap;
2N/A
2N/A bzero(&lk, sizeof (lk));
2N/A
2N/A /*
2N/A * check the file size, if > than MAX_SESSION_LOG bytes make a .bak
2N/A * and truncate
2N/A */
2N/A if (stat(sessionlog, &st) == 0) {
2N/A if (st.st_size > MAX_SESSION_LOG) {
2N/A rename(sessionlog, sessionlog_bak);
2N/A }
2N/A }
2N/A
2N/A va_start(ap, format);
2N/A if ((fp = fopen(sessionlog, "a")) == (FILE *)NULL)
2N/A goto fail;
2N/A lk.l_type = F_WRLCK;
2N/A lk.l_whence = SEEK_SET;
2N/A lk.l_start = (off_t)0;
2N/A lk.l_len = (off_t)0;
2N/A
2N/A if (fcntl(fileno(fp), F_SETLKW, &lk) < 0)
2N/A goto fail;
2N/A
2N/A
2N/A fprintf(fp, "%s %s: ", spcstime(), product);
2N/A (void) vfprintf(fp, format, ap);
2N/A fputs("\n", fp);
2N/A if (status)
2N/A spcs_s_report(*status, fp);
2N/A
2N/A fflush(fp);
2N/A
2N/A lk.l_type = F_UNLCK;
2N/A
2N/A (void) fcntl(fileno(fp), F_SETLKW, &lk);
2N/A
2N/Afail:
2N/A if (fp)
2N/A fclose(fp);
2N/A va_end(ap);
2N/A}
2N/A
2N/A/*
2N/A * spcstime(): gets current time
2N/A */
2N/Astatic char *
2N/Aspcstime()
2N/A{
2N/A static char timeptr[20];
2N/A time_t tnow;
2N/A
2N/A tnow = time((time_t *)0);
2N/A cftime(timeptr, "%b %d %T", &tnow);
2N/A return (timeptr);
2N/A}