8000 Fix crash if exception thrown during daemon startup by gerboland · Pull Request #487 · canonical/multipass · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix crash if exception thrown during daemon startup #487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/multipass/logging/multiplexing_logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ namespace logging
class MultiplexingLogger : public Logger
{
public:
explicit MultiplexingLogger(UPtr system_logger);
void log(Level level, CString category, CString message) const override;
void add_logger(const Logger* logger);
void remove_logger(const Logger* logger);

private:
UPtr system_logger;
mutable std::shared_timed_mutex mutex;
std::vector<const Logger*> loggers;
};
Expand Down
5 changes: 2 additions & 3 deletions src/daemon/daemon_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ std::unique_ptr<const mp::DaemonConfig> mp::DaemonConfigBuilder::build()
if (logger == nullptr)
logger = std::make_unique<mpl::StandardLogger>(verbosity_level);

auto multiplexing_logger = std::make_shared<mpl::MultiplexingLogger>();
multiplexing_logger->add_logger(logger.get());
auto multiplexing_logger = std::make_shared<mpl::MultiplexingLogger>(std::move(logger));
mpl::set_logger(multiplexing_logger);

if (cache_directory.isEmpty())
Expand Down Expand Up @@ -113,6 +112,6 @@ std::unique_ptr<const mp::DaemonConfig> mp::DaemonConfigBuilder::build()
return std::unique_ptr<const DaemonConfig>(
new DaemonConfig{std::move(url_downloader), std::move(factory), std::move(image_hosts), std::move(vault),
std::move(name_generator), std::move(ssh_key_provider), std::move(cert_provider),
std::move(client_cert_store), std::move(logger), multiplexing_logger, cache_directory,
std::move(client_cert_store), multiplexing_logger, cache_directory,
data_directory, server_address, ssh_username, connection_type, image_refresh_timer});
}
1 change: 0 additions & 1 deletion src/daemon/daemon_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ struct DaemonConfig
const std::unique_ptr<SSHKeyProvider> ssh_key_provider;
const std::unique_ptr<CertProvider> cert_provider;
const std::unique_ptr<CertStore> client_cert_store;
const std::unique_ptr<logging::Logger> system_logger;
const std::shared_ptr<logging::MultiplexingLogger> logger;
const multipass::Path cache_directory;
const multipass::Path data_directory;
Expand Down
8 changes: 7 additions & 1 deletion src/logging/multiplexing_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@

namespace mpl = multipass::logging;

multipass::logging::MultiplexingLogger::MultiplexingLogger(UPtr system_logger)
: system_logger{std::move(system_logger)}
{
}

void mpl::MultiplexingLogger::log(mpl::Level level, CString category, CString message) const
{
std::shared_lock<decltype(mutex)> lock{mutex};
system_logger->log(level, category, message);
for (auto logger : loggers)
logger->log(level, category, message);
}
Expand All @@ -38,4 +44,4 @@ void mpl::MultiplexingLogger::remove_logger(const Logger* logger)
{
std::lock_guard<decltype(mutex)> lock{mutex};
loggers.erase(std::remove(loggers.begin(), loggers.end(), logger), loggers.end());
}
}
0