File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import (
2121 "io/ioutil"
2222 "os"
2323 "path/filepath"
24+ "sync"
2425
2526 oci "github.com/opencontainers/runtime-spec/specs-go"
2627 "github.com/pkg/errors"
4142
4243 // Externally set CDI Spec validation function.
4344 specValidator func (* cdi.Spec ) error
45+ validatorLock sync.RWMutex
4446)
4547
4648// Spec represents a single CDI Spec. It is usually loaded from a
@@ -249,11 +251,16 @@ func ParseSpec(data []byte) (*cdi.Spec, error) {
249251// is used for extra CDI Spec content validation whenever a Spec file
250252// loaded (using ReadSpec() or NewSpec()) or written (Spec.Write()).
251253func SetSpecValidator (fn func (* cdi.Spec ) error ) {
254+ validatorLock .Lock ()
255+ defer validatorLock .Unlock ()
252256 specValidator = fn
253257}
254258
255259// validateSpec validates the Spec using the extneral validator.
256260func validateSpec (raw * cdi.Spec ) error {
261+ validatorLock .RLock ()
262+ defer validatorLock .RUnlock ()
263+
257264 if specValidator == nil {
258265 return nil
259266 }
You can’t perform that action at this time.
0 commit comments