diff --git a/src/gidcache.cpp b/src/gidcache.cpp index 8a280f51..594e9291 100644 --- a/src/gidcache.cpp +++ b/src/gidcache.cpp @@ -28,11 +28,16 @@ #include #include +#if defined __linux__ and UGID_USE_RWLOCK == 0 +# include +#endif + #include #include #include "gidcache.hpp" +inline bool gid_t_rec::operator<(const struct gid_t_rec &b) const { @@ -123,21 +128,36 @@ gid_t_cache::cache(const uid_t uid, return rec; } -void +static +inline +int +setgroups(const gid_t_rec *rec) +{ +#if defined __linux__ and UGID_USE_RWLOCK == 0 + return ::syscall(SYS_setgroups,rec->size,rec->gids); +#else + return ::setgroups(rec->size,rec->gids); +#endif +} + +int gid_t_cache::initgroups(const uid_t uid, const gid_t gid) { + int rv; gid_t_rec *rec; rec = lower_bound(begin(),end(),uid); if(rec == end() || rec->uid != uid) { rec = cache(uid,gid); - ::setgroups(rec->size,rec->gids); + rv = ::setgroups(rec); std::sort(begin(),end()); } else { - ::setgroups(rec->size,rec->gids); + rv = ::setgroups(rec); } + + return rv; } diff --git a/src/gidcache.hpp b/src/gidcache.hpp index 29ba1c2b..a3b6d44f 100644 --- a/src/gidcache.hpp +++ b/src/gidcache.hpp @@ -58,7 +58,7 @@ private: const gid_t gid); public: - void + int initgroups(const uid_t uid, const gid_t gid); }; diff --git a/src/ugid.hpp b/src/ugid.hpp index 4555f333..c1eb34b6 100644 --- a/src/ugid.hpp +++ b/src/ugid.hpp @@ -30,15 +30,12 @@ #include -typedef std::vector gid_t_vector; - namespace mergerfs { namespace ugid { void init(); void initgroups(const uid_t uid, const gid_t gid); - void setgroups(const gid_t_vector &gidlist); } } diff --git a/src/ugid_linux.ipp b/src/ugid_linux.ipp index 880ca1f8..97a338f1 100644 --- a/src/ugid_linux.ipp +++ b/src/ugid_linux.ipp @@ -29,8 +29,6 @@ #include -typedef std::vector gid_t_vector; - namespace mergerfs { namespace ugid @@ -43,11 +41,5 @@ namespace mergerfs init() { } - - int - setgroups(const gid_t_vector &gidlist) - { - return ::syscall(SYS_setgroups,gidlist.size(),&gidlist[0]); - } } } diff --git a/src/ugid_rwlock.ipp b/src/ugid_rwlock.ipp index 3b85776c..38d485ca 100644 --- a/src/ugid_rwlock.ipp +++ b/src/ugid_rwlock.ipp @@ -29,8 +29,6 @@ #include -typedef std::vector gid_t_vector; - namespace mergerfs { namespace ugid @@ -54,11 +52,5 @@ namespace mergerfs currentuid = ::geteuid(); currentgid = ::getegid(); } - - int - setgroups(const gid_t_vector &gidlist) - { - return ::setgroups(gidlist.size(),&gidlist[0]); - } } }