Skip to content

Commit

Permalink
Search for local runtime per values in containers.conf
Browse files Browse the repository at this point in the history
After receiving the determing the type of runtime to use,
either "runc" or "crun" dependent upon the system, search
the list of that type of runtime in the containers.conf
file.  It includes the location of those runtimes in a
number of different architectures.  Once found, set the
runtime to use to that value.

Fixes: containers#2113

Signed-off-by: TomSweeneyRedHat <[email protected]>
  • Loading branch information
TomSweeneyRedHat committed Feb 22, 2020
1 parent 002dffb commit e3e3246
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions run_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func setChildProcess() error {

// Run runs the specified command in the container's root filesystem.
func (b *Builder) Run(command []string, options RunOptions) error {

p, err := ioutil.TempDir("", Package)
if err != nil {
return errors.Wrapf(err, "run: error creating temporary directory under %q", os.TempDir())
Expand Down Expand Up @@ -680,6 +681,11 @@ func runUsingRuntime(isolation Isolation, options RunOptions, configureNetwork b
runtime = util.Runtime()
}

localRuntime := util.FindLocalRuntime(runtime)
if localRuntime != "" {
runtime = localRuntime
}

// Default to just passing down our stdio.
getCreateStdio := func() (io.ReadCloser, io.WriteCloser, io.WriteCloser) {
return os.Stdin, os.Stdout, os.Stderr
Expand Down
31 changes: 31 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sync"
"syscall"

"github.com/containers/common/pkg/config"
"github.com/containers/image/v5/docker/reference"
"github.com/containers/image/v5/pkg/sysregistriesv2"
"github.com/containers/image/v5/signature"
Expand Down Expand Up @@ -432,3 +433,33 @@ var (
isUnified bool
isUnifiedErr error
)

//FileExistsAndNotADir - Check to see if a file exists
//and that it is not a directory.
func FileExistsAndNotADir(path string) bool {
file, err := os.Stat(path)

if file == nil || err != nil || os.IsNotExist(err) == true {
return false
}
return !file.IsDir()
}

// FindLocalRuntime find the local runtime of the
// system searching through the config file for
// possible locations.
func FindLocalRuntime(runtime string) string {
var localRuntime string
conf, err := config.NewConfig("")
if err != nil {
logrus.Debugf("Error loading container config when searching for local runtime.")
return localRuntime
}
for key, val := range conf.Libpod.OCIRuntimes[runtime] {
if FileExistsAndNotADir(val) {
localRuntime = val
break
}
}
return localRuntime
}

0 comments on commit e3e3246

Please sign in to comment.