Skip to content

Commit

Permalink
Add support for musl libc on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
BenJarg committed Dec 17, 2022
1 parent 5cee590 commit 796896e
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 15 deletions.
5 changes: 5 additions & 0 deletions src/Xrd/XrdConfig.hh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
#include "Xrd/XrdProtLoad.hh"
#include "Xrd/XrdProtocol.hh"

#if defined(__linux__) && defined(HAVE_MUSL_LIBC)
#define __NEED_mode_t
#include <bits/alltypes.h>
#endif

class XrdSysError;
class XrdTcpMonInfo;
class XrdNetSecurity;
Expand Down
8 changes: 8 additions & 0 deletions src/XrdAcc/XrdAccGroups.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@
#include "XrdAcc/XrdAccGroups.hh"
#include "XrdAcc/XrdAccPrivs.hh"

#if defined(__linux__) && defined(HAVE_MUSL_LIBC)
int innetgr(const char *netgroup, const char *host, const char *user,
const char *domain)
{
return 0;
}
#endif

// Additionally, this routine does not support a user in more than
// NGROUPS_MAX groups. This is a standard unix limit defined in limits.h.

Expand Down
6 changes: 6 additions & 0 deletions src/XrdCl/XrdClFileStateHandler.hh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
#include <sys/uio.h>
#include <cstdint>

#if defined(__linux__) && defined(HAVE_MUSL_LIBC)
#define __NEED_suseconds_t
#define __NEED_struct_timeval
#include <bits/alltypes.h>
#endif

