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 * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 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 * Copyright (c) 1989, 2011, Oracle and/or its affiliates. All rights reserved. 2N/A/* Copyright (c) 1988 AT&T */ 2N/A/* All Rights Reserved */ 2N/A * University Copyright- Copyright (c) 1982, 1986, 1988 2N/A * The Regents of the University of California 2N/A * All Rights Reserved 2N/A * University Acknowledgment- Portions of this document are derived from 2N/A * software developed by the University of California, Berkeley, and its 2N/A * SYSLOG -- print message on log file 2N/A * This routine looks a lot like printf, except that it 2N/A * outputs to the log file instead of the standard output. 2N/A * prints the module name in front of the message, 2N/A * has some other formatting types (or will sometime), 2N/A * adds a newline on the end of the message. 2N/A * The output of this routine is intended to be read by /etc/syslogd. 2N/A#
define MAXLINE 1024 /* max message size (but see below) */ 2N/A -
1,
/* fd for log */ 2N/A 0,
/* status bits, set by openlog() */ 2N/A "syslog",
/* string to tag the entry with */ 2N/A 0xff,
/* mask of priorities to be logged */ 2N/A FALSE,
/* check for validity of fd for log */ 2N/A 0,
/* openlog has not yet been called */ 2N/A * Regrettably, there are several instances inside libc where 2N/A * syslog() is called from the bottom of a deep call stack 2N/A * and a critical lock was acquired near the top of the stack. 2N/A * Because syslog() uses stdio (and it is called from within stdio) 2N/A * it runs the danger of deadlocking, perhaps with an interposed 2N/A * malloc() when fork() is occurring concurrently, perhaps with 2N/A * some other lock within libc. 2N/A * The only fix for this problem is to restructure libc not to do 2N/A * this thing and always to call syslog() with no locks held. 2N/A * This restructuring will require a substantial effort. 2N/A * Meanwhile, we just hope that on the rare occasion that syslog() 2N/A * is called from within libc (such occurrences should "never happen") 2N/A * that we don't get caught in a race condition deadlock. 2N/A char timestr[
26];
/* hardwired value 26 due to Posix */ 2N/A * Maximum tag length is 256 (the pad in outline) minus the size of the 2N/A * other things that can go in the pad. 2N/A /* see if we should just throw out this message */ 2N/A * if openlog() has not been called by the application, 2N/A * try to get the name of the application and set it 2N/A * as the ident string for messages. If unable to get 2N/A * it for any reason, fall back to using the default 2N/A * of syslog. If we succeed in getting the name, also 2N/A * turn on LOG_PID, to provide greater detail. 2N/A /* set default facility if none specified */ 2N/A /* build the header */ 2N/A /* build the message */ 2N/A * To avoid potential security problems, bounds checking is done 2N/A * on outline and buf. 2N/A * The following code presumes that the header information will 2N/A * fit in 250-odd bytes, as was accounted for in the buffer size 2N/A * allocation. This is dependent on the assumption that the LogTag 2N/A * and the string returned by sprintf() for getpid() will return 2N/A * be less than 230-odd characters combined. 2N/A if ((c = *f++) !=
'm') {
2N/A if (b >
buf && *(b-
1) !=
'\n')
/* ensure at least one newline */ 2N/A /* LINTED variable format specifier */ 2N/A * 1136432 points out that the underlying log driver actually 2N/A * refuses to accept (ERANGE) messages longer than LOG_MAXPS 2N/A * bytes. So it really doesn't make much sense to putmsg a 2N/A /* set up the strbufs */ 2N/A /* output the message to the local logger */ 2N/A * Output the message to the console directly. To reduce visual 2N/A * clutter, we strip out the message ID. 2N/A * Use a door call to syslogd to see if it's alive. 2N/A * see if our pid matches the pid of the door server. 2N/A * If so, syslogd has called syslog(), probably as 2N/A * a result of some name service library error, and 2N/A * we don't want to let syslog continue and possibly 2N/A return (0);
/* failure - syslogd dead */ 2N/A * OPENLOG -- open system log 2N/A * if the fstat(2) fails or the st_rdev has changed 2N/A * then we must open the file 2N/A * CLOSELOG -- close the system log 2N/A /* if the LogFile is invalid it can not be closed */ 2N/A * if the fstat(2) fails or the st_rdev has changed 2N/A * then we can not close the file 2N/A * SETLOGMASK -- set the log mask level