diff --git a/Foundation/CMakeLists.txt b/Foundation/CMakeLists.txt index 617ff5947..c3e28fde8 100644 --- a/Foundation/CMakeLists.txt +++ b/Foundation/CMakeLists.txt @@ -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() diff --git a/Foundation/include/Poco/NamedEvent_UNIX.h b/Foundation/include/Poco/NamedEvent_UNIX.h index 22cb31dc9..f4b5255f7 100644 --- a/Foundation/include/Poco/NamedEvent_UNIX.h +++ b/Foundation/include/Poco/NamedEvent_UNIX.h @@ -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 #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 diff --git a/Foundation/include/Poco/NamedMutex_UNIX.h b/Foundation/include/Poco/NamedMutex_UNIX.h index 151aa1ead..b60d6bc2a 100644 --- a/Foundation/include/Poco/NamedMutex_UNIX.h +++ b/Foundation/include/Poco/NamedMutex_UNIX.h @@ -21,7 +21,7 @@ #include "Poco/Foundation.h" #include #include -#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 #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 diff --git a/Foundation/src/Environment_UNIX.cpp b/Foundation/src/Environment_UNIX.cpp index b7e57e431..eb9042b9c 100644 --- a/Foundation/src/Environment_UNIX.cpp +++ b/Foundation/src/Environment_UNIX.cpp @@ -279,6 +279,54 @@ void EnvironmentImpl::nodeIdImpl(NodeId& id) } // namespace Poco +#elif defined(__GNU__) +// +// GNU Hurd +// +#include +#include +#include +#include + + +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 diff --git a/Foundation/src/NamedEvent_UNIX.cpp b/Foundation/src/NamedEvent_UNIX.cpp index b0cc100cd..686d770c8 100644 --- a/Foundation/src/NamedEvent_UNIX.cpp +++ b/Foundation/src/NamedEvent_UNIX.cpp @@ -18,7 +18,7 @@ #include #include #include -#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 #else #include @@ -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 { diff --git a/Foundation/src/NamedMutex_UNIX.cpp b/Foundation/src/NamedMutex_UNIX.cpp index 6466b2ba2..1f52c9798 100644 --- a/Foundation/src/NamedMutex_UNIX.cpp +++ b/Foundation/src/NamedMutex_UNIX.cpp @@ -18,7 +18,7 @@ #include #include #include -#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(_AIX) +#if defined(sun) || defined(__APPLE__) || defined(__osf__) || defined(_AIX) || defined(__GNU__) #include #else #include @@ -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