Commit graph

64 commits

Author SHA1 Message Date
Miroslav Lichvar
b328c8c348 logging: support context-specific severity
Allow messages to have severity set to INFO or DEBUG depending on the
context in which they are made to allow logging important changes made
from chronyc or sourcefile, but not spam the system log if those changes
are normally expected (e.g. specified in the config).
2022-11-16 16:57:49 +01:00
Miroslav Lichvar
3916c3366b update copyright years 2020-09-16 12:09:52 +02:00
Miroslav Lichvar
51d77d6cfc logging: extend functionality
Add a function to get the current minimum severity and a function to set
a global prefix for debug messages in order to identify messages from
helpers.
2020-07-16 13:24:59 +02:00
Miroslav Lichvar
c9f03fb222 logging: handle too many file logs
Don't rely on an assert to catch insufficient maximum number of file
logs (e.g. after introducing a new file log).
2020-06-25 12:43:25 +02:00
Miroslav Lichvar
60049f1551 conf: replace empty strings with NULL
Avoid mixing empty strings with NULLs in configuration strings to make
the handling of default or disabled values consistent.
2020-05-21 12:42:18 +02:00
Miroslav Lichvar
794cbfbbb5 logging: restrict file log permissions
With the new file utility functions permissions can be restricted for
newly created files. For the log file specified by the -l option it
is better to remove the "other" permissions (0640) to make it similar
to the system log.
2020-02-18 16:01:25 +01:00
Miroslav Lichvar
d05e9fb2ec logging: enable line buffering on stderr
This should avoid mixed lines on console or in file log when multiple
processes will be logging messages at the same time.
2019-12-02 18:06:15 +01:00
Miroslav Lichvar
c7223f4c8f logging: disable all debug messages in non-debug build
For consistency, don't print debug messages that are compiled in due to
using the LOG macro instead of DEBUG_LOG.
2019-11-19 14:59:21 +01:00
Miroslav Lichvar
e18903a6b5 switch to new util file functions
Replace all fopen(), rename(), and unlink() calls with the new util
functions.
2019-10-24 12:48:45 +02:00
Miroslav Lichvar
2fc8edacb8 use PATH_MAX
Include <limits.h> and use the PATH_MAX macro to define the length of
buffers containing paths to make it constistent. (It's not supposed to
fit all possible paths.)
2019-10-24 11:03:47 +02:00
Miroslav Lichvar
903fa247f8 logging: include <syslog.h>
Move the inclusion of <syslog.h> from sysincl.h to logging.c to avoid
accidentally using the LOG_* constants from the header.
2019-10-24 11:03:47 +02:00
Miroslav Lichvar
96771d6857 logging: make banner printing safer
Don't rely on the buffer filled with '=' characters to be always at
least as long as the log-specific banner string.
2019-10-24 11:03:41 +02:00
Miroslav Lichvar
f4c6a00b2a logging: call exit() in LOG_Message()
Call exit() in LOG_Message() after printing a fatal message to allow the
LOG macro or LOG_Message() to be used directly instead of the LOG_FATAL
macro.
2019-10-10 18:05:00 +02:00
Miroslav Lichvar
1227873b88 logging: refactor enabling of debug messages
Reorder the LOGS_Severity enum in order of severity and change the code
to not log/print messages with severity below the specified minimum
instead of having a separate debug level.
2019-07-04 17:38:13 +02:00
Miroslav Lichvar
5dc86c236b update copyright years 2018-09-12 11:38:10 +02:00
Miroslav Lichvar
eb8c9ad601 logging: allow reopening stderr
LOG_OpenFileLog(NULL) can be now used to reopen stderr.
2018-08-28 18:18:07 +02:00
Miroslav Lichvar
6847536669 logging: close previous file log after opening new one
Currently, the log is always opened only once, but that will change with
tests temporarily suspending logging.
2018-08-28 15:42:38 +02:00
Miroslav Lichvar
63fe34e890 check values returned by gmtime() and localtime()
While it is not expected to happen with any time that can be represented
by the system clock, the functions are allowed to return NULL. Check the
pointer before dereferencing.

