"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/lib/config/command_mgr.cc" between
kea-1.6.1.tar.gz and kea-1.6.2.tar.gz

About: Kea is a modern DHCPv4 & DHCPv6 Server (potential successor of ISC DHCP).

command_mgr.cc  (kea-1.6.1):command_mgr.cc  (kea-1.6.2)
// Copyright (C) 2015-2018 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2015-2020 Internet Systems Consortium, Inc. ("ISC")
// //
// This Source Code Form is subject to the terms of the Mozilla Public // This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this // License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <config.h> #include <config.h>
#include <asiolink/asio_wrapper.h> #include <asiolink/asio_wrapper.h>
#include <asiolink/interval_timer.h> #include <asiolink/interval_timer.h>
#include <asiolink/io_service.h> #include <asiolink/io_service.h>
skipping to change at line 27 skipping to change at line 27
#include <cc/command_interpreter.h> #include <cc/command_interpreter.h>
#include <cc/json_feed.h> #include <cc/json_feed.h>
#include <dhcp/iface_mgr.h> #include <dhcp/iface_mgr.h>
#include <config/config_log.h> #include <config/config_log.h>
#include <config/timeouts.h> #include <config/timeouts.h>
#include <util/watch_socket.h> #include <util/watch_socket.h>
#include <boost/bind.hpp> #include <boost/bind.hpp>
#include <boost/enable_shared_from_this.hpp> #include <boost/enable_shared_from_this.hpp>
#include <array> #include <array>
#include <unistd.h> #include <unistd.h>
#include <sys/file.h>
using namespace isc; using namespace isc;
using namespace isc::asiolink; using namespace isc::asiolink;
using namespace isc::config; using namespace isc::config;
using namespace isc::data; using namespace isc::data;
namespace { namespace {
/// @brief Maximum size of the data chunk sent/received over the socket. /// @brief Maximum size of the data chunk sent/received over the socket.
const size_t BUF_SIZE = 32768; const size_t BUF_SIZE = 32768;
skipping to change at line 488 skipping to change at line 489
/// @brief Opens acceptor service allowing the control clients to connect. /// @brief Opens acceptor service allowing the control clients to connect.
/// ///
/// @param socket_info Configuration information for the control socket. /// @param socket_info Configuration information for the control socket.
/// @throw BadSocketInfo When socket configuration is invalid. /// @throw BadSocketInfo When socket configuration is invalid.
/// @throw SocketError When socket operation fails. /// @throw SocketError When socket operation fails.
void openCommandSocket(const isc::data::ConstElementPtr& socket_info); void openCommandSocket(const isc::data::ConstElementPtr& socket_info);
/// @brief Asynchronously accepts next connection. /// @brief Asynchronously accepts next connection.
void doAccept(); void doAccept();
/// @brief Returns the lock file name
std::string getLockName() {
return (std::string(socket_name_ + ".lock"));
}
/// @brief Pointer to the IO service used by the server process for running /// @brief Pointer to the IO service used by the server process for running
/// asynchronous tasks. /// asynchronous tasks.
IOServicePtr io_service_; IOServicePtr io_service_;
/// @brief Pointer to the acceptor service. /// @brief Pointer to the acceptor service.
boost::shared_ptr<UnixDomainSocketAcceptor> acceptor_; boost::shared_ptr<UnixDomainSocketAcceptor> acceptor_;
/// @brief Pointer to the socket into which the new connection is accepted. /// @brief Pointer to the socket into which the new connection is accepted.
boost::shared_ptr<UnixDomainSocket> socket_; boost::shared_ptr<UnixDomainSocket> socket_;
skipping to change at line 542 skipping to change at line 548
if (!name) { if (!name) {
isc_throw(BadSocketInfo, "Mandatory 'socket-name' parameter missing"); isc_throw(BadSocketInfo, "Mandatory 'socket-name' parameter missing");
} }
if (name->getType() != Element::string) { if (name->getType() != Element::string) {
isc_throw(BadSocketInfo, "'socket-name' parameter expected to be a strin g"); isc_throw(BadSocketInfo, "'socket-name' parameter expected to be a strin g");
} }
socket_name_ = name->stringValue(); socket_name_ = name->stringValue();
// First let's open lock file.
std::string lock_name = getLockName();
int lock_fd = open(lock_name.c_str(), O_RDONLY | O_CREAT, 0600);
if (lock_fd == -1) {
std::string errmsg = strerror(errno);
isc_throw(SocketError, "cannot create socket lockfile, "
<< lock_name << ", : " << errmsg);
}
// Try to acquire lock. If we can't somebody else is actively
// using it.
int ret = flock(lock_fd, LOCK_EX | LOCK_NB);
if (ret != 0) {
std::string errmsg = strerror(errno);
isc_throw(SocketError, "cannot lock socket lockfile, "
<< lock_name << ", : " << errmsg);
}
// We have the lock, so let's remove the pre-existing socket
// file if it exists.
static_cast<void>(::remove(socket_name_.c_str()));
LOG_INFO(command_logger, COMMAND_ACCEPTOR_START) LOG_INFO(command_logger, COMMAND_ACCEPTOR_START)
.arg(socket_name_); .arg(socket_name_);
try { try {
// Start asynchronous acceptor service. // Start asynchronous acceptor service.
acceptor_.reset(new UnixDomainSocketAcceptor(*io_service_)); acceptor_.reset(new UnixDomainSocketAcceptor(*io_service_));
UnixDomainSocketEndpoint endpoint(socket_name_); UnixDomainSocketEndpoint endpoint(socket_name_);
acceptor_->open(endpoint); acceptor_->open(endpoint);
acceptor_->bind(endpoint); acceptor_->bind(endpoint);
acceptor_->listen(); acceptor_->listen();
// Install this socket in Interface Manager. // Install this socket in Interface Manager.
isc::dhcp::IfaceMgr::instance().addExternalSocket(acceptor_->getNative() , 0); isc::dhcp::IfaceMgr::instance().addExternalSocket(acceptor_->getNative() , 0);
doAccept(); doAccept();
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
isc_throw(SocketError, ex.what()); isc_throw(SocketError, ex.what());
} }
} }
skipping to change at line 602 skipping to change at line 629
CommandMgr::openCommandSocket(const isc::data::ConstElementPtr& socket_info) { CommandMgr::openCommandSocket(const isc::data::ConstElementPtr& socket_info) {
impl_->openCommandSocket(socket_info); impl_->openCommandSocket(socket_info);
} }
void CommandMgr::closeCommandSocket() { void CommandMgr::closeCommandSocket() {
// Close acceptor if the acceptor is open. // Close acceptor if the acceptor is open.
if (impl_->acceptor_ && impl_->acceptor_->isOpen()) { if (impl_->acceptor_ && impl_->acceptor_->isOpen()) {
isc::dhcp::IfaceMgr::instance().deleteExternalSocket(impl_->acceptor_->g etNative()); isc::dhcp::IfaceMgr::instance().deleteExternalSocket(impl_->acceptor_->g etNative());
impl_->acceptor_->close(); impl_->acceptor_->close();
static_cast<void>(::remove(impl_->socket_name_.c_str())); static_cast<void>(::remove(impl_->socket_name_.c_str()));
static_cast<void>(::remove(impl_->getLockName().c_str()));
} }
// Stop all connections which can be closed. The only connection that won't // Stop all connections which can be closed. The only connection that won't
// be closed is the one over which we have received a request to reconfigure // be closed is the one over which we have received a request to reconfigure
// the server. This connection will be held until the CommandMgr responds to // the server. This connection will be held until the CommandMgr responds to
// such request. // such request.
impl_->connection_pool_.stopAll(); impl_->connection_pool_.stopAll();
} }
int int
 End of changes. 6 change blocks. 
2 lines changed or deleted 30 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)