From 8afbc3212d47323cf38f9f8195d9e6b6d8ff3d21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 13 Nov 2003 03:33:24 +0000 Subject: [PATCH] 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 --- src/servers/syslog_daemon/syslog_output.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/servers/syslog_daemon/syslog_output.cpp b/src/servers/syslog_daemon/syslog_output.cpp index 91b4373ebf..86c4b39520 100644 --- a/src/servers/syslog_daemon/syslog_output.cpp +++ b/src/servers/syslog_daemon/syslog_output.cpp @@ -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;