@@ -573,19 +573,20 @@ UnixCommandMgrImpl::openCommandSocket(const isc::data::ConstElementPtr& socket_i
573
573
574
574
// First let's open lock file.
575
575
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 ) {
578
578
std::string errmsg = strerror (errno);
579
579
isc_throw (SocketError, " cannot create socket lockfile, "
580
580
<< lock_name << " , : " << errmsg);
581
581
}
582
582
583
583
// Try to acquire lock. If we can't somebody else is actively
584
584
// using it.
585
- int ret = flock (new_lock_fd , LOCK_EX | LOCK_NB);
585
+ int ret = flock (lock_fd_ , LOCK_EX | LOCK_NB);
586
586
if (ret != 0 ) {
587
587
std::string errmsg = strerror (errno);
588
- close (new_lock_fd);
588
+ close (lock_fd_);
589
+ lock_fd_ = -1 ;
589
590
isc_throw (SocketError, " cannot lock socket lockfile, "
590
591
<< lock_name << " , : " << errmsg);
591
592
}
@@ -597,12 +598,6 @@ UnixCommandMgrImpl::openCommandSocket(const isc::data::ConstElementPtr& socket_i
597
598
LOG_INFO (command_logger, COMMAND_ACCEPTOR_START)
598
599
.arg (socket_name_);
599
600
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
-
606
601
try {
607
602
// Start asynchronous acceptor service.
608
603
acceptor_.reset (new UnixDomainSocketAcceptor (io_service_));
@@ -639,6 +634,10 @@ UnixCommandMgrImpl::closeCommandSocket() {
639
634
// the server. This connection will be held until the UnixCommandMgr
640
635
// responds to such request.
641
636
connection_pool_.stopAll ();
637
+ if (lock_fd_ != -1 ) {
638
+ close (lock_fd_);
639
+ lock_fd_ = -1 ;
640
+ }
642
641
}
643
642
644
643
void
0 commit comments