hst/instance: store priv side pid
All checks were successful
Test / Create distribution (push) Successful in 33s
Test / Sandbox (push) Successful in 2m14s
Test / Hakurei (push) Successful in 3m8s
Test / Sandbox (race detector) (push) Successful in 3m58s
Test / Hpkg (push) Successful in 4m1s
Test / Hakurei (race detector) (push) Successful in 4m44s
Test / Flake checks (push) Successful in 1m29s

This can receive signals, so is more useful to the caller.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
Ophestra 2025-10-23 23:19:55 +09:00
parent dd94818f20
commit 05488bfb8f
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q
4 changed files with 22 additions and 15 deletions

View File

@ -66,7 +66,7 @@ func printShowInstance(
if instance != nil { if instance != nil {
t.Printf("State\n") t.Printf("State\n")
t.Printf(" Instance:\t%s (%d)\n", instance.ID.String(), instance.PID) t.Printf(" Instance:\t%s (%d -> %d)\n", instance.ID.String(), instance.PID, instance.ShimPID)
t.Printf(" Uptime:\t%s\n", now.Sub(instance.Time).Round(time.Second).String()) t.Printf(" Uptime:\t%s\n", now.Sub(instance.Time).Round(time.Second).String())
t.Printf("\n") t.Printf("\n")
} }

View File

@ -17,10 +17,11 @@ var (
0xb4, 0x6e, 0xb5, 0xc1, 0xb4, 0x6e, 0xb5, 0xc1,
} }
testState = &hst.State{ testState = &hst.State{
ID: testID, ID: testID,
PID: 0xDEADBEEF, PID: 0xcafebabe,
Config: hst.Template(), ShimPID: 0xdeadbeef,
Time: testAppTime, Config: hst.Template(),
Time: testAppTime,
} }
testTime = time.Unix(3752, 1).UTC() testTime = time.Unix(3752, 1).UTC()
testAppTime = time.Unix(0, 9).UTC() testAppTime = time.Unix(0, 9).UTC()
@ -131,7 +132,7 @@ Session bus
`, false}, `, false},
{"instance", testState, hst.Template(), false, false, `State {"instance", testState, hst.Template(), false, false, `State
Instance: 8e2c76b066dabe574cf073bdb46eb5c1 (3735928559) Instance: 8e2c76b066dabe574cf073bdb46eb5c1 (3405691582 -> 3735928559)
Uptime: 1h2m32s Uptime: 1h2m32s
App App
@ -173,7 +174,7 @@ System bus
{"instance pd", testState, new(hst.Config), false, false, `Error: configuration missing container state! {"instance pd", testState, new(hst.Config), false, false, `Error: configuration missing container state!
State State
Instance: 8e2c76b066dabe574cf073bdb46eb5c1 (3735928559) Instance: 8e2c76b066dabe574cf073bdb46eb5c1 (3405691582 -> 3735928559)
Uptime: 1h2m32s Uptime: 1h2m32s
App App
@ -186,7 +187,8 @@ App
`, true}, `, true},
{"json instance", testState, nil, false, true, `{ {"json instance", testState, nil, false, true, `{
"instance": "8e2c76b066dabe574cf073bdb46eb5c1", "instance": "8e2c76b066dabe574cf073bdb46eb5c1",
"pid": 3735928559, "pid": 3405691582,
"shim_pid": 3735928559,
"config": { "config": {
"id": "org.chromium.Chromium", "id": "org.chromium.Chromium",
"enablements": { "enablements": {
@ -527,13 +529,14 @@ func TestPrintPs(t *testing.T) {
`}, `},
{"valid", map[hst.ID]*hst.State{testID: testState}, false, false, ` Instance PID Application Uptime {"valid", map[hst.ID]*hst.State{testID: testState}, false, false, ` Instance PID Application Uptime
8e2c76b0 3735928559 9 (org.chromium.Chromium) 1h2m32s 8e2c76b0 3405691582 9 (org.chromium.Chromium) 1h2m32s
`}, `},
{"valid short", map[hst.ID]*hst.State{testID: testState}, true, false, "8e2c76b0\n"}, {"valid short", map[hst.ID]*hst.State{testID: testState}, true, false, "8e2c76b0\n"},
{"valid json", map[hst.ID]*hst.State{testID: testState}, false, true, `{ {"valid json", map[hst.ID]*hst.State{testID: testState}, false, true, `{
"8e2c76b066dabe574cf073bdb46eb5c1": { "8e2c76b066dabe574cf073bdb46eb5c1": {
"instance": "8e2c76b066dabe574cf073bdb46eb5c1", "instance": "8e2c76b066dabe574cf073bdb46eb5c1",
"pid": 3735928559, "pid": 3405691582,
"shim_pid": 3735928559,
"config": { "config": {
"id": "org.chromium.Chromium", "id": "org.chromium.Chromium",
"enablements": { "enablements": {

View File

@ -74,8 +74,11 @@ func (a *ID) UnmarshalText(text []byte) error {
type State struct { type State struct {
// Unique instance id, created by [NewInstanceID]. // Unique instance id, created by [NewInstanceID].
ID ID `json:"instance"` ID ID `json:"instance"`
// Shim process pid. Runs as the target user. // Monitoring process pid. Runs as the priv user.
PID int `json:"pid"` PID int `json:"pid"`
// Shim process pid. Runs as the target user.
ShimPID int `json:"shim_pid"`
// Configuration used to start the container. // Configuration used to start the container.
Config *Config `json:"config"` Config *Config `json:"config"`

View File

@ -290,10 +290,11 @@ func (k *outcome) main(msg message.Msg) {
// shim accepted setup payload, create process state // shim accepted setup payload, create process state
if ok, err := ms.store.Do(k.state.identity.unwrap(), func(c state.Cursor) { if ok, err := ms.store.Do(k.state.identity.unwrap(), func(c state.Cursor) {
if err := c.Save(&hst.State{ if err := c.Save(&hst.State{
ID: k.state.id.unwrap(), ID: k.state.id.unwrap(),
PID: ms.cmd.Process.Pid, PID: os.Getpid(),
Config: k.config, ShimPID: ms.cmd.Process.Pid,
Time: *ms.Time, Config: k.config,
Time: *ms.Time,
}); err != nil { }); err != nil {
ms.fatal("cannot save state entry:", err) ms.fatal("cannot save state entry:", err)
} }