Improve compatibility with Solaris.

Fixes #5129
This commit is contained in:
Gunnar Beutner 2013-11-24 00:27:10 +01:00
parent e32a149049
commit d4cc6fb5e0
3 changed files with 21 additions and 13 deletions

View 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);

View 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>

View 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));