Skip to content

Commit 7a41f31

Browse files
committed
cmd/runtimetest/main: Avoid panics if "linux" isn't set in config.json
Signed-off-by: W. Trevor King <[email protected]>
1 parent 8178fda commit 7a41f31

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

cmd/runtimetest/main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ func validateRlimits(spec *rspec.Spec) error {
280280
}
281281

282282
func validateSysctls(spec *rspec.Spec) error {
283+
if spec.Linux == nil {
284+
return nil
285+
}
283286
for k, v := range spec.Linux.Sysctl {
284287
keyPath := filepath.Join("/proc/sys", strings.Replace(k, ".", "/", -1))
285288
vBytes, err := ioutil.ReadFile(keyPath)
@@ -340,6 +343,9 @@ func validateDefaultFS(spec *rspec.Spec) error {
340343
}
341344

342345
func validateLinuxDevices(spec *rspec.Spec) error {
346+
if spec.Linux == nil {
347+
return nil
348+
}
343349
for _, device := range spec.Linux.Devices {
344350
fi, err := os.Stat(device.Path)
345351
if err != nil {
@@ -435,6 +441,9 @@ func validateDefaultDevices(spec *rspec.Spec) error {
435441
}
436442

437443
func validateMaskedPaths(spec *rspec.Spec) error {
444+
if spec.Linux == nil {
445+
return nil
446+
}
438447
for _, maskedPath := range spec.Linux.MaskedPaths {
439448
f, err := os.Open(maskedPath)
440449
if err != nil {
@@ -451,6 +460,9 @@ func validateMaskedPaths(spec *rspec.Spec) error {
451460
}
452461

453462
func validateROPaths(spec *rspec.Spec) error {
463+
if spec.Linux == nil {
464+
return nil
465+
}
454466
for _, v := range spec.Linux.ReadonlyPaths {
455467
err := testWriteAccess(v)
456468
if err == nil {
@@ -551,10 +563,16 @@ func validateIDMappings(mappings []rspec.LinuxIDMapping, path string, property s
551563
}
552564

553565
func validateUIDMappings(spec *rspec.Spec) error {
566+
if spec.Linux == nil {
567+
return nil
568+
}
554569
return validateIDMappings(spec.Linux.UIDMappings, "/proc/self/uid_map", "linux.uidMappings")
555570
}
556571

557572
func validateGIDMappings(spec *rspec.Spec) error {
573+
if spec.Linux == nil {
574+
return nil
575+
}
558576
return validateIDMappings(spec.Linux.GIDMappings, "/proc/self/gid_map", "linux.gidMappings")
559577
}
560578

0 commit comments

Comments
 (0)