Skip to content

Commit 28f1c5a

Browse files
authored
Apply sysctls from the OCI spec (#580)
Applies sysctls from the OCI spec.
1 parent 622d102 commit 28f1c5a

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

vminitd/Sources/vmexec/RunCommand.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,23 @@ struct RunCommand: ParsableCommand {
159159
}
160160
}
161161

162+
// Apply sysctls from the OCI spec.
163+
if let sysctls = spec.linux?.sysctl {
164+
for (key, value) in sysctls {
165+
let path = "/proc/sys/" + key.replacingOccurrences(of: ".", with: "/")
166+
let fd = open(path, O_WRONLY)
167+
guard fd >= 0 else {
168+
throw App.Errno(stage: "sysctl open(\(path))")
169+
}
170+
defer { close(fd) }
171+
let bytes = Array(value.utf8)
172+
let written = write(fd, bytes, bytes.count)
173+
guard written == bytes.count else {
174+
throw App.Errno(stage: "sysctl write(\(key)=\(value))")
175+
}
176+
}
177+
}
178+
162179
// Apply O_CLOEXEC to all file descriptors except stdio.
163180
// This ensures that all unwanted fds we may have accidentally
164181
// inherited are marked close-on-exec so they stay out of the

0 commit comments

Comments
 (0)