Skip to content

Commit

Permalink
iox-eclipse-iceoryx#2289 Add 'iox' prefix to entities in 'unistd.hpp'
Browse files Browse the repository at this point in the history
  • Loading branch information
elBoberido committed May 16, 2024
1 parent 7d39999 commit aa6149f
Show file tree
Hide file tree
Showing 42 changed files with 293 additions and 130 deletions.
10 changes: 5 additions & 5 deletions iceoryx_hoofs/posix/auth/include/iox/posix_group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ class PosixGroup
{
public:
using groupName_t = string<platform::MAX_GROUP_NAME_LENGTH>;
explicit PosixGroup(const gid_t id) noexcept;
explicit PosixGroup(const iox_gid_t id) noexcept;
explicit PosixGroup(const groupName_t& name) noexcept;

bool operator==(const PosixGroup& other) const noexcept;

groupName_t getName() const noexcept;
gid_t getID() const noexcept;
iox_gid_t getID() const noexcept;

bool doesExist() const noexcept;

static PosixGroup getGroupOfCurrentProcess() noexcept;

static optional<uid_t> getGroupID(const groupName_t& name) noexcept;
static optional<groupName_t> getGroupName(gid_t id) noexcept;
static optional<iox_uid_t> getGroupID(const groupName_t& name) noexcept;
static optional<groupName_t> getGroupName(iox_gid_t id) noexcept;

private:
gid_t m_id;
iox_gid_t m_id;
bool m_doesExist{false};
};

Expand Down
10 changes: 5 additions & 5 deletions iceoryx_hoofs/posix/auth/include/iox/posix_user.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ class PosixUser

using userName_t = string<platform::MAX_USER_NAME_LENGTH>;

explicit PosixUser(const uid_t id) noexcept;
explicit PosixUser(const iox_uid_t id) noexcept;
explicit PosixUser(const userName_t& name) noexcept;

groupVector_t getGroups() const noexcept;
userName_t getName() const noexcept;
uid_t getID() const noexcept;
iox_uid_t getID() const noexcept;

bool doesExist() const noexcept;

static PosixUser getUserOfCurrentProcess() noexcept;

static optional<uid_t> getUserID(const userName_t& name) noexcept;
static optional<userName_t> getUserName(uid_t id) noexcept;
static optional<iox_uid_t> getUserID(const userName_t& name) noexcept;
static optional<userName_t> getUserName(iox_uid_t id) noexcept;

private:
uid_t m_id;
iox_uid_t m_id;
bool m_doesExist{false};
};

Expand Down
14 changes: 7 additions & 7 deletions iceoryx_hoofs/posix/auth/source/posix_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

namespace iox
{
PosixGroup::PosixGroup(gid_t id) noexcept
PosixGroup::PosixGroup(iox_gid_t id) noexcept
: m_id(id)
, m_doesExist(getGroupName(id).has_value())
{
Expand All @@ -43,7 +43,7 @@ PosixGroup::PosixGroup(const PosixGroup::groupName_t& name) noexcept
else
{
IOX_LOG(ERROR, "Error: Group name not found");
m_id = std::numeric_limits<gid_t>::max();
m_id = std::numeric_limits<iox_gid_t>::max();
}
}

Expand All @@ -54,10 +54,10 @@ bool PosixGroup::operator==(const PosixGroup& other) const noexcept

PosixGroup PosixGroup::getGroupOfCurrentProcess() noexcept
{
return PosixGroup(getgid());
return PosixGroup(iox_getgid());
}

optional<gid_t> PosixGroup::getGroupID(const PosixGroup::groupName_t& name) noexcept
optional<iox_gid_t> PosixGroup::getGroupID(const PosixGroup::groupName_t& name) noexcept
{
auto getgrnamCall = IOX_POSIX_CALL(getgrnam)(name.c_str()).failureReturnValue(nullptr).evaluate();

Expand All @@ -67,10 +67,10 @@ optional<gid_t> PosixGroup::getGroupID(const PosixGroup::groupName_t& name) noex
return nullopt_t();
}

return make_optional<gid_t>(getgrnamCall->value->gr_gid);
return make_optional<iox_gid_t>(getgrnamCall->value->gr_gid);
}

optional<PosixGroup::groupName_t> PosixGroup::getGroupName(gid_t id) noexcept
optional<PosixGroup::groupName_t> PosixGroup::getGroupName(iox_gid_t id) noexcept
{
auto getgrgidCall = IOX_POSIX_CALL(getgrgid)(id).failureReturnValue(nullptr).evaluate();

Expand All @@ -94,7 +94,7 @@ PosixGroup::groupName_t PosixGroup::getName() const noexcept
return groupName_t();
}

