Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

posix: options: implement POSIX_SYSTEM_DATABASE_R #84858

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions doc/services/portability/posix/option_groups/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,22 @@ Enable this option group with :kconfig:option:`CONFIG_POSIX_SPIN_LOCKS`.
pthread_spin_trylock(),yes
pthread_spin_unlock(),yes

.. _posix_option_group_system_database_r:

POSIX_SYSTEM_DATABASE_R
+++++++++++++++++++++++

Enable this option group with :kconfig:option:`CONFIG_POSIX_SYSTEM_DATABASE_R`.

.. csv-table:: POSIX_SYSTEM_DATABASE_R
:header: API, Supported
:widths: 50,10

getgrgid_r(),yes
getgrnam_r(),yes
getpwnam_r(),yes
getpwuid_r(),yes

.. _posix_option_group_threads_base:

POSIX_THREADS_BASE
Expand Down
12 changes: 11 additions & 1 deletion include/zephyr/posix/grp.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2024 Meta Platforms
* Copyright (c) 2024 Tenstorrent AI ULC
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -24,9 +25,18 @@ struct group {
char **gr_mem;
};

#if defined(_XOPEN_SOURCE)
void endgrent(void);
struct group *getgrent(void);
#endif
struct group *getgrgid(gid_t gid);
int getgrgid_r(gid_t gid, struct group *grp, char *buffer, size_t bufsize, struct group **result);
struct group *getgrnam(const char *name);
int getgrnam_r(const char *name, struct group *grp, char *buffer, size_t bufsize,
struct group **result);
int getgrgid_r(gid_t gid, struct group *grp, char *buffer, size_t bufsize, struct group **result);
#if defined(_XOPEN_SOURCE)
void setgrent(void);
#endif

#ifdef __cplusplus
}
Expand Down
12 changes: 11 additions & 1 deletion include/zephyr/posix/pwd.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2024 Meta Platforms
* Copyright (c) 2024 Tenstorrent AI ULC
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -25,9 +26,18 @@ struct passwd {
char *pw_shell;
};

int getpwnam_r(const char *nam, struct passwd *pwd, char *buffer, size_t bufsize,
#if defined(_XOPEN_SOURCE)
void endpwent(void);
struct passwd *getpwent(void);
#endif
struct passwd *getpwnam(const char *name);
int getpwnam_r(const char *name, struct passwd *pwd, char *buffer, size_t bufsize,
struct passwd **result);
struct passwd *getpwuid(uid_t uid);
int getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result);
#if defined(_XOPEN_SOURCE)
void setpwent(void);
#endif

#ifdef __cplusplus
}
Expand Down
4 changes: 2 additions & 2 deletions include/zephyr/posix/sys/sysconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ enum {
#define __z_posix_sysconf_SC_XOPEN_UUCP (-1L)
#define __z_posix_sysconf_SC_XOPEN_VERSION _XOPEN_VERSION
#define __z_posix_sysconf_SC_CLK_TCK (100L)
#define __z_posix_sysconf_SC_GETGR_R_SIZE_MAX (0L)
#define __z_posix_sysconf_SC_GETPW_R_SIZE_MAX (0L)
#define __z_posix_sysconf_SC_GETGR_R_SIZE_MAX CONFIG_POSIX_GETGR_R_SIZE_MAX
#define __z_posix_sysconf_SC_GETPW_R_SIZE_MAX CONFIG_POSIX_GETPW_R_SIZE_MAX
#define __z_posix_sysconf_SC_AIO_LISTIO_MAX AIO_LISTIO_MAX
#define __z_posix_sysconf_SC_AIO_MAX AIO_MAX
#define __z_posix_sysconf_SC_AIO_PRIO_DELTA_MAX AIO_PRIO_DELTA_MAX
Expand Down
9 changes: 7 additions & 2 deletions lib/posix/options/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ if (NOT CONFIG_TC_PROVIDES_POSIX_SPIN_LOCKS)
zephyr_library_sources_ifdef(CONFIG_POSIX_SPIN_LOCKS spinlock.c)
endif()

if (NOT CONFIG_TC_PROVIDES_POSIX_SYSTEM_DATABASE_R)
zephyr_library_sources_ifdef(CONFIG_POSIX_SYSTEM_DATABASE_R
system_database_priv.c
system_database_r.c
)
endif()

if (NOT CONFIG_TC_PROVIDES_POSIX_TIMERS)
zephyr_library_sources_ifdef(CONFIG_POSIX_TIMERS
clock.c
Expand All @@ -146,11 +153,9 @@ if (NOT CONFIG_TC_PROVIDES_POSIX_THREADS)
# We have opted to use POSIX_THREADS here to match the Option name.
zephyr_library_sources_ifdef(CONFIG_POSIX_THREADS
cond.c
grp.c
key.c
mutex.c
pthread.c
pwd.c
)
endif()

Expand Down
1 change: 1 addition & 0 deletions lib/posix/options/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ rsource "Kconfig.semaphore"
rsource "Kconfig.signal"
rsource "Kconfig.spinlock"
rsource "Kconfig.sync_io"
rsource "Kconfig.system_database_r"
rsource "Kconfig.timer"
rsource "Kconfig.xsi"

Expand Down
42 changes: 42 additions & 0 deletions lib/posix/options/Kconfig.system_database_r
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright (c) 2024 Tenstorrent AI ULC
#
# SPDX-License-Identifier: Apache-2.0

config POSIX_SYSTEM_DATABASE_R
bool "POSIX System Database"
help
Select 'y' here, and the system will support getgrgid_r(), getgrnam_r(), getpwnam_r(), and
getpwuid_r().

For more information, please see
https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html

config POSIX_GETGR_R_SIZE_MAX
int "Initial size of getgrgid_r() and getgrnam_r() data buffers"
default 96
help
This option sets the maximum size of the buffer for getgrgid_r() and getgrnam_r().

The default size is derived from the formula below. Note, that the home directory and
shell fields are not based on PATH_MAX, which can be excessively large.

_POSIX_LOGIN_NAME_MAX + 1 +
sizeof(void *) +
sizeof("4294967295") + 1 +
2 * (_POSIX_NAME_MAX + 1 + sizeof(void *))
+ sizeof(void *)

config POSIX_GETPW_R_SIZE_MAX
int "Initial size of getpwnam_r() and getpwuid_r() data buffers"
default 64
help
This option sets the maximum size of the buffer for getpwnam_r() and getpwuid_r().

The default size is derived from the formula below. Note, that the home directory and
shell fields are not based on PATH_MAX, which can be excessively large.

_POSIX_LOGIN_NAME_MAX + 1 +
sizeof("4294967295") + 1 +
sizeof("4294967295") + 1 +
_POSIX_NAME_MAX + 1 +
_POSIX_NAME_MAX + 1
37 changes: 0 additions & 37 deletions lib/posix/options/grp.c

This file was deleted.

37 changes: 0 additions & 37 deletions lib/posix/options/pwd.c

This file was deleted.

Loading
Loading