mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-26 10:32:56 +01:00
Add GNU Hurd support (#3946)
Co-authored-by: Jochen Sprickerhof <git@jochen.sprickerhof.de>
This commit is contained in:
@@ -165,7 +165,7 @@ else()
|
|||||||
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
|
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
|
||||||
target_compile_definitions(Foundation PUBLIC POCO_HAVE_FD_POLL)
|
target_compile_definitions(Foundation PUBLIC POCO_HAVE_FD_POLL)
|
||||||
target_link_libraries(Foundation PUBLIC pthread ${CMAKE_DL_LIBS} rt)
|
target_link_libraries(Foundation PUBLIC pthread ${CMAKE_DL_LIBS} rt)
|
||||||
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "AIX")
|
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "AIX" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "GNU")
|
||||||
target_compile_definitions(Foundation PUBLIC _XOPEN_SOURCE=500 POCO_HAVE_FD_POLL)
|
target_compile_definitions(Foundation PUBLIC _XOPEN_SOURCE=500 POCO_HAVE_FD_POLL)
|
||||||
target_link_libraries(Foundation PUBLIC pthread ${CMAKE_DL_LIBS} rt)
|
target_link_libraries(Foundation PUBLIC pthread ${CMAKE_DL_LIBS} rt)
|
||||||
else()
|
else()
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX) || defined(__GNU__)
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ private:
|
|||||||
std::string getFileName();
|
std::string getFileName();
|
||||||
|
|
||||||
std::string _name;
|
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) || defined(__GNU__)
|
||||||
sem_t* _sem;
|
sem_t* _sem;
|
||||||
#else
|
#else
|
||||||
int _semid; // semaphore id
|
int _semid; // semaphore id
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX) || defined(__GNU__)
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ private:
|
|||||||
std::string getFileName();
|
std::string getFileName();
|
||||||
|
|
||||||
std::string _name;
|
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) || defined(__GNU__)
|
||||||
sem_t* _sem;
|
sem_t* _sem;
|
||||||
#else
|
#else
|
||||||
int _semid; // semaphore id
|
int _semid; // semaphore id
|
||||||
|
|||||||
@@ -279,6 +279,54 @@ void EnvironmentImpl::nodeIdImpl(NodeId& id)
|
|||||||
} // namespace Poco
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
|
#elif defined(__GNU__)
|
||||||
|
//
|
||||||
|
// GNU Hurd
|
||||||
|
//
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Poco {
|
||||||
|
|
||||||
|
|
||||||
|
void EnvironmentImpl::nodeIdImpl(NodeId& id)
|
||||||
|
{
|
||||||
|
std::memset(&id, 0, sizeof(id));
|
||||||
|
struct ifreq ifr;
|
||||||
|
struct ifconf ifc;
|
||||||
|
char buf[1024];
|
||||||
|
|
||||||
|
int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
|
||||||
|
if (sock == -1) return;
|
||||||
|
|
||||||
|
ifc.ifc_len = sizeof(buf);
|
||||||
|
ifc.ifc_buf = buf;
|
||||||
|
if (ioctl(sock, SIOCGIFCONF, &ifc) == -1) return;
|
||||||
|
|
||||||
|
struct ifreq* it = ifc.ifc_req;
|
||||||
|
const struct ifreq* const end = it + (ifc.ifc_len / sizeof(struct ifreq));
|
||||||
|
|
||||||
|
for (; it != end; ++it) {
|
||||||
|
std::strcpy(ifr.ifr_name, it->ifr_name);
|
||||||
|
if (ioctl(sock, SIOCGIFFLAGS, &ifr) == 0) {
|
||||||
|
if (! (ifr.ifr_flags & IFF_LOOPBACK)) { // don't count loopback
|
||||||
|
if (ioctl(sock, SIOCGIFHWADDR, &ifr) == 0) {
|
||||||
|
std::memcpy(&id, ifr.ifr_hwaddr.sa_data, sizeof(id));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Poco
|
||||||
|
|
||||||
|
|
||||||
#elif defined(POCO_OS_FAMILY_UNIX)
|
#elif defined(POCO_OS_FAMILY_UNIX)
|
||||||
//
|
//
|
||||||
// General Unix
|
// General Unix
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX) || defined(__GNU__)
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -53,7 +53,7 @@ NamedEventImpl::NamedEventImpl(const std::string& name):
|
|||||||
_name(name)
|
_name(name)
|
||||||
{
|
{
|
||||||
std::string fileName = getFileName();
|
std::string fileName = getFileName();
|
||||||
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX) || defined(__GNU__)
|
||||||
_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(Poco::format("cannot create named mutex %s (sem_open() failed, errno=%d)", fileName, errno), _name);
|
throw SystemException(Poco::format("cannot create named mutex %s (sem_open() failed, errno=%d)", fileName, errno), _name);
|
||||||
@@ -80,13 +80,13 @@ NamedEventImpl::NamedEventImpl(const std::string& name):
|
|||||||
_semid = semget(key, 1, 0);
|
_semid = semget(key, 1, 0);
|
||||||
}
|
}
|
||||||
else throw SystemException(Poco::format("cannot create named mutex %s (semget() failed, errno=%d)", fileName, errno), _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) || defined(__GNU__)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NamedEventImpl::~NamedEventImpl()
|
NamedEventImpl::~NamedEventImpl()
|
||||||
{
|
{
|
||||||
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX) || defined(__GNU__)
|
||||||
sem_close(_sem);
|
sem_close(_sem);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ NamedEventImpl::~NamedEventImpl()
|
|||||||
|
|
||||||
void NamedEventImpl::setImpl()
|
void NamedEventImpl::setImpl()
|
||||||
{
|
{
|
||||||
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX) || defined(__GNU__)
|
||||||
if (sem_post(_sem) != 0)
|
if (sem_post(_sem) != 0)
|
||||||
throw SystemException("cannot set named event", _name);
|
throw SystemException("cannot set named event", _name);
|
||||||
#else
|
#else
|
||||||
@@ -110,7 +110,7 @@ void NamedEventImpl::setImpl()
|
|||||||
|
|
||||||
void NamedEventImpl::waitImpl()
|
void NamedEventImpl::waitImpl()
|
||||||
{
|
{
|
||||||
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX) || defined(__GNU__)
|
||||||
int err;
|
int err;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(_AIX)
|
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(_AIX) || defined(__GNU__)
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
#else
|
#else
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -53,7 +53,7 @@ NamedMutexImpl::NamedMutexImpl(const std::string& name):
|
|||||||
_name(name)
|
_name(name)
|
||||||
{
|
{
|
||||||
std::string fileName = getFileName();
|
std::string fileName = getFileName();
|
||||||
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX) || defined(__GNU__)
|
||||||
_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(Poco::format("cannot create named mutex %s (sem_open() failed, errno=%d)", fileName, errno), _name);
|
throw SystemException(Poco::format("cannot create named mutex %s (sem_open() failed, errno=%d)", fileName, errno), _name);
|
||||||
@@ -85,13 +85,13 @@ NamedMutexImpl::NamedMutexImpl(const std::string& name):
|
|||||||
}
|
}
|
||||||
|
|
||||||
throw SystemException(Poco::format("cannot create named mutex %s (semget() failed, errno=%d)", fileName, errno), _name);
|
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) || defined(__GNU__)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NamedMutexImpl::~NamedMutexImpl()
|
NamedMutexImpl::~NamedMutexImpl()
|
||||||
{
|
{
|
||||||
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX) || defined(__GNU__)
|
||||||
sem_close(_sem);
|
sem_close(_sem);
|
||||||
#else
|
#else
|
||||||
if (_owned) semctl(_semid, 0, IPC_RMID, 0);
|
if (_owned) semctl(_semid, 0, IPC_RMID, 0);
|
||||||
@@ -101,7 +101,7 @@ NamedMutexImpl::~NamedMutexImpl()
|
|||||||
|
|
||||||
void NamedMutexImpl::lockImpl()
|
void NamedMutexImpl::lockImpl()
|
||||||
{
|
{
|
||||||
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX) || defined(__GNU__)
|
||||||
int err;
|
int err;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -127,7 +127,7 @@ void NamedMutexImpl::lockImpl()
|
|||||||
|
|
||||||
bool NamedMutexImpl::tryLockImpl()
|
bool NamedMutexImpl::tryLockImpl()
|
||||||
{
|
{
|
||||||
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX) || defined(__GNU__)
|
||||||
return sem_trywait(_sem) == 0;
|
return sem_trywait(_sem) == 0;
|
||||||
#else
|
#else
|
||||||
struct sembuf op;
|
struct sembuf op;
|
||||||
@@ -141,7 +141,7 @@ bool NamedMutexImpl::tryLockImpl()
|
|||||||
|
|
||||||
void NamedMutexImpl::unlockImpl()
|
void NamedMutexImpl::unlockImpl()
|
||||||
{
|
{
|
||||||
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX)
|
#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(__QNX__) || defined(_AIX) || defined(__GNU__)
|
||||||
if (sem_post(_sem) != 0)
|
if (sem_post(_sem) != 0)
|
||||||
throw SystemException("cannot unlock named mutex", _name);
|
throw SystemException("cannot unlock named mutex", _name);
|
||||||
#else
|
#else
|
||||||
|
|||||||
Reference in New Issue
Block a user