utils_unix.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // +build linux
  2. package daemon
  3. import (
  4. "errors"
  5. "fmt"
  6. "strings"
  7. "github.com/docker/docker/runconfig"
  8. "github.com/opencontainers/runc/libcontainer/selinux"
  9. )
  10. func selinuxSetDisabled() {
  11. selinux.SetDisabled()
  12. }
  13. func selinuxFreeLxcContexts(label string) {
  14. selinux.FreeLxcContexts(label)
  15. }
  16. func selinuxEnabled() bool {
  17. return selinux.SelinuxEnabled()
  18. }
  19. func mergeLxcConfIntoOptions(hostConfig *runconfig.HostConfig) ([]string, error) {
  20. if hostConfig == nil {
  21. return nil, nil
  22. }
  23. out := []string{}
  24. // merge in the lxc conf options into the generic config map
  25. if lxcConf := hostConfig.LxcConf; lxcConf != nil {
  26. lxSlice := lxcConf.Slice()
  27. for _, pair := range lxSlice {
  28. // because lxc conf gets the driver name lxc.XXXX we need to trim it off
  29. // and let the lxc driver add it back later if needed
  30. if !strings.Contains(pair.Key, ".") {
  31. return nil, errors.New("Illegal Key passed into LXC Configurations")
  32. }
  33. parts := strings.SplitN(pair.Key, ".", 2)
  34. out = append(out, fmt.Sprintf("%s=%s", parts[1], pair.Value))
  35. }
  36. }
  37. return out, nil
  38. }