mirror of https://github.com/Icinga/icinga2.git
parent
e32a149049
commit
d4cc6fb5e0
|
@ -525,7 +525,14 @@ void Application::UpdatePidFile(const String& filename)
|
|||
|
||||
Utility::SetCloExec(fd);
|
||||
|
||||
if (flock(fd, LOCK_EX | LOCK_NB) < 0) {
|
||||
struct flock lock;
|
||||
|
||||
lock.l_start = 0;
|
||||
lock.l_len = 0;
|
||||
lock.l_type = F_WRLCK;
|
||||
lock.l_whence = SEEK_SET;
|
||||
|
||||
if (fcntl(fd, F_SETLK, &lock) < 0) {
|
||||
Log(LogCritical, "base", "Could not lock PID file. Make sure that only one instance of the application is running.");
|
||||
|
||||
_exit(EXIT_FAILURE);
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
|
|
@ -40,13 +40,13 @@ void UnixSocket::Bind(const String& path)
|
|||
{
|
||||
unlink(path.CStr());
|
||||
|
||||
sockaddr_un sun;
|
||||
memset(&sun, 0, sizeof(sun));
|
||||
sun.sun_family = AF_UNIX;
|
||||
strncpy(sun.sun_path, path.CStr(), sizeof(sun.sun_path));
|
||||
sun.sun_path[sizeof(sun.sun_path) - 1] = '\0';
|
||||
sockaddr_un s_un;
|
||||
memset(&s_un, 0, sizeof(s_un));
|
||||
s_un.sun_family = AF_UNIX;
|
||||
strncpy(s_un.sun_path, path.CStr(), sizeof(s_un.sun_path));
|
||||
s_un.sun_path[sizeof(s_un.sun_path) - 1] = '\0';
|
||||
|
||||
if (bind(GetFD(), (sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
|
||||
if (bind(GetFD(), (sockaddr *)&s_un, SUN_LEN(&s_un)) < 0) {
|
||||
BOOST_THROW_EXCEPTION(posix_error()
|
||||
<< boost::errinfo_api_function("bind")
|
||||
<< boost::errinfo_errno(errno));
|
||||
|
@ -55,13 +55,13 @@ void UnixSocket::Bind(const String& path)
|
|||
|
||||
void UnixSocket::Connect(const String& path)
|
||||
{
|
||||
sockaddr_un sun;
|
||||
memset(&sun, 0, sizeof(sun));
|
||||
sun.sun_family = AF_UNIX;
|
||||
strncpy(sun.sun_path, path.CStr(), sizeof(sun.sun_path));
|
||||
sun.sun_path[sizeof(sun.sun_path) - 1] = '\0';
|
||||
sockaddr_un s_un;
|
||||
memset(&s_un, 0, sizeof(s_un));
|
||||
s_un.sun_family = AF_UNIX;
|
||||
strncpy(s_un.sun_path, path.CStr(), sizeof(s_un.sun_path));
|
||||
s_un.sun_path[sizeof(s_un.sun_path) - 1] = '\0';
|
||||
|
||||
if (connect(GetFD(), (sockaddr *)&sun, SUN_LEN(&sun)) < 0 && errno != EINPROGRESS) {
|
||||
if (connect(GetFD(), (sockaddr *)&s_un, SUN_LEN(&s_un)) < 0 && errno != EINPROGRESS) {
|
||||
BOOST_THROW_EXCEPTION(posix_error()
|
||||
<< boost::errinfo_api_function("connect")
|
||||
<< boost::errinfo_errno(errno));
|
||||
|
|
Loading…
Reference in New Issue