aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-11-10 07:51:00 +0900
committerOphestra <cat@gensokyo.uk>2025-11-10 07:52:35 +0900
commitbb92e3ada9ddbf315a50f2ec4b8bdafb05df7d3d (patch)
tree3ee95671cddf1b9a3c40f668d81eab992d03047f /internal
parentfad419c2a2be3f05ba85370e26341c0adaba05d1 (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 'internal')
-rw-r--r--internal/outcome/main.go8
-rw-r--r--internal/outcome/process.go17
2 files changed, 20 insertions, 5 deletions
diff --git a/internal/outcome/main.go b/internal/outcome/main.go
index feffb661..a32d220a 100644
--- a/internal/outcome/main.go
+++ b/internal/outcome/main.go
@@ -10,21 +10,21 @@ import (
)
// Main runs an app according to [hst.Config] and terminates. Main does not return.
-func Main(ctx context.Context, msg message.Msg, config *hst.Config) {
+func Main(ctx context.Context, msg message.Msg, config *hst.Config, fd int) {
var id hst.ID
if err := hst.NewInstanceID(&id); err != nil {
log.Fatal(err.Error())
}
- seal := outcome{syscallDispatcher: direct{msg}}
+ k := outcome{syscallDispatcher: direct{msg}}
finaliseTime := time.Now()
- if err := seal.finalise(ctx, msg, &id, config); err != nil {
+ if err := k.finalise(ctx, msg, &id, config); err != nil {
printMessageError(msg.GetLogger().Fatalln, "cannot seal app:", err)
panic("unreachable")
}
msg.Verbosef("finalise took %.2f ms", float64(time.Since(finaliseTime).Nanoseconds())/1e6)
- seal.main(msg)
+ k.main(msg, fd)
panic("unreachable")
}
diff --git a/internal/outcome/process.go b/internal/outcome/process.go
index 78570d26..3aa4d0e2 100644
--- a/internal/outcome/process.go
+++ b/internal/outcome/process.go
@@ -33,7 +33,7 @@ const (
func NewStore(sc *hst.Paths) *store.Store { return store.New(sc.SharePath.Append("state")) }
// main carries out outcome and terminates. main does not return.
-func (k *outcome) main(msg message.Msg) {
+func (k *outcome) main(msg message.Msg, identifierFd int) {
if k.ctx == nil || k.sys == nil || k.state == nil {
panic("outcome: did not finalise")
}
@@ -163,6 +163,21 @@ func (k *outcome) main(msg message.Msg) {
continue
}
+ if f := os.NewFile(uintptr(identifierFd), "identifier"); f != nil {
+ _, err = f.Write(k.state.id.v[:])
+ if err != nil {
+ unlock()
+ // transition here to avoid the commit/revert cycle on the doomed instance
+ perrorFatal(&hst.AppError{Step: "write instance identifier", Err: err},
+ "write instance identifier", processLifecycle)
+ continue
+ }
+ msg.Verbosef("wrote identifier to %d", identifierFd)
+ if err = f.Close(); err != nil {
+ msg.Verbose(err.Error())
+ }
+ }
+
err = k.sys.Commit()
unlock()
if err != nil {