libct: add/use configs.HasHook

This allows to omit a call to c.currentOCIState (which can be somewhat
costly when there are many annotations) when the hooks of a given kind
won't be run.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2024-10-09 11:00:48 -07:00
parent 2e906e292e
commit 8afeb58398
4 changed files with 16 additions and 3 deletions
+13
View File
@@ -332,6 +332,19 @@ const (
Poststop HookName = "poststop"
)
// HasHook checks if config has any hooks with any given names configured.
func (c *Config) HasHook(names ...HookName) bool {
if c.Hooks == nil {
return false
}
for _, h := range names {
if len(c.Hooks[h]) > 0 {
return true
}
}
return false
}
// KnownHookNames returns the known hook names.
// Used by `runc features`.
func KnownHookNames() []string {