[icinga-checkins] icinga.org: icinga2/next: Improve compatibility with Solaris.

git at icinga.org git at icinga.org
Sun Nov 24 01:01:10 CET 2013


Module: icinga2
Branch: next
Commit: d4cc6fb5e0f51f0272fb108c6e0caf6f68caa128
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=d4cc6fb5e0f51f0272fb108c6e0caf6f68caa128

Author: Gunnar Beutner <gunnar at beutner.name>
Date:   Sun Nov 24 00:27:10 2013 +0100

Improve compatibility with Solaris.

Fixes #5129

---

 lib/base/application.cpp |    9 ++++++++-
 lib/base/unix.h          |    1 +
 lib/base/unixsocket.cpp  |   24 ++++++++++++------------
 3 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/lib/base/application.cpp b/lib/base/application.cpp
index 354c7ae..548b7ad 100644
--- a/lib/base/application.cpp
+++ b/lib/base/application.cpp
@@ -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);
diff --git a/lib/base/unix.h b/lib/base/unix.h
index ee60228..7c4d0ed 100644
--- a/lib/base/unix.h
+++ b/lib/base/unix.h
@@ -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>
diff --git a/lib/base/unixsocket.cpp b/lib/base/unixsocket.cpp
index 8623a09..e18c31f 100644
--- a/lib/base/unixsocket.cpp
+++ b/lib/base/unixsocket.cpp
@@ -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));





More information about the icinga-checkins mailing list