Skip to content
This repository has been archived by the owner on Feb 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #4 from oracle/ldocnfig-path
Browse files Browse the repository at this point in the history
look for chmod and ldconfig inside chroot
  • Loading branch information
vishvananda authored Jul 17, 2017
2 parents 7c840c7 + e68a2a7 commit b910e73
Showing 1 changed file with 39 additions and 12 deletions.
51 changes: 39 additions & 12 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,17 +332,6 @@ func buildOci(buildOpts *buildOptions, outputDir string, pkg *ConfigDef) error {
uid, gid := os.Getuid(), os.Getgid()
unpackDir := filepath.Join(os.TempDir(), "smith-unpack-"+strconv.Itoa(uid))

executor := func(name string, arg ...string) (string, string, error) {
attr := &syscall.SysProcAttr{
Chroot: unpackDir,
}
attr, err := setAttrMappings(attr, uid, gid)
if err != nil {
return "", "", err
}
return execute.AttrExecuteQuiet(attr, name, arg...)
}

var image *Image
var err error
if strings.HasPrefix(pkg.Package, "http://") ||
Expand All @@ -368,7 +357,6 @@ func buildOci(buildOpts *buildOptions, outputDir string, pkg *ConfigDef) error {
if len(pkg.Ports) == 0 {
pkg.Ports = image.Config.Config.ExposedPorts
}

if !buildOpts.fast {
// remove directory
logrus.Infof("Removing %v", unpackDir)
Expand All @@ -377,6 +365,45 @@ func buildOci(buildOpts *buildOptions, outputDir string, pkg *ConfigDef) error {
}
}

// set path for executor
path := "/usr/sbin:/usr/bin:/sbin:/bin"
for _, e := range pkg.Env {
if strings.HasPrefix(e, "PATH=") {
path = e[len("PATH="):]
}
}
executor := func(name string, arg ...string) (string, string, error) {
attr := &syscall.SysProcAttr{
Chroot: unpackDir,
}
attr, err := setAttrMappings(attr, uid, gid)
if err != nil {
return "", "", err
}

// find the executable using path in chroot
// note that this does not resolve symlinks properly
if !strings.Contains(name, "/") {
for _, dir := range filepath.SplitList(path) {
if dir == "" {
// Unix shell semantics: path element "" means "."
dir = "."
}
path := filepath.Join(unpackDir, dir, name)
d, err := os.Stat(path)
if err != nil {
continue
}
if m := d.Mode(); m.IsDir() || m&0111 == 0 {
continue
}
name = path[len(unpackDir):]
break
}
}
return execute.AttrExecuteQuiet(attr, name, arg...)
}

// only unpack if the directory doesn't already exist
if _, err := os.Stat(unpackDir); os.IsNotExist(err) {
if err := ExtractOci(image, unpackDir); err != nil {
Expand Down

0 comments on commit b910e73

Please sign in to comment.