Skip to content

Commit b8f70fb

Browse files
committed
[#3506] Final improvements
1 parent 9fda4a5 commit b8f70fb

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[func] fdupont
2+
Reorganized UNIX control socket code.
3+
(Gitlab #3506)

src/lib/config/unix_command_mgr.cc

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -573,19 +573,20 @@ UnixCommandMgrImpl::openCommandSocket(const isc::data::ConstElementPtr& socket_i
573573

574574
// First let's open lock file.
575575
std::string lock_name = getLockName();
576-
int new_lock_fd = open(lock_name.c_str(), O_RDONLY | O_CREAT, 0600);
577-
if (new_lock_fd == -1) {
576+
lock_fd_ = open(lock_name.c_str(), O_RDONLY | O_CREAT, 0600);
577+
if (lock_fd_ == -1) {
578578
std::string errmsg = strerror(errno);
579579
isc_throw(SocketError, "cannot create socket lockfile, "
580580
<< lock_name << ", : " << errmsg);
581581
}
582582

583583
// Try to acquire lock. If we can't somebody else is actively
584584
// using it.
585-
int ret = flock(new_lock_fd, LOCK_EX | LOCK_NB);
585+
int ret = flock(lock_fd_, LOCK_EX | LOCK_NB);
586586
if (ret != 0) {
587587
std::string errmsg = strerror(errno);
588-
close(new_lock_fd);
588+
close(lock_fd_);
589+
lock_fd_ = -1;
589590
isc_throw(SocketError, "cannot lock socket lockfile, "
590591
<< lock_name << ", : " << errmsg);
591592
}
@@ -597,12 +598,6 @@ UnixCommandMgrImpl::openCommandSocket(const isc::data::ConstElementPtr& socket_i
597598
LOG_INFO(command_logger, COMMAND_ACCEPTOR_START)
598599
.arg(socket_name_);
599600

600-
// Close previous lock to avoid file descriptor leak.
601-
if (lock_fd_ != -1) {
602-
close(lock_fd_);
603-
}
604-
lock_fd_ = new_lock_fd;
605-
606601
try {
607602
// Start asynchronous acceptor service.
608603
acceptor_.reset(new UnixDomainSocketAcceptor(io_service_));
@@ -639,6 +634,10 @@ UnixCommandMgrImpl::closeCommandSocket() {
639634
// the server. This connection will be held until the UnixCommandMgr
640635
// responds to such request.
641636
connection_pool_.stopAll();
637+
if (lock_fd_ != -1) {
638+
close(lock_fd_);
639+
lock_fd_ = -1;
640+
}
642641
}
643642

644643
void

0 commit comments

Comments
 (0)