logging: refactor to store config inside log handler

Signed-off-by: Oleg Vasilev <oleg.vasilev@virtuozzo.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Oleg Vasilev 2023-01-30 20:59:58 +06:00 committed by Martin Kletzander
parent b155bd095f
commit 00e682741c
3 changed files with 22 additions and 30 deletions

View File

@ -145,8 +145,7 @@ virLogDaemonNew(virLogDaemonConfig *config, bool privileged)
g_clear_pointer(&srv, virObjectUnref);
if (!(logd->handler = virLogHandlerNew(privileged,
config->max_size,
config->max_backups,
config,
virLogDaemonInhibitor,
logd)))
goto error;
@ -231,8 +230,7 @@ virLogDaemonNewPostExecRestart(virJSONValue *object, bool privileged,
if (!(logd->handler = virLogHandlerNewPostExecRestart(child,
privileged,
config->max_size,
config->max_backups,
config,
virLogDaemonInhibitor,
logd)))
goto error;

View File

@ -58,8 +58,7 @@ struct _virLogHandler {
virObjectLockable parent;
bool privileged;
size_t max_size;
size_t max_backups;
virLogDaemonConfig *config;
virLogHandlerLogFile **files;
size_t nfiles;
@ -185,8 +184,7 @@ virLogHandlerDomainLogFileEvent(int watch,
virLogHandler *
virLogHandlerNew(bool privileged,
size_t max_size,
size_t max_backups,
virLogDaemonConfig *config,
virLogHandlerShutdownInhibitor inhibitor,
void *opaque)
{
@ -199,8 +197,7 @@ virLogHandlerNew(bool privileged,
return NULL;
handler->privileged = privileged;
handler->max_size = max_size;
handler->max_backups = max_backups;
handler->config = config;
handler->inhibitor = inhibitor;
handler->opaque = opaque;
@ -253,8 +250,8 @@ virLogHandlerLogFilePostExecRestart(virLogHandler *handler,
}
if ((file->file = virRotatingFileWriterNew(path,
handler->max_size,
handler->max_backups,
handler->config->max_size,
handler->config->max_backups,
false,
DEFAULT_MODE)) == NULL)
goto error;
@ -282,8 +279,7 @@ virLogHandlerLogFilePostExecRestart(virLogHandler *handler,
virLogHandler *
virLogHandlerNewPostExecRestart(virJSONValue *object,
bool privileged,
size_t max_size,
size_t max_backups,
virLogDaemonConfig *config,
virLogHandlerShutdownInhibitor inhibitor,
void *opaque)
{
@ -292,8 +288,7 @@ virLogHandlerNewPostExecRestart(virJSONValue *object,
size_t i;
if (!(handler = virLogHandlerNew(privileged,
max_size,
max_backups,
config,
inhibitor,
opaque)))
return NULL;
@ -393,8 +388,8 @@ virLogHandlerDomainOpenLogFile(virLogHandler *handler,
file->domname = g_strdup(domname);
if ((file->file = virRotatingFileWriterNew(path,
handler->max_size,
handler->max_backups,
handler->config->max_size,
handler->config->max_backups,
trunc,
DEFAULT_MODE)) == NULL)
goto error;
@ -525,7 +520,7 @@ virLogHandlerDomainReadLogFile(virLogHandler *handler,
virObjectLock(handler);
if (!(file = virRotatingFileReaderNew(path, handler->max_backups)))
if (!(file = virRotatingFileReaderNew(path, handler->config->max_backups)))
goto error;
if (virRotatingFileReaderSeek(file, inode, offset) < 0)
@ -579,8 +574,8 @@ virLogHandlerDomainAppendLogFile(virLogHandler *handler,
if (!writer) {
if (!(newwriter = virRotatingFileWriterNew(path,
handler->max_size,
handler->max_backups,
handler->config->max_size,
handler->config->max_backups,
false,
DEFAULT_MODE)))
goto cleanup;

View File

@ -22,6 +22,7 @@
#include "internal.h"
#include "virjson.h"
#include "log_daemon_config.h"
typedef struct _virLogHandler virLogHandler;
@ -30,14 +31,12 @@ typedef void (*virLogHandlerShutdownInhibitor)(bool inhibit,
void *opaque);
virLogHandler *virLogHandlerNew(bool privileged,
size_t max_size,
size_t max_backups,
virLogDaemonConfig *config,
virLogHandlerShutdownInhibitor inhibitor,
void *opaque);
virLogHandler *virLogHandlerNewPostExecRestart(virJSONValue *child,
bool privileged,
size_t max_size,
size_t max_backups,
virLogDaemonConfig *config,
virLogHandlerShutdownInhibitor inhibitor,
void *opaque);