syslog_daemon: add syslog_max_history option
This driver setting in ~/config/settings/kernel/drivers/kernel allows setting an arbitrary number of syslog files to keep around. The files are now named with a numeric suffix instead of being called "syslog.old". The old files are rotated so that syslog.1 is the newest, then syslog.2, and so on. Change-Id: I7e3d01caa34680553b161ceb27ab8c3b2eaf508c Reviewed-on: https://review.haiku-os.org/c/haiku/+/9055 Reviewed-by: waddlesplash <[email protected]> Tested-by: Commit checker robot <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
ce6f846b6f
commit
7521af58c4
@@ -52,6 +52,12 @@ load_symbols true
|
|||||||
#syslog_time_stamps true
|
#syslog_time_stamps true
|
||||||
# Include time stamps in syslog debug output, defaults to false.
|
# Include time stamps in syslog debug output, defaults to false.
|
||||||
|
|
||||||
|
#syslog_max_history 7
|
||||||
|
# Maximum number of old syslogs to keep. The files are named
|
||||||
|
# syslog.1, syslog.2, syslog.3,... with syslog.1 being the newest.
|
||||||
|
# Defaults to 1, using 0 will disable this and syslog will be recreated
|
||||||
|
# when it reaches syslog_max_size.
|
||||||
|
|
||||||
#syslog_max_size 20MB
|
#syslog_max_size 20MB
|
||||||
# Sets the maximum syslog file size, default is 512kB.
|
# Sets the maximum syslog file size, default is 512kB.
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ static char sLastMessage[1024];
|
|||||||
static thread_id sLastThread;
|
static thread_id sLastThread;
|
||||||
static int32 sRepeatCount;
|
static int32 sRepeatCount;
|
||||||
static size_t sLogMaxSize = 524288; // 512kB
|
static size_t sLogMaxSize = 524288; // 512kB
|
||||||
|
static int32 sMaxHistory = 1;
|
||||||
static bool sLogTimeStamps = false;
|
static bool sLogTimeStamps = false;
|
||||||
|
|
||||||
|
|
||||||
@@ -69,14 +70,25 @@ prepare_output()
|
|||||||
BPath syslog(base);
|
BPath syslog(base);
|
||||||
syslog.Append("syslog");
|
syslog.Append("syslog");
|
||||||
|
|
||||||
// move old file if it already exists
|
// move old files if they already exist
|
||||||
if (tooLarge) {
|
if (tooLarge) {
|
||||||
BPath oldlog(base);
|
// remove latest syslog.X and rename others with a suffix incremented by one
|
||||||
oldlog.Append("syslog.old");
|
// syslog.6 -> syslog.7, syslog.5 -> syslog.6, ...
|
||||||
|
for (int32 x = sMaxHistory; x >= 0; x--) {
|
||||||
remove(oldlog.Path());
|
BString oldlog(syslog.Path());
|
||||||
rename(syslog.Path(), oldlog.Path());
|
// no suffix on 0, just 'syslog'
|
||||||
|
if (x > 0)
|
||||||
|
oldlog << "." << x;
|
||||||
|
|
||||||
|
if (x == sMaxHistory)
|
||||||
|
remove(oldlog.String());
|
||||||
|
else {
|
||||||
|
// increment our suffix
|
||||||
|
BString rotateTo(syslog.Path());
|
||||||
|
rotateTo << "." << (x + 1);
|
||||||
|
rename(oldlog.String(), rotateTo.String());
|
||||||
|
}
|
||||||
|
}
|
||||||
// ToDo: just remove old file if space on device is tight?
|
// ToDo: just remove old file if space on device is tight?
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,8 +227,11 @@ init_syslog_output(SyslogDaemon *daemon)
|
|||||||
if (handle != NULL) {
|
if (handle != NULL) {
|
||||||
sLogTimeStamps = get_driver_boolean_parameter(handle,
|
sLogTimeStamps = get_driver_boolean_parameter(handle,
|
||||||
"syslog_time_stamps", false, false);
|
"syslog_time_stamps", false, false);
|
||||||
const char *param = get_driver_parameter(handle,
|
const char *param = get_driver_parameter(handle, "syslog_max_history", "1", "1");
|
||||||
"syslog_max_size", "0", "0");
|
sMaxHistory = strtol(param, NULL, 0);
|
||||||
|
if (sMaxHistory < 0)
|
||||||
|
sMaxHistory = 0;
|
||||||
|
param = get_driver_parameter(handle, "syslog_max_size", "0", "0");
|
||||||
int maxSize = strtol(param, NULL, 0);
|
int maxSize = strtol(param, NULL, 0);
|
||||||
if (strchr(param, 'k') || strchr(param, 'K'))
|
if (strchr(param, 'k') || strchr(param, 'K'))
|
||||||
maxSize *= 1024;
|
maxSize *= 1024;
|
||||||
|
|||||||
Reference in New Issue
Block a user