-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Truncate user and group ids for 64 bit Linux systems #7466
Truncate user and group ids for 64 bit Linux systems #7466
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.
Thanks for the fast PR @klingtnet ! I have a couple suggestions.
38c5364
to
b294e14
Compare
Calls to `getuid`, `getgid` and their `eid` variants fail to compile on 64bit Linux systems because the return value of the syscall is of `usize` and needs to be truncated to fit the size of `uid_t` that is 32 bit. Thanks to @FireFox317 for figuring this out in Zig's Discord channel!
b294e14
to
f1c40ba
Compare
What about a nice test in
|
Sounds fine to me, will address this after work. |
I added a regression test as suggested, unfortunately I could not find any documentation on how to run them. If it does not exist already then there should be some documentation for new contributors. |
You can simply run |
Thank you very much! Test's will probably fail with Side note: The test does not compile with $ zig test lib/std/os/linux/test.zig
./lib/std/os/linux/test.zig:6:13: error: import of file outside package path: '../../std.zig'
const std = @import("../../std.zig");
^
./lib/std/os/linux/test.zig:13:12: note: referenced here
const fs = std.fs;
^
./lib/std/os/linux/test.zig:17:22: note: referenced here
const file = try fs.cwd().createFile(path, .{ .truncate = true, .mode = 0o666 }); |
26d7683
to
e885958
Compare
Yes, some tests are not meant to be run stand-alone. You want to run |
So, to run the tests locally I needed to compile $ pacman -S llvm clang lld
# follow the wiki instructions
$ cmake .. -DZIG_PREFER_CLANG_CPP_DYLIB=True
# wait ... done The test still does not compile: $ build/zig test lib/std/os/linux/test.zig
./lib/std/os/linux/test.zig:105:17: error: use of undeclared identifier 'getauxval'
expectEqual(getauxval(AT_UID), getuid());
^ I imported $ build/zig test lib/std/os/linux/test.zig | clipit
./lib/std/os/linux/test.zig:105:17: error: use of undeclared identifier 'getauxval'
expectEqual(getauxval(AT_UID), getuid());
^ Unfortunately, I could not find a reference to |
You can use
Those are defined in |
This reverts commit 38f93dc.
Seems to work fine now: $ build/zig test lib/std/os/linux/test.zig
All 5 tests passed.
s1 alinz@kn-portable |
I need to fix the failing CI test:
|
The problem is in the Lines 37 to 49 in 506af7e
As you can see the |
Oh this is some other |
* Truncate user and group ids Calls to `getuid`, `getgid` and their `eid` variants fail to compile on 64bit Linux systems because the return value of the syscall is of `usize` and needs to be truncated to fit the size of `uid_t` that is 32 bit. Thanks to @FireFox317 for figuring this out in Zig's Discord channel! * Add a regression test for user and group ids * Replace @truncate with @intcast This should be safe because `uid_t` will be 32-bit. * Add missing import for getauxval * Add missing package names * Revert "Add missing import for getauxval" This reverts commit 38f93dc. * Skip user and group test if builtin.link_libc
Calls to
getuid
,getgid
and theireid
variants fail to compile on64bit Linux systems because the return value of the syscall is of
usize
and needs to be truncated to fit the size ofuid_t
that is 32bit.
Thanks to @FireFox317 for figuring this out in Zig's Discord channel!
TODO