charon-systemd: Register journal logger as custom logger
This way we get early log messages during plugin loading (including integrity check results). Instead of the fallback we could also remove the `customlog` namespace, which was added to avoid conflicts with other settings/sections.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2006-2012 Tobias Brunner
|
* Copyright (C) 2006-2018 Tobias Brunner
|
||||||
* Copyright (C) 2005-2014 Martin Willi
|
* Copyright (C) 2005-2014 Martin Willi
|
||||||
* Copyright (C) 2006 Daniel Roethlisberger
|
* Copyright (C) 2006 Daniel Roethlisberger
|
||||||
* Copyright (C) 2005 Jan Hutter
|
* Copyright (C) 2005 Jan Hutter
|
||||||
@@ -79,9 +79,9 @@ typedef struct journal_logger_t journal_logger_t;
|
|||||||
struct journal_logger_t {
|
struct journal_logger_t {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implements logger_t
|
* Public interface
|
||||||
*/
|
*/
|
||||||
logger_t logger;
|
custom_logger_t public;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Configured loglevels
|
* Configured loglevels
|
||||||
@@ -171,66 +171,37 @@ METHOD(logger_t, get_level, level_t,
|
|||||||
return level;
|
return level;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(custom_logger_t, set_level, void,
|
||||||
* Reload journal logger configuration
|
journal_logger_t *this, debug_t group, level_t level)
|
||||||
*/
|
|
||||||
CALLBACK(journal_reload, bool,
|
|
||||||
journal_logger_t **journal)
|
|
||||||
{
|
{
|
||||||
journal_logger_t *this = *journal;
|
|
||||||
debug_t group;
|
|
||||||
level_t def;
|
|
||||||
|
|
||||||
def = lib->settings->get_int(lib->settings, "%s.journal.default", 1, lib->ns);
|
|
||||||
|
|
||||||
this->lock->write_lock(this->lock);
|
this->lock->write_lock(this->lock);
|
||||||
for (group = 0; group < DBG_MAX; group++)
|
this->levels[group] = level;
|
||||||
{
|
|
||||||
this->levels[group] =
|
|
||||||
lib->settings->get_int(lib->settings,
|
|
||||||
"%s.journal.%N", def, lib->ns, debug_lower_names, group);
|
|
||||||
}
|
|
||||||
this->lock->unlock(this->lock);
|
this->lock->unlock(this->lock);
|
||||||
|
|
||||||
charon->bus->add_logger(charon->bus, &this->logger);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(custom_logger_t, logger_destroy, void,
|
||||||
* Initialize/deinitialize journal logger
|
journal_logger_t *this)
|
||||||
*/
|
{
|
||||||
static bool journal_register(void *plugin, plugin_feature_t *feature,
|
this->lock->destroy(this->lock);
|
||||||
bool reg, journal_logger_t **logger)
|
free(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
static custom_logger_t *journal_logger_create(const char *name)
|
||||||
{
|
{
|
||||||
journal_logger_t *this;
|
journal_logger_t *this;
|
||||||
|
|
||||||
if (reg)
|
INIT(this,
|
||||||
{
|
.public = {
|
||||||
INIT(this,
|
|
||||||
.logger = {
|
.logger = {
|
||||||
.vlog = _vlog,
|
.vlog = _vlog,
|
||||||
.get_level = _get_level,
|
.get_level = _get_level,
|
||||||
},
|
},
|
||||||
.lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
|
.set_level = _set_level,
|
||||||
);
|
.destroy = _logger_destroy,
|
||||||
|
},
|
||||||
journal_reload(&this);
|
.lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
|
||||||
|
);
|
||||||
*logger = this;
|
return &this->public;
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
this = *logger;
|
|
||||||
|
|
||||||
charon->bus->remove_logger(charon->bus, &this->logger);
|
|
||||||
|
|
||||||
this->lock->destroy(this->lock);
|
|
||||||
free(this);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -327,19 +298,6 @@ static void segv_handler(int signal)
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The journal logger instance
|
|
||||||
*/
|
|
||||||
static journal_logger_t *journal;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Journal static features
|
|
||||||
*/
|
|
||||||
static plugin_feature_t features[] = {
|
|
||||||
PLUGIN_CALLBACK((plugin_feature_callback_t)journal_register, &journal),
|
|
||||||
PLUGIN_PROVIDE(CUSTOM, "systemd-journal"),
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add namespace alias
|
* Add namespace alias
|
||||||
*/
|
*/
|
||||||
@@ -349,6 +307,14 @@ static void __attribute__ ((constructor))register_namespace()
|
|||||||
library_add_namespace("charon");
|
library_add_namespace("charon");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register journal logger
|
||||||
|
*/
|
||||||
|
static void __attribute__ ((constructor))register_logger()
|
||||||
|
{
|
||||||
|
register_custom_logger("journal", journal_logger_create);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main function, starts the daemon.
|
* Main function, starts the daemon.
|
||||||
*/
|
*/
|
||||||
@@ -390,10 +356,15 @@ int main(int argc, char *argv[])
|
|||||||
sd_notifyf(0, "STATUS=unknown uid/gid");
|
sd_notifyf(0, "STATUS=unknown uid/gid");
|
||||||
return SS_RC_INITIALIZATION_FAILED;
|
return SS_RC_INITIALIZATION_FAILED;
|
||||||
}
|
}
|
||||||
charon->load_loggers(charon);
|
/* we registered the journal logger as custom logger, which gets its
|
||||||
|
* settings from <ns>.customlog.journal, let it fallback to <ns>.journal */
|
||||||
|
lib->settings->add_fallback(lib->settings, "%s.customlog.journal",
|
||||||
|
"%s.journal", lib->ns);
|
||||||
|
/* load the journal logger by default */
|
||||||
|
lib->settings->set_default_str(lib->settings, "%s.journal.default", "1",
|
||||||
|
lib->ns);
|
||||||
|
|
||||||
lib->plugins->add_static_features(lib->plugins, lib->ns, features,
|
charon->load_loggers(charon);
|
||||||
countof(features), TRUE, journal_reload, &journal);
|
|
||||||
|
|
||||||
if (!charon->initialize(charon,
|
if (!charon->initialize(charon,
|
||||||
lib->settings->get_str(lib->settings, "%s.load", PLUGINS, lib->ns)))
|
lib->settings->get_str(lib->settings, "%s.load", PLUGINS, lib->ns)))
|
||||||
|
|||||||
Reference in New Issue
Block a user