File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515//===----------------------------------------------------------------------===//
1616
1717import FoundationEssentials
18+
19+ #if canImport(Musl)
1820import Musl
21+ private let _close = Musl . close
22+ #elseif canImport(Glibc)
23+ import Glibc
24+ private let _close = Glibc . close
25+ #endif
1926
2027class Console {
2128 let master : Int32
@@ -45,7 +52,7 @@ class Console {
4552 guard slaveFD != - 1 else {
4653 throw App . Errno ( stage: " open_pts " )
4754 }
48- defer { Musl . close ( slaveFD) }
55+ defer { _ = _close ( slaveFD) }
4956
5057 for fd : Int32 in 0 ... 2 {
5158 guard dup3 ( slaveFD, fd, 0 ) != - 1 else {
@@ -55,7 +62,7 @@ class Console {
5562 }
5663
5764 func close( ) throws {
58- guard Musl . close ( self . master) == 0 else {
65+ guard _close ( self . master) == 0 else {
5966 throw App . Errno ( stage: " close " )
6067 }
6168 }
Original file line number Diff line number Diff line change @@ -20,9 +20,14 @@ import ContainerizationOS
2020import FoundationEssentials
2121import LCShim
2222import Logging
23- import Musl
2423import SystemPackage
2524
25+ #if canImport(Musl)
26+ import Musl
27+ #elseif canImport(Glibc)
28+ import Glibc
29+ #endif
30+
2631struct ExecCommand : ParsableCommand {
2732 static let configuration = CommandConfiguration (
2833 commandName: " exec " ,
Original file line number Diff line number Diff line change 1717import ContainerizationOCI
1818import ContainerizationOS
1919import FoundationEssentials
20+
21+ #if canImport(Musl)
2022import Musl
23+ #elseif canImport(Glibc)
24+ import Glibc
25+ #endif
2126
2227struct ContainerMount {
2328 private let mounts : [ ContainerizationOCI . Mount ]
Original file line number Diff line number Diff line change @@ -20,9 +20,14 @@ import ContainerizationOCI
2020import ContainerizationOS
2121import FoundationEssentials
2222import LCShim
23- import Musl
2423import SystemPackage
2524
25+ #if canImport(Musl)
26+ import Musl
27+ #elseif canImport(Glibc)
28+ import Glibc
29+ #endif
30+
2631struct RunCommand : ParsableCommand {
2732 static let configuration = CommandConfiguration (
2833 commandName: " run " ,
@@ -152,7 +157,7 @@ struct RunCommand: ParsableCommand {
152157
153158 if !spec. hostname. isEmpty {
154159 let errCode = spec. hostname. withCString { ptr in
155- Musl . sethostname ( ptr, spec. hostname. count)
160+ sethostname ( ptr, spec. hostname. count)
156161 }
157162 guard errCode == 0 else {
158163 throw App . Errno ( stage: " sethostname() " )
Original file line number Diff line number Diff line change @@ -26,9 +26,14 @@ import ContainerizationOS
2626import FoundationEssentials
2727import LCShim
2828import Logging
29- import Musl
3029import SystemPackage
3130
31+ #if canImport(Musl)
32+ import Musl
33+ #elseif canImport(Glibc)
34+ import Glibc
35+ #endif
36+
3237@main
3338struct App : ParsableCommand {
3439 static let ackPid = " AckPid "
Original file line number Diff line number Diff line change @@ -26,7 +26,11 @@ import NIOCore
2626import NIOPosix
2727
2828#if os(Linux)
29+ #if canImport(Musl)
2930import Musl
31+ #elseif canImport(Glibc)
32+ import Glibc
33+ #endif
3034import LCShim
3135#endif
3236
@@ -157,13 +161,13 @@ struct AgentCommand: AsyncParsableCommand {
157161 log. info ( " vminitd API returned, syncing filesystems " )
158162
159163 #if os(Linux)
160- Musl . sync ( )
164+ sync ( )
161165 #endif
162166 } catch {
163167 log. error ( " vminitd boot error \( error) " )
164168
165169 #if os(Linux)
166- Musl . sync ( )
170+ sync ( )
167171 #endif
168172
169173 _exit ( 1 )
Original file line number Diff line number Diff line change 1717import ArgumentParser
1818import ContainerizationOS
1919import LCShim
20+
21+ #if canImport(Musl)
2022import Musl
23+ private let _exit = Musl . exit
24+ private let _kill = Musl . kill
25+ #elseif canImport(Glibc)
26+ import Glibc
27+ private let _exit = Glibc . exit
28+ private let _kill = Glibc . kill
29+ #endif
2130
2231/// A minimal init process that:
2332/// - Spawns and monitors a child process
@@ -78,7 +87,7 @@ struct InitCommand: ParsableCommand {
7887 let sig = sigtimedwait ( & allSignals, & siginfo, & timeout)
7988
8089 if sig > 0 && !Self. ignoredSignals. contains ( sig) {
81- _ = Musl . kill ( signalTarget, sig)
90+ _ = _kill ( signalTarget, sig)
8291 }
8392
8493 while true {
@@ -93,6 +102,6 @@ struct InitCommand: ParsableCommand {
93102 }
94103 }
95104
96- Musl . exit ( childExitStatus ?? 1 )
105+ _exit ( childExitStatus ?? 1 )
97106 }
98107}
Original file line number Diff line number Diff line change 1717import ArgumentParser
1818import Dispatch
1919import Logging
20+
21+ #if canImport(Musl)
2022import Musl
23+ private let _exit = Musl . exit
24+ #elseif canImport(Glibc)
25+ import Glibc
26+ private let _exit = Glibc . exit
27+ #endif
2128
2229struct PauseCommand : ParsableCommand {
2330 static let configuration = CommandConfiguration (
@@ -39,14 +46,14 @@ struct PauseCommand: ParsableCommand {
3946 let sigintSource = DispatchSource . makeSignalSource ( signal: SIGINT)
4047 sigintSource. setEventHandler {
4148 log. info ( " Shutting down, got SIGINT " )
42- Musl . exit ( 0 )
49+ _exit ( 0 )
4350 }
4451 sigintSource. resume ( )
4552
4653 let sigtermSource = DispatchSource . makeSignalSource ( signal: SIGTERM)
4754 sigtermSource. setEventHandler {
4855 log. info ( " Shutting down, got SIGTERM " )
49- Musl . exit ( 0 )
56+ _exit ( 0 )
5057 }
5158 sigtermSource. resume ( )
5259
@@ -60,10 +67,10 @@ struct PauseCommand: ParsableCommand {
6067 log. info ( " pause container running, waiting for signals... " )
6168
6269 while true {
63- Musl . pause ( )
70+ _ = pause ( )
6471 }
6572
6673 log. error ( " Error: infinite loop terminated " )
67- Musl . exit ( 42 )
74+ _exit ( 42 )
6875 }
6976}
You can’t perform that action at this time.
0 commit comments