gid_t PosixGroup::getID() const noexcept
iox_gid_t PosixGroup::getID() const noexcept
{
return m_id;
}
Expand Down
19 changes: 10 additions & 9 deletions iceoryx_hoofs/posix/auth/source/posix_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "iceoryx_platform/platform_correction.hpp"
#include "iceoryx_platform/pwd.hpp"
#include "iceoryx_platform/types.hpp"
#include "iceoryx_platform/unistd.hpp"
#include "iox/logging.hpp"
#include "iox/posix_call.hpp"
#include "iox/uninitialized_array.hpp"
Expand All @@ -28,7 +29,7 @@

namespace iox
{
optional<uid_t> PosixUser::getUserID(const userName_t& name) noexcept
optional<iox_uid_t> PosixUser::getUserID(const userName_t& name) noexcept
{
auto getpwnamCall = IOX_POSIX_CALL(getpwnam)(name.c_str()).failureReturnValue(nullptr).evaluate();

Expand All @@ -37,10 +38,10 @@ optional<uid_t> PosixUser::getUserID(const userName_t& name) noexcept
IOX_LOG(ERROR, "Error: Could not find user '" << name << "'.");
return nullopt_t();
}
return make_optional<uid_t>(getpwnamCall->value->pw_uid);
return make_optional<iox_uid_t>(getpwnamCall->value->pw_uid);
}

optional<PosixUser::userName_t> PosixUser::getUserName(uid_t id) noexcept
optional<PosixUser::userName_t> PosixUser::getUserName(iox_uid_t id) noexcept
{
auto getpwuidCall = IOX_POSIX_CALL(getpwuid)(id).failureReturnValue(nullptr).evaluate();

Expand All @@ -67,8 +68,8 @@ PosixUser::groupVector_t PosixUser::getGroups() const noexcept
return groupVector_t();
}

gid_t userDefaultGroup = getpwnamCall->value->pw_gid;
UninitializedArray<gid_t, MAX_NUMBER_OF_GROUPS> groups{}; // groups is initialized in iox_getgrouplist
iox_gid_t userDefaultGroup = getpwnamCall->value->pw_gid;
UninitializedArray<iox_gid_t, MAX_NUMBER_OF_GROUPS> groups{}; // groups is initialized in iox_getgrouplist
int numGroups = MAX_NUMBER_OF_GROUPS;

auto getgrouplistCall =
Expand Down Expand Up @@ -96,7 +97,7 @@ PosixUser::groupVector_t PosixUser::getGroups() const noexcept
return vec;
}

PosixUser::PosixUser(uid_t id) noexcept
PosixUser::PosixUser(iox_uid_t id) noexcept
: m_id(id)
, m_doesExist(getUserName(id).has_value())
{
Expand All @@ -112,7 +113,7 @@ PosixUser::PosixUser(const PosixUser::userName_t& name) noexcept
else
{
IOX_LOG(ERROR, "Error: User name not found");
m_id = std::numeric_limits<gid_t>::max();
m_id = std::numeric_limits<iox_gid_t>::max();
}
}

Expand All @@ -127,7 +128,7 @@ PosixUser::userName_t PosixUser::getName() const noexcept
return userName_t();
}

uid_t PosixUser::getID() const noexcept
iox_uid_t PosixUser::getID() const noexcept
{
return m_id;
}
Expand All @@ -139,7 +140,7 @@ bool PosixUser::doesExist() const noexcept

PosixUser PosixUser::getUserOfCurrentProcess() noexcept
{
return PosixUser(geteuid());
return PosixUser(iox_geteuid());
}

} // namespace iox
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ enum class FileSetPermissionError : uint8_t
namespace details
{
expected<iox_stat, FileStatError> get_file_status(const int fildes) noexcept;
expected<void, FileSetOwnerError> set_owner(const int fildes, const uid_t uid, const gid_t gid) noexcept;
expected<void, FileSetOwnerError> set_owner(const int fildes, const iox_uid_t uid, const iox_gid_t gid) noexcept;
expected<void, FileSetPermissionError> set_permissions(const int fildes, const access_rights perms) noexcept;
} // namespace details

