Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions vminitd/Sources/vmexec/Console.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
//===----------------------------------------------------------------------===//

import FoundationEssentials

#if canImport(Musl)
import Musl
private let _close = Musl.close
#elseif canImport(Glibc)
import Glibc
private let _close = Glibc.close
#endif

class Console {
let master: Int32
Expand Down Expand Up @@ -45,7 +52,7 @@ class Console {
guard slaveFD != -1 else {
throw App.Errno(stage: "open_pts")
}
defer { Musl.close(slaveFD) }
defer { _ = _close(slaveFD) }

for fd: Int32 in 0...2 {
guard dup3(slaveFD, fd, 0) != -1 else {
Expand All @@ -55,7 +62,7 @@ class Console {
}

func close() throws {
guard Musl.close(self.master) == 0 else {
guard _close(self.master) == 0 else {
throw App.Errno(stage: "close")
}
}
Expand Down
7 changes: 6 additions & 1 deletion vminitd/Sources/vmexec/ExecCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ import ContainerizationOS
import FoundationEssentials
import LCShim
import Logging
import Musl
import SystemPackage

#if canImport(Musl)
import Musl
#elseif canImport(Glibc)
import Glibc
#endif

struct ExecCommand: ParsableCommand {
static let configuration = CommandConfiguration(
commandName: "exec",
Expand Down
5 changes: 5 additions & 0 deletions vminitd/Sources/vmexec/Mount.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
import ContainerizationOCI
import ContainerizationOS
import FoundationEssentials

#if canImport(Musl)
import Musl
#elseif canImport(Glibc)
import Glibc
#endif

struct ContainerMount {
private let mounts: [ContainerizationOCI.Mount]
Expand Down
9 changes: 7 additions & 2 deletions vminitd/Sources/vmexec/RunCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ import ContainerizationOCI
import ContainerizationOS
import FoundationEssentials
import LCShim
import Musl
import SystemPackage

#if canImport(Musl)
import Musl
#elseif canImport(Glibc)
import Glibc
#endif

struct RunCommand: ParsableCommand {
static let configuration = CommandConfiguration(
commandName: "run",
Expand Down Expand Up @@ -152,7 +157,7 @@ struct RunCommand: ParsableCommand {

if !spec.hostname.isEmpty {
let errCode = spec.hostname.withCString { ptr in
Musl.sethostname(ptr, spec.hostname.count)
sethostname(ptr, spec.hostname.count)
}
guard errCode == 0 else {
throw App.Errno(stage: "sethostname()")
Expand Down
7 changes: 6 additions & 1 deletion vminitd/Sources/vmexec/vmexec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ import ContainerizationOS
import FoundationEssentials
import LCShim
import Logging
import Musl
import SystemPackage

#if canImport(Musl)
import Musl
#elseif canImport(Glibc)
import Glibc
#endif

@main
struct App: ParsableCommand {
static let ackPid = "AckPid"
Expand Down
8 changes: 6 additions & 2 deletions vminitd/Sources/vminitd/AgentCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ import NIOCore
import NIOPosix

#if os(Linux)
#if canImport(Musl)
import Musl
#elseif canImport(Glibc)
import Glibc
#endif
import LCShim
#endif

Expand Down Expand Up @@ -157,13 +161,13 @@ struct AgentCommand: AsyncParsableCommand {
log.info("vminitd API returned, syncing filesystems")

#if os(Linux)
Musl.sync()
sync()
#endif
} catch {
log.error("vminitd boot error \(error)")

#if os(Linux)
Musl.sync()
sync()
#endif

_exit(1)
Expand Down
13 changes: 11 additions & 2 deletions vminitd/Sources/vminitd/InitCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@
import ArgumentParser
import ContainerizationOS
import LCShim

#if canImport(Musl)
import Musl
private let _exit = Musl.exit
private let _kill = Musl.kill
#elseif canImport(Glibc)
import Glibc
private let _exit = Glibc.exit
private let _kill = Glibc.kill
#endif

/// A minimal init process that:
/// - Spawns and monitors a child process
Expand Down Expand Up @@ -78,7 +87,7 @@ struct InitCommand: ParsableCommand {
let sig = sigtimedwait(&allSignals, &siginfo, &timeout)

if sig > 0 && !Self.ignoredSignals.contains(sig) {
_ = Musl.kill(signalTarget, sig)
_ = _kill(signalTarget, sig)
}

while true {
Expand All @@ -93,6 +102,6 @@ struct InitCommand: ParsableCommand {
}
}

Musl.exit(childExitStatus ?? 1)
_exit(childExitStatus ?? 1)
}
}
15 changes: 11 additions & 4 deletions vminitd/Sources/vminitd/PauseCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@
import ArgumentParser
import Dispatch
import Logging

#if canImport(Musl)
import Musl
private let _exit = Musl.exit
#elseif canImport(Glibc)
import Glibc
private let _exit = Glibc.exit
#endif

struct PauseCommand: ParsableCommand {
static let configuration = CommandConfiguration(
Expand All @@ -39,14 +46,14 @@ struct PauseCommand: ParsableCommand {
let sigintSource = DispatchSource.makeSignalSource(signal: SIGINT)
sigintSource.setEventHandler {
log.info("Shutting down, got SIGINT")
Musl.exit(0)
_exit(0)
}
sigintSource.resume()

let sigtermSource = DispatchSource.makeSignalSource(signal: SIGTERM)
sigtermSource.setEventHandler {
log.info("Shutting down, got SIGTERM")
Musl.exit(0)
_exit(0)
}
sigtermSource.resume()

Expand All @@ -60,10 +67,10 @@ struct PauseCommand: ParsableCommand {
log.info("pause container running, waiting for signals...")

while true {
Musl.pause()
_ = pause()
}

log.error("Error: infinite loop terminated")
Musl.exit(42)
_exit(42)
}
}
Loading