log.c revision 0bd4e3591ac1a729c7ec8f811844119473350975
823N/A * Copyright (C) 1999 Internet Software Consortium. 823N/A * Permission to use, copy, modify, and distribute this software for any 823N/A * purpose with or without fee is hereby granted, provided that the above 823N/A * copyright notice and this permission notice appear in all copies. 823N/A * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS 823N/A * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES 823N/A * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE 823N/A * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 823N/A * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 823N/A * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS 823N/A * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 823N/A/* $Id: log.c,v 1.14 2000/01/06 15:01:16 tale Exp $ */ 823N/A/* Principal Authors: DCL */ 823N/A * This is the structure that holds each named channel. A simple linked 823N/A * list chains all of the channels together, so an individual channel is 823N/A * found by doing strcmp()s with the names down the list. Their should 823N/A * be no peformance penalty from this as it is expected that the number 897N/A * of named channels will be no more than a dozen or so, and name lookups 823N/A * from the head of the list are only done when isc_log_usechannel() is 823N/A * called, which should also be very infrequent. 823N/A * The logchannelist structure associates categories and modules with 823N/A * channels. First the appropriate channellist is found based on the 823N/A * category, and then each structure in the linked list is checked for 823N/A * a matching module. It is expected that the number of channels 823N/A * associated with any given category will be very short, no more than 823N/A * three or four in the more unusual cases. 823N/A * This structure is used to remember messages for pruning via * This isc_log structure provides the context for the isc_log functions. * The log context locks itself in isc_log_vwrite, the internal backend to * isc_log_write. The locking is necessary both to provide exclusive access * to the the buffer into which the message is formatted and to guard against * competing threads trying to write to the same syslog resource. (On * some systems, such as BSD/OS, stdio is thread safe but syslog is not.) * Unfortunately, the lock cannot guard against a _different_ logging * context in the same program competing for syslog's attention. Thus * There Can Be Only One, but this is not enforced. * Used when ISC_LOG_PRINTLEVEL is enabled for a channel. "debug",
"info",
"notice",
"warning",
"error",
"critical" * Used to convert ISC_LOG_* priorities into syslog priorities. * When adding new categories, a corresponding ISC_LOGCATEGORY_foo * definition needs to be added to <isc/log.h>. Each name string should * end with a colon-space pair because they are used in the formatted * log message when ISC_LOG_PRINTCATEGORY is enabled. * The default category is provided so that the internal default can * be overridden. Since the default is always looked up as the first * channellist in the log context, it must come first in isc_categories[]. {
"default", 0 },
/* "default" must come first. */ * This essentially static structure must be filled in at run time, * so that the default_debug channel's structure can be addressed. * Establish a new logging context, with default channels. * Normally the magic number is the last thing set in the structure, * but isc_log_createchannel() needs a valid context. If the channel * creation fails, the lctx is not returned to the caller. * Create the default channels: * default_syslog, default_stderr, default_debug and null. * Set the default category's channel to default_stderr. * Total the number of categories that will exist when these are added. * Update the id number of the category with its new global id. * Total the number of modules that will exist when these are added. * Update the id number of the module with its new global id. /* XXX DCL find duplicate names? */ * The file name is copied because greatest_version wants * to scribble on it, so it needs to be definitely in * If default_stderr was redefined, make the default category * point to the new default_stderr. * Silence bogus GCC warning, "`result' might be used uninitialized". * Assign to all categories. Note that this includes * Contract checking is done in isc_log_doit(). * Contract checking is done in isc_log_doit(). * Contract checking is done in isc_log_doit(). * Contract checking is done in isc_log_doit(). /* XXXDCL NT -- This interface will assuredly be changing. */ return (0);
/* ... and roll_log will likely report an error. */ * XXXDCL versions = 0 & versions == ISC_LOG_ROLLINFINITE do not work. * Do nothing (not even excess version trimming) if ISC_LOG_ROLLNEVER * is specified. Apparently complete external control over the log * Set greatest_version to the greatest existing version * (not the maximum requested version). This is 1 based even * though the file names are 0 based, so an oldest log of log.1 * is a greatest_version of 2. * Now greatest should be set to the highest version number desired. * Since the highest number is one less than FILE_VERSIONS(channel) * when not doing infinite log rolling, greatest will need to be * decremented when it is equal to -- or greater than -- * FILE_VERSIONS(channel). When greatest is less than * FILE_VERSIONS(channel), it is already suitable for use as * the maximum version number. * When greatest is >= FILE_VERSIONS(channel), it needs to * be reduced until it is FILE_VERSIONS(channel) - 1. * Remove any excess logs on the way to that value. * Ensure the name fits in the filesystem. Note that in this will not * trigger failure until there is going to be a log rolled into a name * that is too long, not when the maximum possible version name would * be too long. Imagine a case where the name for logs 0-9 is exactly * as long as the maximum filename, but FILE_VERSIONS is configured as * 11. log.10's name will be too long, but no error will be triggered * until log.9 exists and needs to be rolled. * Determine type of file; only regular files will be /* XXXDCL if not regular_file complain? */ * Programs can use libraries that use this logging code without * wanting to do any logging, thus the log context is allowed to * XXX duplicate filtering (do not write multiple times to same source * If the channel list end was reached and a match was made, * everything is finished. * Try the category named "default". * No matching module was explicitly configured * for the category named "default". Use the internal * Emulate syslog's time format. * XXXDCL it would be nice if format were configurable. * Only format the message once. * 'oldest' is the age of the oldest messages * which fall within the duplicate_interval * than the duplicate_interval, * so it should be dropped from * XXX Setting the interval * to be longer will obviously * message to spring back into * This message is in the duplicate * ... and it is a duplicate. * get the hell out of Dodge. * It wasn't in the duplicate interval, * so add it to the message list. * Put the text immediately after * the struct. The strcpy is safe. * This will cause the message * to immediately expire on * the next call to [v]write1. * Probably something more meaningful should be * If the file now exceeds its maximum size * threshold, close it and mark it ready * for reopening the next time the channel is used. /* XXXDCL complain if fstat fails? */