Expand All @@ -71,16 +71,16 @@ class Ownership
public:
/// @brief Acquire the user id
/// @returns uid
uid_t uid() const noexcept;
iox_uid_t uid() const noexcept;

/// @brief Acquire the group id
/// @returns gid
gid_t gid() const noexcept;
iox_gid_t gid() const noexcept;

/// @brief Constructs a ownership object from a uid and a gid.
/// @returns If the user or group does not exist it returns 'iox::nullopt' otherwise an Ownership object
/// with existing user and group
static optional<Ownership> from_user_and_group(const uid_t uid, const gid_t gid) noexcept;
static optional<Ownership> from_user_and_group(const iox_uid_t uid, const iox_gid_t gid) noexcept;

/// @brief Constructs a ownership object from a user name and a group name.
/// @returns If the user or group does not exist it returns 'iox::nullopt' otherwise an Ownership object
Expand All @@ -93,11 +93,11 @@ class Ownership
private:
template <typename>
friend struct FileManagementInterface;
Ownership(const uid_t uid, const gid_t gid) noexcept;
Ownership(const iox_uid_t uid, const iox_gid_t gid) noexcept;

private:
uid_t m_uid{std::numeric_limits<uid_t>::max()};
gid_t m_gid{std::numeric_limits<gid_t>::max()};
iox_uid_t m_uid{std::numeric_limits<iox_uid_t>::max()};
iox_gid_t m_gid{std::numeric_limits<iox_gid_t>::max()};
};

/// @brief Abstract implementation to manage things common to all file descriptor
Expand Down
10 changes: 5 additions & 5 deletions iceoryx_hoofs/posix/design/source/file_management_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ expected<iox_stat, FileStatError> get_file_status(const int fildes) noexcept
return ok(file_status);
}

