Apply sysctls from the OCI spec (#580)

Applies sysctls from the OCI spec.
This commit is contained in:
Dmitry Kovba authored and GitHub committed 2026-03-12 20:46:16 -07:00
1 parent 622d102b8e
commit 28f1c5a9b5
1 file changed
+17
+17
View File
@@ -159,6 +159,23 @@ struct RunCommand: ParsableCommand {
}
}
// Apply sysctls from the OCI spec.
if let sysctls = spec.linux?.sysctl {
for (key, value) in sysctls {
let path = "/proc/sys/" + key.replacingOccurrences(of: ".", with: "/")
let fd = open(path, O_WRONLY)
guard fd >= 0 else {
throw App.Errno(stage: "sysctl open(\(path))")
}
defer { close(fd) }
let bytes = Array(value.utf8)
let written = write(fd, bytes, bytes.count)
guard written == bytes.count else {
throw App.Errno(stage: "sysctl write(\(key)=\(value))")
}
}
}
// Apply O_CLOEXEC to all file descriptors except stdio.
// This ensures that all unwanted fds we may have accidentally
// inherited are marked close-on-exec so they stay out of the