-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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: implement uname
#59981
posix: implement uname
#59981
Conversation
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 - just a couple of nits and suggestions.
The sample is good, but it would also be good to add to the testsuite.
One tricky area in particular is the version string.
We actually do want to be fairly consistent here with e.g. the boot banner.
So it would make sense to detect and modify the string such that we can display
- a tagged release (e.g.
v3.5.0
) - something commit-ish (IIRC git short ref plus epoch time? I can't remember)
- whether the build is dirty (Linux uses a
+
, not sure how Zephyr does it)
Of possible, can you please also update doc/services/portability/posix.rst
?
Great work! Thanks @ycsin 🚀🪁👍🍍
Some compliance fixes.. |
IIRC, we cannot yet build for |
58c7e3e
to
ed10e85
Compare
The
Should be covered by:
Not epoch time though..
Looks like something to be done in the build system, not sure if @tejlmand has any idea? |
80b4cbd
to
ee95091
Compare
c5df7b4
to
87237ae
Compare
Adding But the use-case / reason for not having As people has various ways of working / verifying patches, then I think a wider audience should be invited to discuss if we want to have |
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.
the strncpy usage needs to be fixed, otherwise my comments are just suggestions.
include/zephyr/posix/sys/utsname.h
Outdated
char sysname[sizeof("Zephyr")]; | ||
char nodename[CONFIG_POSIX_UNAME_NODENAME_LEN]; | ||
char release[sizeof("99.99.99")]; | ||
char version[CONFIG_POSIX_UNAME_VERSION_LEN]; |
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.
I think the size of this field can also be computed -- just need to insert the computation of the version string into this header. One less config value to deal with seems like a nice thing.
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.
We can actually compute everything using preprocessor defines here, at the expense of including 2 more headers & some macro magic then looks a bit complicated
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.
The version field can be fixed size as well, technically, too, if we omit the date and time, and it's compatible with the banner version as well.
char version[sizeof("zephyr-v99.99.99-9999-g0123456789ab")];
Ideally we could just include <version.h>
, which is generated at build time and use the exact #define
s that appear there.
I'm hesitant to do that, just because it really isn't referenced outside of banner.c
, which gives me the impression that it's private somehow.
If that makes life easier though, by all means, just
struct utsname {
char sysname[sizeof("Zephyr")];
char nodename[CONFIG_POSIX_UNAME_NODENAME_LEN + 1];
char release[sizeof(KERNEL_VERSION_STRING)];
char version[sizeof(STRINGIFY(BUILD_VERSION))];
char machine[sizeof(CONFIG_ARCH)];
};
And honestly, the __DATE__
and __TIME__
macros are probably not super critical.
I would be less hesitant to include <version.h>
if it were namespaced properly (e.g. <zephyr/kernel/build_version.h>
).
At the same time, there is plenty of time to improve things before v3.5.0, so no need to stall here.
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.
__DATE__
and __TIME__
break build reproducibility and should not be enabled by default (not sure what is the current situation)
how about having a separate define to indicate this in "version.h", rather than appending to the hash directly? |
Did you read the links ? Even if placing this info in a separate define to use in So if this is to be changed, then please open a dedicated issue for discussing, and not in this PR. |
Add implementation for posix uname. Signed-off-by: Yong Cong Sin <ycsin@meta.com>
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.
One minor change request
Add a simple, testable sample to print everything in the utsname struct, and added a `uname` shell cmd basically copied from nuttx just for fun. Signed-off-by: Yong Cong Sin <ycsin@meta.com>
add ztest for uname api Signed-off-by: Yong Cong Sin <ycsin@meta.com>
@keith-packard - does this one look OK to you now? |
@ycsin - I'm OK getting 1 more approval for this and merging if you wouldn't mind a follow-up PR for namespacing |
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.
Yeah, given the concerns about mixing too many bits into the application namespace, having compile-time checks that make sure the sizes are big enough seems good enough here.
Implementation for posix api:
uname
MacOS as a reference:
fixes #59924
doc/services/portability/posix.rst