mirror of
https://github.com/apple/container.git
synced 2026-09-08 00:35:43 +00:00
This change adds documentation to quite a few existing public types that didn't have a blurb before. Additionally, this fixes a couple things that I think either didn't make sense when going to document them: - Rename ConnectionStream to VsockConnectionStream. This type only functions for vsock connections. - Deletes NsLock+Closure. This was not used anywhere. - Rename ContainerizationOCI/Config.swift to ImageConfig.swift. Signed-off-by: Danny Canter <danny_canter@apple.com>
137 lines
3.6 KiB
Swift
137 lines
3.6 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
// Copyright © 2025 Apple Inc. and the containerization project authors. All rights reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import Foundation
|
|
|
|
/// Helper type with utilities to parse and manipulate unix signals.
|
|
public struct Signals {
|
|
public static func allNumeric() -> [Int32] {
|
|
Array(Signals.all.values)
|
|
}
|
|
|
|
public static func parseSignal(_ signal: String) throws -> Int32 {
|
|
if let sig = Int32(signal) {
|
|
if !Signals.all.values.contains(sig) {
|
|
throw Error.invalidSignal(signal)
|
|
}
|
|
return sig
|
|
}
|
|
var signalUpper = signal.uppercased()
|
|
signalUpper.trimPrefix("SIG")
|
|
guard let sig = Signals.all[signalUpper] else {
|
|
throw Error.invalidSignal(signal)
|
|
}
|
|
return sig
|
|
}
|
|
|
|
public enum Error: Swift.Error, CustomStringConvertible {
|
|
case invalidSignal(String)
|
|
|
|
public var description: String {
|
|
switch self {
|
|
case .invalidSignal(let sig):
|
|
return "invalid signal: \(sig)"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#if os(macOS)
|
|
|
|
extension Signals {
|
|
/// all returns all signals for the current platform.
|
|
public static let all: [String: Int32] = [
|
|
"ABRT": SIGABRT,
|
|
"ALRM": SIGALRM,
|
|
"BUS": SIGBUS,
|
|
"CHLD": SIGCHLD,
|
|
"CONT": SIGCONT,
|
|
"EMT": SIGEMT,
|
|
"FPE": SIGFPE,
|
|
"HUP": SIGHUP,
|
|
"ILL": SIGILL,
|
|
"INFO": SIGINFO,
|
|
"INT": SIGINT,
|
|
"IO": SIGIO,
|
|
"IOT": SIGIOT,
|
|
"KILL": SIGKILL,
|
|
"PIPE": SIGPIPE,
|
|
"PROF": SIGPROF,
|
|
"QUIT": SIGQUIT,
|
|
"SEGV": SIGSEGV,
|
|
"STOP": SIGSTOP,
|
|
"SYS": SIGSYS,
|
|
"TERM": SIGTERM,
|
|
"TRAP": SIGTRAP,
|
|
"TSTP": SIGTSTP,
|
|
"TTIN": SIGTTIN,
|
|
"TTOU": SIGTTOU,
|
|
"URG": SIGURG,
|
|
"USR1": SIGUSR1,
|
|
"USR2": SIGUSR2,
|
|
"VTALRM": SIGVTALRM,
|
|
"WINCH": SIGWINCH,
|
|
"XCPU": SIGXCPU,
|
|
"XFSZ": SIGXFSZ,
|
|
]
|
|
}
|
|
|
|
#endif
|
|
|
|
#if os(Linux)
|
|
|
|
extension Signals {
|
|
/// all returns all signals for the current platform.
|
|
public static let all: [String: Int32] = [
|
|
"ABRT": SIGABRT,
|
|
"ALRM": SIGALRM,
|
|
"BUS": SIGBUS,
|
|
"CHLD": SIGCHLD,
|
|
"CLD": SIGCHLD,
|
|
"CONT": SIGCONT,
|
|
"FPE": SIGFPE,
|
|
"HUP": SIGHUP,
|
|
"ILL": SIGILL,
|
|
"INT": SIGINT,
|
|
"IO": SIGIO,
|
|
"IOT": SIGIOT,
|
|
"KILL": SIGKILL,
|
|
"PIPE": SIGPIPE,
|
|
"POLL": SIGPOLL,
|
|
"PROF": SIGPROF,
|
|
"PWR": SIGPWR,
|
|
"QUIT": SIGQUIT,
|
|
"SEGV": SIGSEGV,
|
|
"STKFLT": SIGSTKFLT,
|
|
"STOP": SIGSTOP,
|
|
"SYS": SIGSYS,
|
|
"TERM": SIGTERM,
|
|
"TRAP": SIGTRAP,
|
|
"TSTP": SIGTSTP,
|
|
"TTIN": SIGTTIN,
|
|
"TTOU": SIGTTOU,
|
|
"URG": SIGURG,
|
|
"USR1": SIGUSR1,
|
|
"USR2": SIGUSR2,
|
|
"VTALRM": SIGVTALRM,
|
|
"WINCH": SIGWINCH,
|
|
"XCPU": SIGXCPU,
|
|
"XFSZ": SIGXFSZ,
|
|
]
|
|
}
|
|
|
|
#endif
|