@@ -615,9 +615,16 @@ func (p *initProcess) start() (retErr error) {
615615	if  err  :=  p .createNetworkInterfaces (); err  !=  nil  {
616616		return  fmt .Errorf ("error creating network interfaces: %w" , err )
617617	}
618- 	if  err  :=  p .updateSpecState (); err  !=  nil  {
619- 		return  fmt .Errorf ("error updating spec state: %w" , err )
618+ 
619+ 	// initConfig.SpecState is only needed to run hooks that are executed 
620+ 	// inside a container, i.e. CreateContainer and StartContainer. 
621+ 	if  p .config .Config .HasHook (configs .CreateContainer , configs .StartContainer ) {
622+ 		p .config .SpecState , err  =  p .container .currentOCIState ()
623+ 		if  err  !=  nil  {
624+ 			return  fmt .Errorf ("error getting current state: %w" , err )
625+ 		}
620626	}
627+ 
621628	if  err  :=  utils .WriteJSON (p .comm .initSockParent , p .config ); err  !=  nil  {
622629		return  fmt .Errorf ("error sending config to init process: %w" , err )
623630	}
@@ -740,7 +747,7 @@ func (p *initProcess) start() (retErr error) {
740747					return  fmt .Errorf ("error setting Intel RDT config for procHooks process: %w" , err )
741748				}
742749			}
743- 			if  len ( p .config .Config .Hooks )  !=   0  {
750+ 			if  p .config .Config .HasHook ( configs . Prestart ,  configs . CreateRuntime )  {
744751				s , err  :=  p .container .currentOCIState ()
745752				if  err  !=  nil  {
746753					return  err 
@@ -779,16 +786,6 @@ func (p *initProcess) start() (retErr error) {
779786	return  nil 
780787}
781788
782- func  (p  * initProcess ) updateSpecState () error  {
783- 	s , err  :=  p .container .currentOCIState ()
784- 	if  err  !=  nil  {
785- 		return  err 
786- 	}
787- 
788- 	p .config .SpecState  =  s 
789- 	return  nil 
790- }
791- 
792789func  (p  * initProcess ) createNetworkInterfaces () error  {
793790	for  _ , config  :=  range  p .config .Config .Networks  {
794791		strategy , err  :=  getStrategy (config .Type )
0 commit comments