expected<void, FileSetOwnerError> set_owner(const int fildes, const uid_t uid, const gid_t gid) noexcept
expected<void, FileSetOwnerError> set_owner(const int fildes, const iox_uid_t uid, const iox_gid_t gid) noexcept
{
auto result = IOX_POSIX_CALL(iox_fchown)(fildes, uid, gid).failureReturnValue(-1).evaluate();

Expand Down Expand Up @@ -118,17 +118,17 @@ expected<void, FileSetPermissionError> set_permissions(const int fildes, const a

} // namespace details

uid_t Ownership::uid() const noexcept
iox_uid_t Ownership::uid() const noexcept
{
return m_uid;
}

gid_t Ownership::gid() const noexcept
iox_gid_t Ownership::gid() const noexcept
{
return m_gid;
}

optional<Ownership> Ownership::from_user_and_group(const uid_t uid, const gid_t gid) noexcept
optional<Ownership> Ownership::from_user_and_group(const iox_uid_t uid, const iox_gid_t gid) noexcept
{
if (!PosixUser(uid).doesExist() || !PosixGroup(gid).doesExist())
{
Expand Down Expand Up @@ -156,7 +156,7 @@ Ownership Ownership::from_process() noexcept
return Ownership(PosixUser::getUserOfCurrentProcess().getID(), PosixGroup::getGroupOfCurrentProcess().getID());
}

Ownership::Ownership(const uid_t uid, const gid_t gid) noexcept
Ownership::Ownership(const iox_uid_t uid, const iox_gid_t gid) noexcept
: m_uid{uid}
, m_gid{gid}
{
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/posix/filesystem/source/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ void File::close_fd() noexcept

expected<bool, FileAccessError> File::does_exist(const FilePath& file) noexcept
{
auto result = IOX_POSIX_CALL(iox_access)(file.as_string().c_str(), F_OK).failureReturnValue(-1).evaluate();
auto result = IOX_POSIX_CALL(iox_access)(file.as_string().c_str(), IOX_F_OK).failureReturnValue(-1).evaluate();

if (!result.has_error())
{
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/posix/ipc/source/posix_shared_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ expected<PosixSharedMemory, PosixSharedMemoryError> PosixSharedMemoryBuilder::cr

if (hasOwnership)
{
auto result = IOX_POSIX_CALL(ftruncate)(sharedMemoryFileHandle, static_cast<int64_t>(m_size))
auto result = IOX_POSIX_CALL(iox_ftruncate)(sharedMemoryFileHandle, static_cast<int64_t>(m_size))
.failureReturnValue(PosixSharedMemory::INVALID_HANDLE)
.evaluate();
if (result.has_error())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ uint64_t pageSize() noexcept
{
// sysconf fails when one provides an invalid name parameter. _SC_PAGESIZE
// is a valid name parameter therefore it should never fail.
return static_cast<uint64_t>(IOX_POSIX_CALL(sysconf)(_SC_PAGESIZE)
return static_cast<uint64_t>(IOX_POSIX_CALL(iox_sysconf)(IOX_SC_PAGESIZE)
.failureReturnValue(-1)
.evaluate()
.or_else([](auto& r) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct PwUidResult
char buff[BUFFER_SIZE];
};

std::unique_ptr<PwUidResult> iox_getpwuid(const uid_t uid)
std::unique_ptr<PwUidResult> iox_getpwuid(const iox_uid_t uid)
{
passwd* resultPtr = nullptr;
std::unique_ptr<PwUidResult> result = std::make_unique<PwUidResult>();
Expand Down Expand Up @@ -126,7 +126,7 @@ TEST_F(PosixAcl_test, writeSpecialUserPermissions)
// no name specified
EXPECT_FALSE(entryAdded);

auto name = iox_getpwuid(geteuid());
auto name = iox_getpwuid(iox_geteuid());
ASSERT_TRUE(name);
PosixUser::userName_t currentUserName(iox::TruncateToCapacity, name->pwd.pw_name);

Expand Down Expand Up @@ -209,11 +209,11 @@ TEST_F(PosixAcl_test, writeSpecialPermissionsWithID)
{
::testing::Test::RecordProperty("TEST_ID", "ef0c7e17-de0e-4cfb-aafa-3e68580660e5");

auto name = iox_getpwuid(geteuid());
auto name = iox_getpwuid(iox_geteuid());
ASSERT_TRUE(name);
std::string currentUserName(name->pwd.pw_name);
uid_t currentUserId(name->pwd.pw_uid);
gid_t groupId = 0; // root
iox_uid_t currentUserId(name->pwd.pw_uid);
iox_gid_t groupId = 0; // root

bool entryAdded = m_accessController.addPermissionEntry(
PosixAcl::Category::SPECIFIC_USER, PosixAcl::Permission::READWRITE, currentUserId);
Expand Down Expand Up @@ -254,7 +254,7 @@ TEST_F(PosixAcl_test, writeSpecialPermissionsWithID)
TEST_F(PosixAcl_test, addNameInWrongPlace)
{
::testing::Test::RecordProperty("TEST_ID", "2d2dbb0d-1fb6-4569-8651-d341a4525ea6");
auto name = iox_getpwuid(geteuid());
auto name = iox_getpwuid(iox_geteuid());
ASSERT_TRUE(name);

m_accessController.addPermissionEntry(PosixAcl::Category::GROUP, PosixAcl::Permission::READ);
Expand Down
8 changes: 5 additions & 3 deletions iceoryx_platform/freertos/include/iceoryx_platform/grp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
#ifndef IOX_HOOFS_FREERTOS_PLATFORM_GRP_HPP
#define IOX_HOOFS_FREERTOS_PLATFORM_GRP_HPP

#include "iceoryx_platform/types.hpp"

struct group
{
const char* gr_name;
const char* gr_passwd;
gid_t gr_gid;
iox_gid_t gr_gid;
const char** gr_mem;
};

Expand All @@ -39,7 +41,7 @@ inline struct group* getgrnam(const char*)
return &dummy;
}

inline struct group* getgrgid(gid_t)
inline struct group* getgrgid(iox_gid_t)
{
static const char* groupName = "iceoryx_freertos_group";
static const char* groupPasswd = "iceoryx_freertos_passwd";
Expand All @@ -51,7 +53,7 @@ inline struct group* getgrgid(gid_t)
return &dummy;
}

inline int iox_getgrouplist(const char*, gid_t, gid_t* groups, int* ngroups)
inline int iox_getgrouplist(const char*, iox_gid_t, iox_gid_t* groups, int* ngroups)
{
groups[0] = 0;
*ngroups = 1;
Expand Down
5 changes: 5 additions & 0 deletions iceoryx_platform/freertos/include/iceoryx_platform/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@
#ifndef IOX_HOOFS_FREERTOS_PLATFORM_TYPES_HPP
#define IOX_HOOFS_FREERTOS_PLATFORM_TYPES_HPP

#include <sys/types.h>

using iox_gid_t = gid_t;
using iox_uid_t = uid_t;

#endif // IOX_HOOFS_FREERTOS_PLATFORM_TYPES_HPP
Loading

0 comments on commit aa6149f

Please sign in to comment.