lib: posix: add stubs for thread-safe grp & pwd functions
Create stubs for getpwnam_r, getpwuid_r, getgrgid_r & getgrnam_r. These functions are in the _POSIX_THREAD_SAFE_FUNCTIONS option group. Signed-off-by: Yong Cong Sin <ycsin@meta.com>
This commit is contained in:
parent
b7ad4c53b0
commit
2ccfe8202d
8 changed files with 187 additions and 4 deletions
|
@ -988,10 +988,10 @@ Enable this option with :kconfig:option:`CONFIG_POSIX_THREAD_SAFE_FUNCTIONS`.
|
||||||
funlockfile(),
|
funlockfile(),
|
||||||
getc_unlocked(),
|
getc_unlocked(),
|
||||||
getchar_unlocked(),
|
getchar_unlocked(),
|
||||||
getgrgid_r(),
|
getgrgid_r(),yes :ref:`†<posix_undefined_behaviour>`
|
||||||
getgrnam_r(),
|
getgrnam_r(),yes :ref:`†<posix_undefined_behaviour>`
|
||||||
getpwnam_r(),
|
getpwnam_r(),yes :ref:`†<posix_undefined_behaviour>`
|
||||||
getpwuid_r(),
|
getpwuid_r(),yes :ref:`†<posix_undefined_behaviour>`
|
||||||
gmtime_r(), yes
|
gmtime_r(), yes
|
||||||
localtime_r(),
|
localtime_r(),
|
||||||
putc_unlocked(),
|
putc_unlocked(),
|
||||||
|
|
35
include/zephyr/posix/grp.h
Normal file
35
include/zephyr/posix/grp.h
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Meta Platforms
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef ZEPHYR_INCLUDE_POSIX_GRP_H_
|
||||||
|
#define ZEPHYR_INCLUDE_POSIX_GRP_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <zephyr/posix/sys/stat.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Group structure
|
||||||
|
*/
|
||||||
|
struct group {
|
||||||
|
/**< the name of the group */
|
||||||
|
char *gr_name;
|
||||||
|
/**< numerical group ID */
|
||||||
|
gid_t gr_gid;
|
||||||
|
/**< pointer to a null-terminated array of character pointers to member names */
|
||||||
|
char **gr_mem;
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* ZEPHYR_INCLUDE_POSIX_GRP_H_ */
|
36
include/zephyr/posix/pwd.h
Normal file
36
include/zephyr/posix/pwd.h
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Meta Platforms
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
#ifndef ZEPHYR_INCLUDE_POSIX_PWD_H_
|
||||||
|
#define ZEPHYR_INCLUDE_POSIX_PWD_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <zephyr/posix/sys/stat.h>
|
||||||
|
|
||||||
|
struct passwd {
|
||||||
|
/* user's login name */
|
||||||
|
char *pw_name;
|
||||||
|
/* numerical user ID */
|
||||||
|
uid_t pw_uid;
|
||||||
|
/* numerical group ID */
|
||||||
|
gid_t pw_gid;
|
||||||
|
/* initial working directory */
|
||||||
|
char *pw_dir;
|
||||||
|
/* program to use as shell */
|
||||||
|
char *pw_shell;
|
||||||
|
};
|
||||||
|
|
||||||
|
int getpwnam_r(const char *nam, struct passwd *pwd, char *buffer, size_t bufsize,
|
||||||
|
struct passwd **result);
|
||||||
|
int getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* ZEPHYR_INCLUDE_POSIX_PWD_H_ */
|
|
@ -142,9 +142,11 @@ if (NOT CONFIG_TC_PROVIDES_POSIX_THREADS)
|
||||||
# We have opted to use POSIX_THREADS here to match the Option name.
|
# We have opted to use POSIX_THREADS here to match the Option name.
|
||||||
zephyr_library_sources_ifdef(CONFIG_POSIX_THREADS
|
zephyr_library_sources_ifdef(CONFIG_POSIX_THREADS
|
||||||
cond.c
|
cond.c
|
||||||
|
grp.c
|
||||||
key.c
|
key.c
|
||||||
mutex.c
|
mutex.c
|
||||||
pthread.c
|
pthread.c
|
||||||
|
pwd.c
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
37
lib/posix/options/grp.c
Normal file
37
lib/posix/options/grp.c
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Meta Platforms
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <zephyr/sys/util.h>
|
||||||
|
#include <zephyr/posix/grp.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_POSIX_THREAD_SAFE_FUNCTIONS
|
||||||
|
|
||||||
|
int getgrnam_r(const char *name, struct group *grp, char *buffer, size_t bufsize,
|
||||||
|
struct group **result)
|
||||||
|
{
|
||||||
|
ARG_UNUSED(name);
|
||||||
|
ARG_UNUSED(grp);
|
||||||
|
ARG_UNUSED(buffer);
|
||||||
|
ARG_UNUSED(bufsize);
|
||||||
|
ARG_UNUSED(result);
|
||||||
|
|
||||||
|
return ENOSYS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getgrgid_r(gid_t gid, struct group *grp, char *buffer, size_t bufsize, struct group **result)
|
||||||
|
{
|
||||||
|
ARG_UNUSED(gid);
|
||||||
|
ARG_UNUSED(grp);
|
||||||
|
ARG_UNUSED(buffer);
|
||||||
|
ARG_UNUSED(bufsize);
|
||||||
|
ARG_UNUSED(result);
|
||||||
|
|
||||||
|
return ENOSYS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_POSIX_THREAD_SAFE_FUNCTIONS */
|
37
lib/posix/options/pwd.c
Normal file
37
lib/posix/options/pwd.c
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Meta Platforms
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <zephyr/sys/util.h>
|
||||||
|
#include <zephyr/posix/pwd.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_POSIX_THREAD_SAFE_FUNCTIONS
|
||||||
|
|
||||||
|
int getpwnam_r(const char *nam, struct passwd *pwd, char *buffer, size_t bufsize,
|
||||||
|
struct passwd **result)
|
||||||
|
{
|
||||||
|
ARG_UNUSED(nam);
|
||||||
|
ARG_UNUSED(pwd);
|
||||||
|
ARG_UNUSED(buffer);
|
||||||
|
ARG_UNUSED(bufsize);
|
||||||
|
ARG_UNUSED(result);
|
||||||
|
|
||||||
|
return ENOSYS;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
|
||||||
|
{
|
||||||
|
ARG_UNUSED(uid);
|
||||||
|
ARG_UNUSED(pwd);
|
||||||
|
ARG_UNUSED(buffer);
|
||||||
|
ARG_UNUSED(bufsize);
|
||||||
|
ARG_UNUSED(result);
|
||||||
|
|
||||||
|
return ENOSYS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_POSIX_THREAD_SAFE_FUNCTIONS */
|
18
tests/posix/common/src/grp.c
Normal file
18
tests/posix/common/src/grp.c
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Meta Platforms
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <grp.h>
|
||||||
|
|
||||||
|
#include <zephyr/ztest.h>
|
||||||
|
|
||||||
|
ZTEST(grp, test_grp_stubs)
|
||||||
|
{
|
||||||
|
zassert_equal(getgrnam_r(NULL, NULL, NULL, 42, NULL), ENOSYS);
|
||||||
|
zassert_equal(getgrgid_r(42, NULL, NULL, 42, NULL), ENOSYS);
|
||||||
|
}
|
||||||
|
|
||||||
|
ZTEST_SUITE(grp, NULL, NULL, NULL, NULL, NULL);
|
18
tests/posix/common/src/pwd.c
Normal file
18
tests/posix/common/src/pwd.c
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Meta Platforms
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <pwd.h>
|
||||||
|
|
||||||
|
#include <zephyr/ztest.h>
|
||||||
|
|
||||||
|
ZTEST(pwd, test_pwd_stubs)
|
||||||
|
{
|
||||||
|
zassert_equal(getpwnam_r(NULL, NULL, NULL, 42, NULL), ENOSYS);
|
||||||
|
zassert_equal(getpwuid_r(42, NULL, NULL, 42, NULL), ENOSYS);
|
||||||
|
}
|
||||||
|
|
||||||
|
ZTEST_SUITE(pwd, NULL, NULL, NULL, NULL, NULL);
|
Loading…
Add table
Add a link
Reference in a new issue