Pavel Charvat [Sat, 4 Jul 2009 14:27:00 +0000 (16:27 +0200)]
Improved building of centrum-sherlock-* packages.
* Added sherlock build system to centrum-sherlock-lib-dev.
* We now use custom INSTALL_*_DIR options to avoid replacing of paths everywhere.
* Resulting .tar.gz contains entire sherlock tree.
Martin Mares [Sun, 22 Feb 2009 10:41:13 +0000 (11:41 +0100)]
Config: If cf_def_file is NULL, initialize the configuration.
Otherwise we end up uninitialized clists and other nasty stuff. (The problems
were rarely visible, but the recent changes to conf-input.c have caused some
extra commits, which crashed when no configuration was loaded.)
This is a departure from the behavior of LibUCW 3.12, but I think we should
guarantee that after cf_getopt(), the configuration is always in a consistent
state, meaning that it has been initialized and committed. This should not
depend on whether the default config file was loaded or not.
On the other hand, program which avoid cf_getopt() and call cf_load() are on
their own, there is no implicit commit for them yet. Maybe this should be
fixed, too.
Martin Mares [Sat, 21 Feb 2009 21:05:29 +0000 (22:05 +0100)]
Logging: Let log_new_file() and log_new_fd() accept flags.
This way, we can request a stream cloned to stderr (originally, this was
available only via log_file()) or a FD-based stream which closes the FD
upon closing.
Martin Mares [Sat, 21 Feb 2009 19:31:30 +0000 (20:31 +0100)]
Logging: Write a note when some messages fall victim to limiting.
I was considering various shapes of this message. It is tempting to mention
the number of dropped messages, but that has to be done at the time of
an accepted message, which could be too late (the user might already have
wondered about the fate of the missing messages).
Second, I wanted to include a message type, but it would be misleading,
since a single limiter can apply to more types at once with a common bucket.
Martin Mares [Fri, 20 Feb 2009 15:54:09 +0000 (16:54 +0100)]
Logging: L_SIGHANDLER should be really safe.
I have realized that many operations performed by the log stream code are
either unsafe to call from signal handlers, subject to races between the
main program and its signal handlers, or subject to deadlocks when the
ucwlib_lock is taken.
I have therefore changed the semantics of L_SIGHANDLER to provide only
the minimal logging service: All sighandler messages are now logged to
stderr (which usually follows the main log file) and they are limited
to 255 characters (so that no dynamic allocation is performed).
Martin Mares [Thu, 19 Feb 2009 17:48:23 +0000 (18:48 +0100)]
Logging: Report logging errors.
Introduce an analogue of the infamous "Error while printing error message" :-)
When logging to a stream fails, the error is reported to the default stream,
but there are two precautions against infinite loops and floods of error
messages. First, we never report an error when logging of an error fails.
Second, we report only the first failure of a stream.
It is also possible to request program termination when logging fails.
Martin Mares [Thu, 19 Feb 2009 17:03:14 +0000 (18:03 +0100)]
Logging: Fixed a bug in log_close_all().
Under some circumstances (involving loops in substream structure),
log_close_all() crashed, because a stream could have become freed
when removing its substreams.
I have changed log_close_all() to unlink all substreams first and
then proceed with deallocating memory.
The same problem can never occur in simple log_close_stream(),
because a stream that is a part of a loop never gets a use count of 0.
Martin Mares [Sat, 14 Feb 2009 21:21:58 +0000 (22:21 +0100)]
Logging: Documentation and minor cleanups of headers.
I have written complete documentation for the logging module. In the process,
I have performed a couple of minor cleanups:
o Internal declarations were moved to ucw/log-internal.h.
o Defines for "all" and "nothing" values have been removed, the customary
constants `0' and `~0U' always work and they seem to be more readable.
o LSFLAG_SIGHANDLER gave its way to L_SIGHANDLER.
o The (unused) user flags field was replaced by a message type field;
in the future, the streams will be able to filter the message based
on a type.
o The `internal flags' field was renamed to `control bits'.
Martin Mares [Sat, 14 Feb 2009 09:23:19 +0000 (10:23 +0100)]
Logging: Log file established log_file() is always dup'ed as stderr.
Previously, stderr was set only at the first open and we forgot to re-dup
it after switching log files.
I have also removed the logic in do_log_reopen() which tried to keep the fd
of the log file stable. Except for having stderr follow the log file, this
was of no use.
Martin Mares [Fri, 13 Feb 2009 23:59:36 +0000 (00:59 +0100)]
Logging: Introduce inheritance of log_stream's.
The outbreak of various private fields (idata, pdata, udata) in struct log_stream
has gotten somewhat ugly, so I have replaced them by real private data allocated
after the standard portion of the log_stream structure.
log_new_stream() has gained a parameter telling it the size of the structure
to allocate. I have kept the recycler for the time being -- while saving allocations
is not worth the effort, it still nicely keeps the list of free stream ID's.
As idata are gone, the list of free items is now chained by log_stream->levels.
The default log stream no longer stores the fd explicitly, both log-file and
log-syslog keep private data in their own data structure extending log_stream.
Martin Mares [Fri, 13 Feb 2009 23:36:27 +0000 (00:36 +0100)]
Logging: Introduce use counts on streams.
It turned out to be quite inconvenient to have to close the substreams in
topological order. I have introduced use counts on all streams: A newly
created stream has use count of 1, whenever it is used as a substream,
the use count increases; when the count drops to 0, the stream is
automatically destroyed.
A slightly unpleasant side-effect is that the default log stream
can no longer be constant, since we modify its counter.
I have also extended log_rm_substream() to remove all substreams
when what==NULL. This is useful in log_close_stream() and also
in log_file().
Martin Mares [Fri, 13 Feb 2009 18:47:00 +0000 (19:47 +0100)]
Logging: Introduced struct log_msg.
The logging handlers and filters are often interested in various properties
of the message in their raw form. I have modified the hooks to accept
a single pointer to `struct log_msg', which contains all needed information.
An immediate consequence is that we no longer need the calls to time() in
log-file, so a message is always timestamped at a single place when entering
the log machinery.
Martin Mares [Fri, 13 Feb 2009 18:32:48 +0000 (19:32 +0100)]
Logging: Resurrected the log_file() interface.
It is still useful for programs that use just a single log file. It creates
a new file stream and connects it as a substream of stream #0, replacing
the previous substreams.
Also keep fd #2 as a duplicate of the log file fd, so that errors of exec'd
programs will not be lost.
Martin Mares [Fri, 13 Feb 2009 18:20:47 +0000 (19:20 +0100)]
Logging: Rewritten the log-file module to implement log switching.
o log-file is a cross between the old libucw code and Tom's version.
o Introduced log_stream->udata for backend's flags.
o log_fork() moved to log.c.
o log_switch() and log_file() are not implemented yet.
Martin Mares [Fri, 13 Feb 2009 17:12:39 +0000 (18:12 +0100)]
Logging: Clean up log-stream.c.
o Simplified log_new_stream() -- recycling of closed streams
and allocation of new streams are two different code paths now.
o The calls to log_init_module() need not be conditional.
o Use clist_init() for initializing clists.
o The usual coding style and namespace cleanups.
Also added an explanatory comment about the uninitialized state to log.c.
Martin Mares [Fri, 13 Feb 2009 16:52:31 +0000 (17:52 +0100)]
Logging: Cleanup of log.c
o log_progname[] moved to log_init()
o Both vmsg() and log_pass_msg() now allocate the buffer on the stack
if the message is smaller than 256 bytes.
o log_pid is used instead of repeated calls to getpid()
o sizeof(array) always preferred over repeated constants
o Many coding style cleanups to make the old and new code fit together.
o Namespace cleanups
o Updated comments
Martin Mares [Fri, 13 Feb 2009 16:22:43 +0000 (17:22 +0100)]
Logging: The Great Shuffle
I have split the new logging machinery to several files and started merging
it with the old logger.
The intention behind the split is that programs which do not create their
own log streams should include only <ucw/lib.h> (which brings only the minimum
set of symbols) and link only a minimalistic library module, while the programs
in need of the full power of the new logger include <ucw/log.h> and link with
all log-* modules.
I have also started renaming `ls_*' to `log_*', but so far only at a couple
of places.
(Beware, most parts of the trees are currently left in an uncompilable
state. Use `make obj/ucw/log-t' for a working test program.)