]> granicus.if.org Git - icinga2/commitdiff
Improve compatibility with Solaris.
authorGunnar Beutner <gunnar@beutner.name>
Sat, 23 Nov 2013 23:27:10 +0000 (00:27 +0100)
committerGunnar Beutner <gunnar@beutner.name>
Sun, 24 Nov 2013 00:00:35 +0000 (01:00 +0100)
Fixes #5129

lib/base/application.cpp
lib/base/unix.h
lib/base/unixsocket.cpp

index 354c7aebb3f6b0a4291ca0e40897b029538180a1..548b7ade779ec053cd79214008e5b30b1da6374d 100644 (file)
@@ -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);
index ee6022839f7fd2e06a6a8d801c46c0029c10f77e..7c4d0ed61c959ba2f77d8b3cc8d7f1e2b416b64d 100644 (file)
@@ -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>
index 8623a09a05cf2ca8afd4d3533ff57836b4314044..e18c31fe8eae11652e13d3de9af68f5fc445c16e 100644 (file)
@@ -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));