Add GNU Hurd support (#3946)

Co-authored-by: Jochen Sprickerhof <git@jochen.sprickerhof.de>
This commit is contained in:
Samuel Thibault 2023-03-17 21:24:57 +01:00 committed by GitHub
parent 9a374ca2de
commit d05d689622
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 66 additions and 18 deletions

View File

@ -165,7 +165,7 @@ else()
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
target_compile_definitions(Foundation PUBLIC POCO_HAVE_FD_POLL)
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_link_libraries(Foundation PUBLIC pthread ${CMAKE_DL_LIBS} rt)
else()

View File

@ -19,7 +19,7 @@
#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>
#endif
@ -39,7 +39,7 @@ private:
std::string getFileName();
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;
#else
int _semid; // semaphore id

View File

@ -21,7 +21,7 @@
#include "Poco/Foundation.h"
#include <sys/types.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>
#endif
@ -42,7 +42,7 @@ private:
std::string getFileName();
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;
#else
int _semid; // semaphore id

View File

@ -279,6 +279,54 @@ void EnvironmentImpl::nodeIdImpl(NodeId& id)
} // 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)
//
// General Unix

View File

@ -18,7 +18,7 @@
#include <fcntl.h>
#include <sys/stat.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>
#else
#include <unistd.h>
@ -53,7 +53,7 @@ NamedEventImpl::NamedEventImpl(const std::string& name):
_name(name)
{
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);
if ((long) _sem == (long) SEM_FAILED)
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);
}
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()
{
#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);
#endif
}
@ -94,7 +94,7 @@ NamedEventImpl::~NamedEventImpl()
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)
throw SystemException("cannot set named event", _name);
#else
@ -110,7 +110,7 @@ void NamedEventImpl::setImpl()
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;
do
{

View File

@ -18,7 +18,7 @@
#include <fcntl.h>
#include <sys/stat.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>
#else
#include <unistd.h>
@ -53,7 +53,7 @@ NamedMutexImpl::NamedMutexImpl(const std::string& name):
_name(name)
{
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);
if ((long) _sem == (long) SEM_FAILED)
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);
#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()
{
#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);
#else
if (_owned) semctl(_semid, 0, IPC_RMID, 0);
@ -101,7 +101,7 @@ NamedMutexImpl::~NamedMutexImpl()
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;
do
{
@ -127,7 +127,7 @@ void NamedMutexImpl::lockImpl()
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;
#else
struct sembuf op;
@ -141,7 +141,7 @@ bool NamedMutexImpl::tryLockImpl()
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)
throw SystemException("cannot unlock named mutex", _name);
#else