Skip to content

Commit 0c91962

Browse files
committed
Drop the version metadata Mutex from AgentCommand
1 parent 6b686ec commit 0c91962

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

vminitd/Sources/VminitdCore/AgentCommand.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import GRPCCore
2626
import Logging
2727
import NIOCore
2828
import NIOPosix
29-
import Synchronization
3029

3130
#if os(Linux)
3231
#if canImport(Musl)
@@ -46,8 +45,6 @@ public struct AgentCommand: AsyncParsableCommand {
4645
private static let foregroundEnvVar = "FOREGROUND"
4746
public static let vsockPort = 1024
4847

49-
public static let versionMetadata = Mutex<Logger.Metadata>([:])
50-
5148
@OptionGroup var options: LogLevelOption
5249

5350
public init() {}
@@ -81,7 +78,7 @@ public struct AgentCommand: AsyncParsableCommand {
8178

8279
signal(SIGPIPE, SIG_IGN)
8380

84-
log.info("vminitd booting", metadata: Self.versionMetadata.withLock { $0 })
81+
log.info("vminitd booting", metadata: versionMetadata())
8582

8683
// Set of mounts necessary to be mounted prior to taking any RPCs.
8784
// 1. /proc as the sysctl rpc wouldn't make sense if it wasn't there (NOTE: This is done before this method

vminitd/Sources/VminitdCore/Logging.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ public struct LogLevelOption: ParsableArguments {
5050
}
5151

5252
private let _loggingBootstrapped = Mutex(false)
53+
private let _versionMetadata = Mutex<Logger.Metadata>([:])
54+
55+
/// Set the version metadata logged on boot.
56+
public func setVersionMetadata(_ metadata: Logger.Metadata) {
57+
_versionMetadata.withLock { $0 = metadata }
58+
}
59+
60+
func versionMetadata() -> Logger.Metadata {
61+
_versionMetadata.withLock { $0 }
62+
}
5363

5464
func makeLogger(label: String, level: Logger.Level) -> Logger {
5565
_loggingBootstrapped.withLock { bootstrapped in

vminitd/Sources/vminitd/Application.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct Application: AsyncParsableCommand {
3636
)
3737

3838
static func main() async throws {
39-
AgentCommand.versionMetadata.withLock { $0 = Self.versionMetadata() }
39+
setVersionMetadata(Self.versionMetadata())
4040

4141
// Busybox-style: if invoked as .cz-init, run init mode directly.
4242
let invoked = CommandLine.arguments.first?.split(separator: "/").last.map(String.init) ?? ""

0 commit comments

Comments
 (0)