The virtlogd daemon currently opens all files for append, but
in some cases the user may wish to discard existing data. Define
a new flag to indicate that logfiles should be truncated when
opening.
---
src/logging/log_daemon_dispatch.c | 3 ++-
src/logging/log_handler.c | 6 ++----
src/logging/log_handler.h | 2 +-
src/logging/log_manager.h | 2 ++
src/logging/log_protocol.x | 4 ++++
5 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/src/logging/log_daemon_dispatch.c b/src/logging/log_daemon_dispatch.c
index a5fa7f0..b00cee2 100644
--- a/src/logging/log_daemon_dispatch.c
+++ b/src/logging/log_daemon_dispatch.c
@@ -50,13 +50,14 @@ virLogManagerProtocolDispatchDomainOpenLogFile(virNetServerPtr server
ATTRIBUTE_
int rv = -1;
off_t offset;
ino_t inode;
+ bool trunc = args->flags &
VIR_LOG_MANAGER_PROTOCOL_DOMAIN_OPEN_LOG_FILE_TRUNCATE;
if ((fd = virLogHandlerDomainOpenLogFile(virLogDaemonGetHandler(logDaemon),
args->driver,
(unsigned char *)args->dom.uuid,
args->dom.name,
args->path,
- args->flags,
+ trunc,
&inode, &offset)) < 0)
goto cleanup;
diff --git a/src/logging/log_handler.c b/src/logging/log_handler.c
index 92cff50..4c08223 100644
--- a/src/logging/log_handler.c
+++ b/src/logging/log_handler.c
@@ -357,7 +357,7 @@ virLogHandlerDomainOpenLogFile(virLogHandlerPtr handler,
const unsigned char *domuuid,
const char *domname,
const char *path,
- unsigned int flags,
+ bool trunc,
ino_t *inode,
off_t *offset)
{
@@ -365,8 +365,6 @@ virLogHandlerDomainOpenLogFile(virLogHandlerPtr handler,
virLogHandlerLogFilePtr file = NULL;
int pipefd[2] = { -1, -1 };
- virCheckFlags(0, -1);
-
virObjectLock(handler);
handler->inhibitor(true, handler->opaque);
@@ -400,7 +398,7 @@ virLogHandlerDomainOpenLogFile(virLogHandlerPtr handler,
if ((file->file = virRotatingFileWriterNew(path,
DEFAULT_FILE_SIZE,
DEFAULT_MAX_BACKUP,
- false,
+ trunc,
DEFAULT_MODE)) == NULL)
goto error;
diff --git a/src/logging/log_handler.h b/src/logging/log_handler.h
index e61f32d..54a9cd9 100644
--- a/src/logging/log_handler.h
+++ b/src/logging/log_handler.h
@@ -48,7 +48,7 @@ int virLogHandlerDomainOpenLogFile(virLogHandlerPtr handler,
const unsigned char *domuuid,
const char *domname,
const char *path,
- unsigned int flags,
+ bool trunc,
ino_t *inode,
off_t *offset);
diff --git a/src/logging/log_manager.h b/src/logging/log_manager.h
index d3b9d29..7deaba7 100644
--- a/src/logging/log_manager.h
+++ b/src/logging/log_manager.h
@@ -26,6 +26,8 @@
# include "internal.h"
+# include "logging/log_protocol.h"
+
typedef struct _virLogManager virLogManager;
typedef virLogManager *virLogManagerPtr;
diff --git a/src/logging/log_protocol.x b/src/logging/log_protocol.x
index b0ac31b..0363c75 100644
--- a/src/logging/log_protocol.x
+++ b/src/logging/log_protocol.x
@@ -30,6 +30,10 @@ struct virLogManagerProtocolLogFilePosition {
};
typedef struct virLogManagerProtocolLogFilePosition
virLogManagerProtocolLogFilePosition;
+enum virLogManagerProtocolDomainOpenLogFileFlags {
+ VIR_LOG_MANAGER_PROTOCOL_DOMAIN_OPEN_LOG_FILE_TRUNCATE = 1
+};
+
/* Obtain a file handle suitable for writing to a
* log file for a domain
*/
--
2.5.0