mirror of
https://github.com/apple/container.git
synced 2026-10-17 19:49:20 +00:00
Apply sysctls from the OCI spec (#580)
Applies sysctls from the OCI spec.
This commit is contained in:
1 parent
622d102b8e
commit
28f1c5a9b5
1 file changed
+17
@@ -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
|
||||
|
||||
Reference in new issue
Block a user