mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-10 21:53:57 +08:00
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:
@@ -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 {
|
||||
|
||||
@@ -350,7 +350,7 @@ func (c *Container) start(process *Process) (retErr error) {
|
||||
|
||||
if process.Init {
|
||||
c.fifo.Close()
|
||||
if c.config.Hooks != nil {
|
||||
if c.config.HasHook(configs.Poststart) {
|
||||
s, err := c.currentOCIState()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1113,7 +1113,7 @@ func (c *Container) criuNotifications(resp *criurpc.CriuResp, process *Process,
|
||||
return err
|
||||
}
|
||||
case "setup-namespaces":
|
||||
if c.config.Hooks != nil {
|
||||
if c.config.HasHook(configs.Prestart, configs.CreateRuntime) {
|
||||
s, err := c.currentOCIState()
|
||||
if err != nil {
|
||||
return nil
|
||||
|
||||
@@ -740,7 +740,7 @@ func (p *initProcess) start() (retErr error) {
|
||||
return fmt.Errorf("error setting Intel RDT config for procHooks process: %w", err)
|
||||
}
|
||||
}
|
||||
if len(p.config.Config.Hooks) != 0 {
|
||||
if p.config.Config.HasHook(configs.Prestart, configs.CreateRuntime) {
|
||||
s, err := p.container.currentOCIState()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user