diff options
| author | Ophestra <cat@gensokyo.uk> | 2025-11-10 07:51:00 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2025-11-10 07:52:35 +0900 |
| commit | bb92e3ada9ddbf315a50f2ec4b8bdafb05df7d3d (patch) | |
| tree | 3ee95671cddf1b9a3c40f668d81eab992d03047f /cmd | |
| parent | fad419c2a2be3f05ba85370e26341c0adaba05d1 (diff) | |
cmd/hakurei: expose current instance identifier
This writes the 16-byte instance identifier to file descriptor specified by --identifier-fd if set, and closes the file.
This enables safely obtaining the new instance's identifier.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/hakurei/command.go | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/cmd/hakurei/command.go b/cmd/hakurei/command.go index a741ecf6..e049cfc4 100644 --- a/cmd/hakurei/command.go +++ b/cmd/hakurei/command.go @@ -52,20 +52,26 @@ func buildCommand(ctx context.Context, msg message.Msg, early *earlyHardeningErr c.Command("shim", command.UsageInternal, func([]string) error { outcome.Shim(msg); return errSuccess }) - c.Command("app", "Load and start container from configuration file", func(args []string) error { - if len(args) < 1 { - log.Fatal("app requires at least 1 argument") - } + { + var ( + flagIdentifierFile int + ) + c.NewCommand("app", "Load and start container from configuration file", func(args []string) error { + if len(args) < 1 { + log.Fatal("app requires at least 1 argument") + } - // config extraArgs... - config := tryPath(msg, args[0]) - if config != nil && config.Container != nil { - config.Container.Args = append(config.Container.Args, args[1:]...) - } + config := tryPath(msg, args[0]) + if config != nil && config.Container != nil { + config.Container.Args = append(config.Container.Args, args[1:]...) + } - outcome.Main(ctx, msg, config) - panic("unreachable") - }) + outcome.Main(ctx, msg, config, flagIdentifierFile) + panic("unreachable") + }). + Flag(&flagIdentifierFile, "identifier-fd", command.IntFlag(-1), + "Write identifier of current instance to fd after successful startup") + } { var ( @@ -257,7 +263,7 @@ func buildCommand(ctx context.Context, msg message.Msg, early *earlyHardeningErr } } - outcome.Main(ctx, msg, config) + outcome.Main(ctx, msg, config, -1) panic("unreachable") }). Flag(&flagDBusConfigSession, "dbus-config", command.StringFlag("builtin"), |
