Skip to content

test: parse WSL kernel version without error #24042

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion lib/std/os/linux/IoUring.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4065,7 +4065,22 @@ inline fn skipKernelLessThan(required: std.SemanticVersion) !void {
const release = mem.sliceTo(&uts.release, 0);
// Strips potential extra, as kernel version might not be semver compliant, example "6.8.9-300.fc40.x86_64"
const extra_index = std.mem.indexOfAny(u8, release, "-+");
const stripped = release[0..(extra_index orelse release.len)];

// Also strips the string after the third dot because examples exist such as "6.6.87.1-microsoft-standard-WSL2"
var dot_count: usize = 0;
var index: usize = 0;
var third_dot_index: ?usize = null;
while (std.mem.indexOfScalar(u8, release[index..], '.')) |addend| {
index += addend;
dot_count += 1;
if (dot_count == 3) {
third_dot_index = index;
break;
}
index += 1;
}

const stripped = release[0..(@min(extra_index orelse release.len, third_dot_index orelse release.len))];
// Make sure the input don't rely on the extra we just stripped
try testing.expect(required.pre == null and required.build == null);

Expand Down
Loading