pathut pid file: make sure we dont close the same fd twice. Might fix the mysterious "error 9 on netlink descriptor" crash?
This commit is contained in:
parent
423dee3cb0
commit
747a04ac50
@ -813,10 +813,7 @@ out:
|
|||||||
// alone.
|
// alone.
|
||||||
Pidfile::~Pidfile()
|
Pidfile::~Pidfile()
|
||||||
{
|
{
|
||||||
if (m_fd >= 0) {
|
this->close();
|
||||||
::close(m_fd);
|
|
||||||
}
|
|
||||||
m_fd = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_t Pidfile::read_pid()
|
pid_t Pidfile::read_pid()
|
||||||
@ -857,7 +854,7 @@ int Pidfile::flopen()
|
|||||||
lockdata.l_whence = SEEK_SET;
|
lockdata.l_whence = SEEK_SET;
|
||||||
if (fcntl(m_fd, F_SETLK, &lockdata) != 0) {
|
if (fcntl(m_fd, F_SETLK, &lockdata) != 0) {
|
||||||
int serrno = errno;
|
int serrno = errno;
|
||||||
(void)::close(m_fd);
|
this->close()
|
||||||
errno = serrno;
|
errno = serrno;
|
||||||
m_reason = "fcntl lock failed";
|
m_reason = "fcntl lock failed";
|
||||||
return -1;
|
return -1;
|
||||||
@ -869,7 +866,7 @@ int Pidfile::flopen()
|
|||||||
int operation = LOCK_EX | LOCK_NB;
|
int operation = LOCK_EX | LOCK_NB;
|
||||||
if (flock(m_fd, operation) == -1) {
|
if (flock(m_fd, operation) == -1) {
|
||||||
int serrno = errno;
|
int serrno = errno;
|
||||||
(void)::close(m_fd);
|
this->close();
|
||||||
errno = serrno;
|
errno = serrno;
|
||||||
m_reason = "flock failed";
|
m_reason = "flock failed";
|
||||||
return -1;
|
return -1;
|
||||||
@ -880,7 +877,7 @@ int Pidfile::flopen()
|
|||||||
if (ftruncate(m_fd, 0) != 0) {
|
if (ftruncate(m_fd, 0) != 0) {
|
||||||
/* can't happen [tm] */
|
/* can't happen [tm] */
|
||||||
int serrno = errno;
|
int serrno = errno;
|
||||||
(void)::close(m_fd);
|
this->close();
|
||||||
errno = serrno;
|
errno = serrno;
|
||||||
m_reason = "ftruncate failed";
|
m_reason = "ftruncate failed";
|
||||||
return -1;
|
return -1;
|
||||||
@ -915,7 +912,12 @@ int Pidfile::write_pid()
|
|||||||
|
|
||||||
int Pidfile::close()
|
int Pidfile::close()
|
||||||
{
|
{
|
||||||
return ::close(m_fd);
|
int ret = -1;
|
||||||
|
if (m_fd >= 0) {
|
||||||
|
ret = ::close(m_fd);
|
||||||
|
m_fd = -1;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Pidfile::remove()
|
int Pidfile::remove()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user