mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-14 19:13:49 +01:00
improved NamedMutex/Event error diagnostics
This commit is contained in:
parent
46acf8b6dc
commit
94c54f926d
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Poco/NamedEvent_UNIX.h"
|
#include "Poco/NamedEvent_UNIX.h"
|
||||||
|
#include "Poco/Format.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -77,16 +78,16 @@ NamedEventImpl::NamedEventImpl(const std::string& name):
|
|||||||
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
||||||
_sem = sem_open(fileName.c_str(), O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO, 0);
|
_sem = sem_open(fileName.c_str(), O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO, 0);
|
||||||
if ((long) _sem == (long) SEM_FAILED)
|
if ((long) _sem == (long) SEM_FAILED)
|
||||||
throw SystemException("cannot create named event (sem_open() failed)", _name);
|
throw SystemException(Poco::format("cannot create named mutex %s (sem_open() failed, errno=%d)", fileName, errno), _name);
|
||||||
#else
|
#else
|
||||||
int fd = open(fileName.c_str(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
int fd = open(fileName.c_str(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
close(fd);
|
close(fd);
|
||||||
else
|
else
|
||||||
throw SystemException("cannot create named event (lockfile)", _name);
|
throw SystemException(Poco::format("cannot create named event %s (lockfile)", fileName), _name);
|
||||||
key_t key = ftok(fileName.c_str(), 0);
|
key_t key = ftok(fileName.c_str(), 0);
|
||||||
if (key == -1)
|
if (key == -1)
|
||||||
throw SystemException("cannot create named event (ftok() failed)", _name);
|
throw SystemException(Poco::format("cannot create named mutex %s (ftok() failed, errno=%d)", fileName, errno), _name);
|
||||||
_semid = semget(key, 1, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | IPC_CREAT | IPC_EXCL);
|
_semid = semget(key, 1, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | IPC_CREAT | IPC_EXCL);
|
||||||
if (_semid >= 0)
|
if (_semid >= 0)
|
||||||
{
|
{
|
||||||
@ -98,7 +99,7 @@ NamedEventImpl::NamedEventImpl(const std::string& name):
|
|||||||
{
|
{
|
||||||
_semid = semget(key, 1, 0);
|
_semid = semget(key, 1, 0);
|
||||||
}
|
}
|
||||||
else throw SystemException("cannot create named event (semget() failed)", _name);
|
else throw SystemException(Poco::format("cannot create named mutex %s (semget() failed, errno=%d)", fileName, errno), _name);
|
||||||
#endif // defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
#endif // defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Poco/NamedMutex_UNIX.h"
|
#include "Poco/NamedMutex_UNIX.h"
|
||||||
|
#include "Poco/Format.h"
|
||||||
#include "Poco/Exception.h"
|
#include "Poco/Exception.h"
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -77,16 +78,16 @@ NamedMutexImpl::NamedMutexImpl(const std::string& name):
|
|||||||
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
||||||
_sem = sem_open(fileName.c_str(), O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO, 1);
|
_sem = sem_open(fileName.c_str(), O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO, 1);
|
||||||
if ((long) _sem == (long) SEM_FAILED)
|
if ((long) _sem == (long) SEM_FAILED)
|
||||||
throw SystemException("cannot create named mutex (sem_open() failed)", _name);
|
throw SystemException(Poco::format("cannot create named mutex %s (sem_open() failed, errno=%d)", fileName, errno), _name);
|
||||||
#else
|
#else
|
||||||
int fd = open(fileName.c_str(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
int fd = open(fileName.c_str(), O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
close(fd);
|
close(fd);
|
||||||
else
|
else
|
||||||
throw SystemException("cannot create named mutex (lockfile)", _name);
|
throw SystemException(Poco::format("cannot create named mutex %s (lockfile)", fileName), _name);
|
||||||
key_t key = ftok(fileName.c_str(), 0);
|
key_t key = ftok(fileName.c_str(), 0);
|
||||||
if (key == -1)
|
if (key == -1)
|
||||||
throw SystemException("cannot create named mutex (ftok() failed)", _name);
|
throw SystemException(Poco::format("cannot create named mutex %s (ftok() failed, errno=%d)", fileName, errno), _name);
|
||||||
_semid = semget(key, 1, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | IPC_CREAT | IPC_EXCL);
|
_semid = semget(key, 1, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH | IPC_CREAT | IPC_EXCL);
|
||||||
if (_semid >= 0)
|
if (_semid >= 0)
|
||||||
{
|
{
|
||||||
@ -98,7 +99,7 @@ NamedMutexImpl::NamedMutexImpl(const std::string& name):
|
|||||||
{
|
{
|
||||||
_semid = semget(key, 1, 0);
|
_semid = semget(key, 1, 0);
|
||||||
}
|
}
|
||||||
else throw SystemException("cannot create named mutex (semget() failed)", _name);
|
else throw SystemException(Poco::format("cannot create named mutex %s (semget() failed, errno=%d)", fileName, errno), _name);
|
||||||
#endif // defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
#endif // defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,3 +182,4 @@ std::string NamedMutexImpl::getFileName()
|
|||||||
|
|
||||||
|
|
||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user