mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-09-03 23:45:27 +00:00
[#3506] Final improvements
This commit is contained in:
3
changelog_unreleased/3506-unix-control-socket
Normal file
3
changelog_unreleased/3506-unix-control-socket
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[func] fdupont
|
||||||
|
Reorganized UNIX control socket code.
|
||||||
|
(Gitlab #3506)
|
@@ -573,8 +573,8 @@ UnixCommandMgrImpl::openCommandSocket(const isc::data::ConstElementPtr& socket_i
|
|||||||
|
|
||||||
// First let's open lock file.
|
// First let's open lock file.
|
||||||
std::string lock_name = getLockName();
|
std::string lock_name = getLockName();
|
||||||
int new_lock_fd = open(lock_name.c_str(), O_RDONLY | O_CREAT, 0600);
|
lock_fd_ = open(lock_name.c_str(), O_RDONLY | O_CREAT, 0600);
|
||||||
if (new_lock_fd == -1) {
|
if (lock_fd_ == -1) {
|
||||||
std::string errmsg = strerror(errno);
|
std::string errmsg = strerror(errno);
|
||||||
isc_throw(SocketError, "cannot create socket lockfile, "
|
isc_throw(SocketError, "cannot create socket lockfile, "
|
||||||
<< lock_name << ", : " << errmsg);
|
<< lock_name << ", : " << errmsg);
|
||||||
@@ -582,10 +582,11 @@ UnixCommandMgrImpl::openCommandSocket(const isc::data::ConstElementPtr& socket_i
|
|||||||
|
|
||||||
// Try to acquire lock. If we can't somebody else is actively
|
// Try to acquire lock. If we can't somebody else is actively
|
||||||
// using it.
|
// using it.
|
||||||
int ret = flock(new_lock_fd, LOCK_EX | LOCK_NB);
|
int ret = flock(lock_fd_, LOCK_EX | LOCK_NB);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
std::string errmsg = strerror(errno);
|
std::string errmsg = strerror(errno);
|
||||||
close(new_lock_fd);
|
close(lock_fd_);
|
||||||
|
lock_fd_ = -1;
|
||||||
isc_throw(SocketError, "cannot lock socket lockfile, "
|
isc_throw(SocketError, "cannot lock socket lockfile, "
|
||||||
<< lock_name << ", : " << errmsg);
|
<< lock_name << ", : " << errmsg);
|
||||||
}
|
}
|
||||||
@@ -597,12 +598,6 @@ UnixCommandMgrImpl::openCommandSocket(const isc::data::ConstElementPtr& socket_i
|
|||||||
LOG_INFO(command_logger, COMMAND_ACCEPTOR_START)
|
LOG_INFO(command_logger, COMMAND_ACCEPTOR_START)
|
||||||
.arg(socket_name_);
|
.arg(socket_name_);
|
||||||
|
|
||||||
// Close previous lock to avoid file descriptor leak.
|
|
||||||
if (lock_fd_ != -1) {
|
|
||||||
close(lock_fd_);
|
|
||||||
}
|
|
||||||
lock_fd_ = new_lock_fd;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Start asynchronous acceptor service.
|
// Start asynchronous acceptor service.
|
||||||
acceptor_.reset(new UnixDomainSocketAcceptor(io_service_));
|
acceptor_.reset(new UnixDomainSocketAcceptor(io_service_));
|
||||||
@@ -639,6 +634,10 @@ UnixCommandMgrImpl::closeCommandSocket() {
|
|||||||
// the server. This connection will be held until the UnixCommandMgr
|
// the server. This connection will be held until the UnixCommandMgr
|
||||||
// responds to such request.
|
// responds to such request.
|
||||||
connection_pool_.stopAll();
|
connection_pool_.stopAll();
|
||||||
|
if (lock_fd_ != -1) {
|
||||||
|
close(lock_fd_);
|
||||||
|
lock_fd_ = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Reference in New Issue
Block a user