@@ -220,18 +220,13 @@ public actor SandboxService {
220220 czConfig. process. stdout = stdout
221221 czConfig. process. stderr = stderr
222222 czConfig. process. stdin = stdin
223- // NOTE: We can support a user providing new entries eventually, but for now craft
224- // a default /etc/hosts.
225- var hostsEntries = [ Hosts . Entry. localHostIPV4 ( ) ]
226- if !interfaces. isEmpty {
227- let primaryIfaceAddr = interfaces [ 0 ] . ipv4Address
228- hostsEntries. append (
229- Hosts . Entry (
230- ipAddress: primaryIfaceAddr. address. description,
231- hostnames: [ czConfig. hostname ?? id] ,
232- ) )
233- }
234- czConfig. hosts = Hosts ( entries: hostsEntries)
223+ czConfig. hosts = Hosts ( entries: Self . resolvedHosts (
224+ hostname: czConfig. hostname ?? id,
225+ primaryAddress: interfaces. first? . ipv4Address. address. description,
226+ extraHosts: config. hosts
227+ ) . map {
228+ Hosts . Entry ( ipAddress: $0. ipAddress, hostnames: $0. hostnames)
229+ } )
235230 czConfig. bootLog = BootLog . file ( path: bundle. bootlog, append: true )
236231 }
237232
@@ -1292,6 +1287,22 @@ extension FileHandle: @retroactive ReaderStream, @retroactive Writer {
12921287// MARK: State handler and bundle creation helpers
12931288
12941289extension SandboxService {
1290+ static func resolvedHosts(
1291+ hostname: String,
1292+ primaryAddress: String? ,
1293+ extraHosts: [ ContainerConfiguration . HostEntry]
1294+ ) - > [ ContainerConfiguration . HostEntry] {
1295+ var hosts = [ ContainerConfiguration . HostEntry ( ipAddress: " 127.0.0.1 " , hostnames: [ " localhost " ] ) ]
1296+
1297+ if let primaryAddress {
1298+ let ip = String ( primaryAddress. split ( separator: " / " ) [ 0 ] )
1299+ hosts. append ( ContainerConfiguration . HostEntry ( ipAddress: ip, hostnames: [ hostname] ) )
1300+ }
1301+
1302+ hosts. append ( contentsOf: extraHosts)
1303+ return hosts
1304+ }
1305+
12951306 private func initializeWaiters( for id: String ) throws {
12961307 guard waiters [ id] == nil else {
12971308 throw ContainerizationError ( . invalidState, message: " waiter for \( id) already initialized " )
0 commit comments