This issue was found in a Frama-C analysis.
2018-06-20 16:45:14 +02:00
Miroslav Lichvar
7b98443a13 logging: don't write fatal messages to invalid descriptor
If opening the log file specified with the -l option failed (after
closing all descriptors), the error message is written to an invalid
descriptor as no log file or syslog is opened yet. Fix the code to track
when the output is usable.
2018-02-26 13:42:04 +01:00
Miroslav Lichvar
d70df3daab logging: enable line buffering of file log
The file log specified with the -l option should have the messages as
soon as they are produced.
2017-08-08 15:37:59 +02:00
Miroslav Lichvar
6cbeb107db logging: allow logging to file instead of syslog 2017-05-26 13:33:53 +02:00
Miroslav Lichvar
f282856c72 logging: remove facility parameter
It was never used for anything and messages in debug output already
include filenames, which can be easily grepped if there is a need
to see log messages only from a particular file.
2017-03-10 16:51:03 +01:00
Miroslav Lichvar
c08e7e716d use correct facility in LOG messages 2016-09-07 11:16:01 +02:00
Miroslav Lichvar
fb5d4f1da4 conf: disable dumpdir and logdir by default
Use empty string instead of "." (which is normally the root directory)
as the default value of dumpdir and logdir to indicate they are not
specified. Print warnings in syslog when trying to log or dump
measurements without dumpdir or logdir.
2016-09-07 11:16:01 +02:00
Miroslav Lichvar
7b2430fc3c logging: don't save debugging arguments when debug is disabled
Don't save the facility number, line number, function name and filename
in the compiled binary unless the debugging support is enabled.
2015-09-24 18:32:23 +02:00
Miroslav Lichvar
4bc6950632 drop WINNT-specific code
This was never really supported and it would probably require a lot of
work to get a usable chronyd in Cygwin. Remove all WINNT-specific code.
2015-09-17 15:52:49 +02:00
Miroslav Lichvar
6d42dd8603 conf: create directories before dropping root
Create logdir and dumpdir before dropping root. Set their uid/gid to the
user chronyd will switch to. This allows chronyd to create the
directories in a directory where the user won't have write permissions
(e.g. /var/lib).
2015-08-12 14:45:20 +02:00
Miroslav Lichvar
236576c124 util: add mode, uid, gid parameters to UTI_CreateDirAndParents() 2015-08-10 14:56:17 +02:00
Miroslav Lichvar
92706b158e move mkdirpp code to util.c 2015-08-05 18:07:39 +02:00
Miroslav Lichvar
c404786b92 logging: remove warning on missing debug messages
The state of the DEBUG feature is now printed with chronyd version.
2014-09-25 11:12:23 +02:00
Miroslav Lichvar
51a2b436f4 logging: move exit call from LOG_Message to LOG_FATAL 2014-08-05 15:15:15 +02:00
Miroslav Lichvar
cb74f3e7ad Update copyright years 2014-06-05 18:06:56 +02:00
Miroslav Lichvar
a646cf7923 logging: convert rate limited messages to debug messages 2014-06-04 12:26:27 +02:00
Miroslav Lichvar
0dea8d97f4 logging: move check of enabled debugging to DEBUG_LOG macro
This avoids unnecessary calls to the logging function when debugging
messages are not logged. The cost is a slight increase in the size of
the binary (when compiled with debug messages).
2014-06-04 12:12:04 +02:00
Miroslav Lichvar
0baf00e1c0 logging: print warning message when not compiled with debug support 2014-04-09 12:09:25 +02:00
Miroslav Lichvar
788e7fcd89 logging: set debug level instead of on/off
Prefix messages written to terminal with filename, line and function
name only with debug level 2 and higher.
2014-04-09 12:09:23 +02:00
Miroslav Lichvar
7c45b1d2a3 logging: update format of messages written to terminal
Move the time stamp to start of the line and print full date in ISO 8601
format.
2014-04-09 12:08:59 +02:00
Miroslav Lichvar
ed0ac6e3f6 Write fatal messages also to stderr when started with -n 2013-11-28 18:17:50 +01:00
Miroslav Lichvar
6cc9c4940c Don't try to write to parent logging fd when closed 2013-11-28 18:11:37 +01:00
Miroslav Lichvar
4bbc5520b8 Add support for debug messages
Add new DEBUG_LOG macro for debug messages. The messages are enabled
when compiled with --enable-debug and they are printed when the -d
option is used twice.
2013-11-27 14:35:38 +01:00
Miroslav Lichvar
cd7bfa2510 Refactor logging
- merge LOG_Line_Function, LOG_Fatal_Function and LOG_Position
- use C99 variadic macros for LOG and LOG_FATAL
2013-11-26 18:40:43 +01:00
Miroslav Lichvar
6ba764b5be Don't call finalise functions on fatal error
Also, return with non-zero exit code.
2013-06-19 12:28:00 +02:00
Miroslav Lichvar
359d444343 Remove unncessary return statements 2013-05-21 15:08:34 +02:00
Miroslav Lichvar
0c738d84af Update copyright years 2012-02-28 13:11:56 +01:00
Miroslav Lichvar
2a305d8e16 Fix compiler warnings 2012-02-27 16:08:21 +01:00
Miroslav Lichvar
1d2a0856b4 Wait in foreground process until daemon is fully initialized
Exit when all sockets are ready and initstepslew command and rtc step
are completed. Also, in case of a fatal error, print the error message
and exit with a non-zero status.
2011-08-26 18:31:26 +02:00
Miroslav Lichvar
411f4da340 Fix creating logdir 2011-08-11 14:15:15 +02:00
Miroslav Lichvar
da2c8d9076 Use config.h 2011-05-24 18:07:06 +02:00
Miroslav Lichvar
cb9055072d Make starting log even in debug mode 2011-02-14 18:21:38 +01:00
Miroslav Lichvar
e8c5d15690 Remove CVS headers 2011-01-28 12:56:09 +01:00