Skip to content

Commit

Permalink
Merge pull request containers#668 from vrothberg/0.38-backports
Browse files Browse the repository at this point in the history
[0.38] Don't use systemd defaults if /proc/1/comm != systemd
  • Loading branch information
openshift-merge-robot authored Jul 6, 2021
2 parents 9904ee5 + e032047 commit 8824db3
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ GO_BUILD=$(GO) build
ifeq ($(shell go help mod >/dev/null 2>&1 && echo true), true)
GO_BUILD=GO111MODULE=on $(GO) build -mod=vendor
endif
BUILDTAGS := containers_image_openpgp
BUILDTAGS := containers_image_openpgp,systemd
DESTDIR ?=
PREFIX := /usr/local
CONFIGDIR := ${PREFIX}/share/containers
Expand Down
12 changes: 10 additions & 2 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ var _ = Describe("Config", func() {
gomega.Expect(defaultConfig.GetDefaultEnvEx(false, true)).To(gomega.BeEquivalentTo(httpEnvs))
gomega.Expect(strings.Join(defaultConfig.GetDefaultEnvEx(true, true), ",")).To(gomega.ContainSubstring("HTTP_PROXY"))
gomega.Expect(strings.Join(defaultConfig.GetDefaultEnvEx(true, true), ",")).To(gomega.ContainSubstring("foo"))

// Undo that
if proxyEnvSet {
os.Setenv("HTTP_PROXY", oldProxy)
Expand Down Expand Up @@ -292,7 +291,16 @@ var _ = Describe("Config", func() {
gomega.Expect(config.Network.CNIPluginDirs).To(gomega.Equal(pluginDirs))
gomega.Expect(config.Engine.NumLocks).To(gomega.BeEquivalentTo(2048))
gomega.Expect(config.Engine.OCIRuntimes["runc"]).To(gomega.Equal(OCIRuntimeMap["runc"]))
gomega.Expect(config.LogDriver()).To(gomega.Equal("k8s-file"))
if useSystemd() {
gomega.Expect(config.Engine.CgroupManager).To(gomega.BeEquivalentTo("systemd"))
gomega.Expect(config.Engine.EventsLogger).To(gomega.BeEquivalentTo("journald"))
gomega.Expect(config.Containers.LogDriver).To(gomega.BeEquivalentTo("k8s-file"))
} else {
gomega.Expect(config.Engine.CgroupManager).To(gomega.BeEquivalentTo("cgroupfs"))
gomega.Expect(config.Engine.EventsLogger).To(gomega.BeEquivalentTo("file"))
gomega.Expect(config.Containers.LogDriver).To(gomega.BeEquivalentTo("k8s-file"))
}

})

It("should success with valid user file path", func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func DefaultConfig() (*Config, error) {
Init: false,
InitPath: "",
IPCNS: "private",
LogDriver: DefaultLogDriver,
LogDriver: defaultLogDriver(),
LogSizeMax: DefaultLogSizeMax,
NetNS: netns,
NoHosts: false,
Expand Down
10 changes: 9 additions & 1 deletion pkg/config/nosystemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@
package config

func defaultCgroupManager() string {
return "cgroupfs"
return CgroupfsCgroupsManager
}

func defaultEventsLogger() string {
return "file"
}

func defaultLogDriver() string {
return DefaultLogDriver
}

func useSystemd() bool {
return false
}
40 changes: 39 additions & 1 deletion pkg/config/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,56 @@
package config

import (
"io/ioutil"
"strings"
"sync"

"github.com/containers/common/pkg/cgroupv2"
"github.com/containers/storage/pkg/unshare"
)

var (
systemdOnce sync.Once
usesSystemd bool
)

func defaultCgroupManager() string {
if !useSystemd() {
return CgroupfsCgroupsManager
}
enabled, err := cgroupv2.Enabled()
if err == nil && !enabled && unshare.IsRootless() {
return CgroupfsCgroupsManager
}

return SystemdCgroupsManager
}

func defaultEventsLogger() string {
return "journald"
if useSystemd() {
return "journald"
}
return "file"
}

func defaultLogDriver() string {
// If we decide to change the default for logdriver, it should be done here.
if useSystemd() {
return DefaultLogDriver
}

return DefaultLogDriver

}

func useSystemd() bool {
systemdOnce.Do(func() {
dat, err := ioutil.ReadFile("/proc/1/comm")
if err == nil {
val := strings.TrimSuffix(string(dat), "\n")
usesSystemd = (val == "systemd")
}
return
})
return usesSystemd
}

0 comments on commit 8824db3

Please sign in to comment.