namespace
{
class PgReadHandler;
Expand Down
6 changes: 6 additions & 0 deletions src/XrdCl/XrdClMonitor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@

#include "XrdCl/XrdClFileSystem.hh"

#if defined(__linux__) && defined(HAVE_MUSL_LIBC)
#define __NEED_suseconds_t
#define __NEED_struct_timeval
#include <bits/alltypes.h>
#endif

namespace XrdCl
{
class URL;
Expand Down
4 changes: 3 additions & 1 deletion src/XrdNet/XrdNetSecurity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@
#include <sys/types.h>
#include <Winsock2.h>
#include <io.h>
#include "XrdSys/XrdWin32.hh"
#endif
#if WIN32 || defined(__linux__) && defined(HAVE_MUSL_LIBC)
int innetgr(const char *netgroup, const char *host, const char *user,
const char *domain)
{
return 0;
}
#include "XrdSys/XrdWin32.hh"
#endif

#include "XrdNet/XrdNetAddr.hh"
Expand Down
2 changes: 1 addition & 1 deletion src/XrdOssCsi/XrdOssCsiTagstoreFile.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#include <memory>
#include <mutex>

#if defined(__GLIBC__) || defined(__BIONIC__) || defined(__CYGWIN__)
#if defined(__GLIBC__) || defined(HAVE_MUSL_LIBC) || defined(__BIONIC__) || defined(__CYGWIN__)
#include <byteswap.h>
#elif defined(__APPLE__)
// Make sure that byte swap functions are not already defined.
Expand Down
11 changes: 9 additions & 2 deletions src/XrdPosix/XrdPosix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
#include <fcntl.h>
#include <unistd.h>
#include <sys/uio.h>
#if defined(__linux__) && defined(HAVE_MUSL_LIBC)
#include <stdio_ext.h>
#endif

#include "XrdSys/XrdSysHeaders.hh"
#include "XrdPosix/XrdPosixLinkage.hh"
Expand Down Expand Up @@ -310,9 +313,11 @@ size_t XrdPosix_Fread(void *ptr, size_t size, size_t nitems, FILE *stream)
//
if (bytes > 0 && size) rc = bytes/size;
#ifndef SUNX86
#if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
#if defined(__GLIBC__) || defined(__GNU__)
else if (bytes < 0) stream->_flags |= _IO_ERR_SEEN;
else stream->_flags |= _IO_EOF_SEEN;
#elif defined(HAVE_MUSL_LIBC)
else if (bytes < 0) __fseterr(stream);
#elif defined(__APPLE__) || defined(__FreeBSD__)
else if (bytes < 0) stream->_flags |= __SEOF;
else stream->_flags |= __SERR;
Expand Down Expand Up @@ -481,8 +486,10 @@ size_t XrdPosix_Fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream
//
if (bytes > 0 && size) rc = bytes/size;
#ifndef SUNX86
#if defined(__linux__) || defined(__GNU__) || (defined(__FreeBSD_kernel__) && defined(__GLIBC__))
#if defined(__GLIBC__) || defined(__GNU__)
else stream->_flags |= _IO_ERR_SEEN;
#elif defined(HAVE_MUSL_LIBC)
else __fseterr(stream);
#elif defined(__APPLE__) || defined(__FreeBSD__)
else stream->_flags |= __SERR;
#else
Expand Down
1 change: 1 addition & 0 deletions src/XrdPosix/XrdPosixLinkage.hh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <unistd.h>

#include "XrdPosix/XrdPosixOsDep.hh"
#include "XrdPosix/XrdPosixXrootd.hh"
#include "XrdSys/XrdSysPlatform.hh"

/******************************************************************************/
Expand Down
5 changes: 5 additions & 0 deletions src/XrdPosix/XrdPosixMap.hh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
#include "XrdCl/XrdClFileSystem.hh"
#include "XrdCl/XrdClXRootDResponses.hh"

#if defined(__linux__) && defined(HAVE_MUSL_LIBC)
#define __NEED_dev_t
#include <bits/alltypes.h>
#endif

class XrdPosixMap
{
public:
Expand Down
16 changes: 16 additions & 0 deletions src/XrdPosix/XrdPosixPreload.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@

#include "XrdPosix/XrdPosixExtern.hh"

#ifdef creat64
#undef creat64
#undef fseeko64
#undef ftello64
#undef ftruncate64
#undef lseek64
#undef open64
#undef pread64
#undef pwrite64
#undef readdir64
#undef readdir64_r
#undef statfs64
#undef statvfs64
#undef truncate64
#endif

/******************************************************************************/
/* G l o b a l D e c l a r a t i o n s */
/******************************************************************************/
Expand Down
10 changes: 1 addition & 9 deletions src/XrdSys/XrdSysPlatform.hh
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,8 @@ extern "C"
#if defined(_AIX) || \
(defined(XR__SUNGCC3) && !defined(__arch64__))
# define SOCKLEN_t size_t
#elif defined(XR__GLIBC) || \
defined(__FreeBSD__) || \
(defined(__FreeBSD_kernel__) && defined(__GLIBC__)) || \
(defined(XR__SUNGCC3) && defined(__arch64__)) || defined(__APPLE__) || \
(defined(__sun) && defined(_SOCKLEN_T))
# ifndef SOCKLEN_t
# define SOCKLEN_t socklen_t
# endif
#elif !defined(SOCKLEN_t)
# define SOCKLEN_t int
# define SOCKLEN_t socklen_t
#endif

#ifdef _LP64
Expand Down
4 changes: 2 additions & 2 deletions src/XrdSys/XrdSysPthread.hh
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ enum PrefType {prefWR=1};

XrdSysRWLock(PrefType ptype)
{
#ifdef __linux__
#ifdef __GLIBC__
pthread_rwlockattr_t attr;
pthread_rwlockattr_setkind_np(&attr,
PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
Expand All @@ -367,7 +367,7 @@ enum PrefType {prefWR=1};
inline void ReInitialize(PrefType ptype)
{
pthread_rwlock_destroy(&lock);
#ifdef __linux__
#ifdef __GLIBC__
pthread_rwlockattr_t attr;
pthread_rwlockattr_setkind_np(&attr,
PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
Expand Down

0 comments on commit 796896e

Please sign in to comment.