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/*
2N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A/* Copyright (c) 1988 AT&T */
2N/A/* All Rights Reserved */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A/* lfmt_log() - log info */
2N/A
2N/A#include "lint.h"
2N/A#include <mtlib.h>
2N/A#include <pfmt.h>
2N/A#include <stdio.h>
2N/A#include <sys/types.h>
2N/A#include <sys/types32.h>
2N/A#include <sys/stropts.h>
2N/A#include <sys/strlog.h>
2N/A#include <fcntl.h>
2N/A#include <errno.h>
2N/A#include <synch.h>
2N/A#include <thread.h>
2N/A#include "pfmt_data.h"
2N/A#include <time.h>
2N/A#include <stropts.h>
2N/A#include <unistd.h>
2N/A#include <strings.h>
2N/A#include <sys/uio.h>
2N/A
2N/A#define MAXMSG 1024
2N/A#define LOGNAME "/dev/conslog"
2N/A#define LOG_CONSOLE "/dev/console"
2N/A
2N/Aint
2N/A__lfmt_log(const char *text, const char *sev, va_list args, long flag, int ret)
2N/A{
2N/A static int fd = -1;
2N/A struct strbuf dat;
2N/A int msg_offset;
2N/A long len;
2N/A union {
2N/A long flag;
2N/A char buf[MAXMSG];
2N/A } msg;
2N/A int err;
2N/A int fdd;
2N/A
2N/A len = ret + sizeof (long) + 3;
2N/A
2N/A if (len > sizeof (msg)) {
2N/A errno = ERANGE;
2N/A return (-2);
2N/A }
2N/A
2N/A msg.flag = flag;
2N/A msg_offset = (int)sizeof (long);
2N/A
2N/A lrw_rdlock(&_rw_pfmt_label);
2N/A if (*__pfmt_label)
2N/A msg_offset += strlcpy(msg.buf + msg_offset, __pfmt_label,
2N/A sizeof (msg.buf) - msg_offset);
2N/A lrw_unlock(&_rw_pfmt_label);
2N/A
2N/A if (sev)
2N/A msg_offset += sprintf(msg.buf + msg_offset, sev, flag & 0xff);
2N/A
2N/A msg_offset += 1 + vsprintf(msg.buf + msg_offset, text, args);
2N/A msg.buf[msg_offset++] = '\0';
2N/A
2N/A if (fd == -1 &&
2N/A ((fd = open(LOGNAME, O_WRONLY)) == -1 ||
2N/A fcntl(fd, F_SETFD, 1) == -1))
2N/A return (-2);
2N/A
2N/A dat.maxlen = MAXMSG;
2N/A dat.len = (int)msg_offset;
2N/A dat.buf = msg.buf;
2N/A
2N/A if (putmsg(fd, 0, &dat, 0) == -1) {
2N/A (void) close(fd);
2N/A return (-2);
2N/A }
2N/A
2N/A /*
2N/A * Display it to a console
2N/A */
2N/A if ((flag & MM_CONSOLE) != 0) {
2N/A char *p;
2N/A time_t t;
2N/A char buf[128];
2N/A err = errno;
2N/A fdd = open(LOG_CONSOLE, O_WRONLY);
2N/A if (fdd != -1) {
2N/A /*
2N/A * Use C locale for time stamp.
2N/A */
2N/A (void) time(&t);
2N/A (void) ctime_r(&t, buf, sizeof (buf));
2N/A p = (char *)strrchr(buf, '\n');
2N/A if (p != NULL)
2N/A *p = ':';
2N/A (void) write(fdd, buf, strlen(buf));
2N/A (void) write(fdd, msg.buf + sizeof (long),
2N/A msg_offset - sizeof (long));
2N/A (void) write(fdd, "\n", 1);
2N/A } else
2N/A return (-2);
2N/A (void) close(fdd);
2N/A errno = err;
2N/A }
2N/A return (ret);
2N/A}