Fixed some bugs concerning switching the log when it's getting too large:
never closed old file - with BeOS, it would only get deleted if the server would be restarted... good for disk fragmentation etc. Also, renaming failed if there already was a syslog.old file - it's now removed first. Furthermore, the first time the syslog was opened, its size was not checked, the first output always went through. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5346 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -41,7 +41,7 @@ prepare_output()
|
||||
bool needNew = true;
|
||||
bool tooLarge = false;
|
||||
|
||||
if (sLog > 0) {
|
||||
if (sLog >= 0) {
|
||||
// check file size
|
||||
struct stat stat;
|
||||
if (fstat(sLog, &stat) == 0) {
|
||||
@@ -53,6 +53,10 @@ prepare_output()
|
||||
}
|
||||
|
||||
if (needNew) {
|
||||
// close old file; it'll be (re)moved soon
|
||||
if (sLog >= 0)
|
||||
close(sLog);
|
||||
|
||||
// get path
|
||||
BPath base;
|
||||
find_directory(/*B_COMMON_LOG_DIRECTORY*/B_COMMON_TEMP_DIRECTORY, &base);
|
||||
@@ -63,14 +67,23 @@ prepare_output()
|
||||
|
||||
// move old file if it already exists
|
||||
if (tooLarge) {
|
||||
base.Append("syslog.old");
|
||||
rename(syslog.Path(), base.Path());
|
||||
BPath oldlog(base);
|
||||
oldlog.Append("syslog.old");
|
||||
|
||||
// ToDo: remove old file if space on device is tight?
|
||||
remove(oldlog.Path());
|
||||
rename(syslog.Path(), oldlog.Path());
|
||||
|
||||
// ToDo: just remove old file if space on device is tight?
|
||||
}
|
||||
|
||||
bool haveSyslog = sLog >= 0;
|
||||
|
||||
// open file
|
||||
sLog = open(syslog.Path(), O_APPEND | O_CREAT | O_WRONLY, 644);
|
||||
if (!haveSyslog && sLog >=0) {
|
||||
// first time open, check file size again
|
||||
prepare_output();
|
||||
}
|
||||
}
|
||||
|
||||
return sLog >= 0 ? B_OK : B_ERROR;
|
||||
|
||||
Reference in New Issue
Block a user