-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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: env: support for environ, getenv(), setenv(), unsetenv() #66762
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cfriedt
requested review from
jakub-uC,
keith-packard,
stephanosio,
ycsin and
jgl-meta
December 21, 2023 16:37
cfriedt
force-pushed
the
setenv
branch
2 times, most recently
from
December 21, 2023 16:47
51df4f7
to
64111f4
Compare
zephyrbot
added
area: Shell
Shell subsystem
area: C Library
C Standard Library
area: POSIX
POSIX API Library
labels
Dec 21, 2023
cfriedt
commented
Dec 21, 2023
cfriedt
force-pushed
the
setenv
branch
2 times, most recently
from
December 21, 2023 18:21
7e0f165
to
02aaed3
Compare
This comment was marked as resolved.
This comment was marked as resolved.
cfriedt
commented
Dec 21, 2023
This comment was marked as off-topic.
This comment was marked as off-topic.
aescolar
previously requested changes
Dec 22, 2023
This comment was marked as off-topic.
This comment was marked as off-topic.
ycsin
previously approved these changes
Jan 31, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks - I'll rebase to fix merge conflicts 😄 |
@ycsin - I also created a sample application (borrowed from your uname sample) |
ycsin
previously approved these changes
Feb 5, 2024
jukkar
reviewed
Mar 7, 2024
Support getting and setting POSIX environment variables. Additionally, the thread-safe BSD variant getenv_r() is provided. environ, getenv(), setenv(), and unsetenv() are required by the POSIX_SINGLE_PROCESS Option Group as detailed in Section E.1 of IEEE-1003.1-2017. The POSIX_SINGLE_PROCESS Option Group is required for PSE51, PSE52, PSE53, and PSE54 conformance, and is otherwise mandatory for any POSIX conforming system as per Section A.2.1.3 of IEEE-1003-1.2017. Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Add tests for environ, getenv(), setenv(), unsetenv(), and getenv_r(). Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Mark environ, getenv(), setevn(), and unsetenv as supported. Signed-off-by: Christopher Friedt <cfriedt@meta.com>
This service is used to get, set, and unset system environment variables. Note: shell parameter expansion is not supported at this time. Signed-off-by: Christopher Friedt <cfriedt@meta.com>
This PR adds declarations for the application conformance feature test macro _POSIX_C_SOURCE. It needs to be defined to value greater than or equal to 200112L by the appplication. However, Zephyr currently does not have a simple and consistent means of specifying this value for POSIX samples, tests, applications, and other libraries. Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Add a sample application to demonstrate some basic C and shell interfaces for manipulating environment variables. Signed-off-by: Christopher Friedt <cfriedt@meta.com>
|
ycsin
approved these changes
Mar 7, 2024
jukkar
approved these changes
Mar 8, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area: C Library
C Standard Library
area: POSIX
POSIX API Library
area: Samples
Samples
area: Shell
Shell subsystem
area: Tests
Issues related to a particular existing or missing test
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Note: Coding Guidelines failures are false positives
Support getting and setting POSIX environment variables. Additionally, the thread-safe BSD variant
getenv_r()
is provided.environ
,getenv()
,setenv()
, andunsetenv()
are required by thePOSIX_SINGLE_PROCESS
Option Group as detailed in Section E.1 of IEEE-1003.1-2017.The
POSIX_SINGLE_PROCESS
Option Group is required for PSE51, PSE52, PSE53, and PSE54 conformance, and is otherwise mandatory for any POSIX conforming system as per Section A.2.1.3 of IEEE-1003-1.2017.This lets us do fun things like what is shown below in the Zephyr shell:
App and library code can then query values from the environment, as a relatively simple and portable way of steering the behaviour of code at runtime.
Some notes:
echo "$VALUE"
will not work as one might expectPossible future improvements:
env get <tab>
HOME
,PWD
, ...).$RANDOM
.Fixes #66861
Fixes #66862
Fixes #66863
Fixes #66864