There are situations in which is useful to detect the first invocation,
i.e. you may want to cleanup dangling unix sockets, but not during an upgrade.
We already have WaitForParent and it can be exploited to get this information, but it looks so hacky...
func isUpgrade(u *tableflip.Upgrader) bool {
ctx, cancel := context.WithCancel(context.Background())
// we use a canceled context because WaitForParent returns immediately, without errors, only on the parent process
// an already expired context ensure us an immediate failure also inside the children process
cancel()
return u.WaitForParent(ctx) != nil
}
This can be easily implemented in Upgrader with 1 line of code + tests.
There are situations in which is useful to detect the first invocation, i.e. you may want to cleanup dangling unix sockets, but not during an upgrade.
We already have
WaitForParent
and it can be exploited to get this information, but it looks so hacky...This can be easily implemented in
Upgrader
with 1 line of code + tests.