Skip to content

Commit

Permalink
Merge pull request containers#841 from hshiina/use-journald
Browse files Browse the repository at this point in the history
Check accessibility to journal without sdjournal library
  • Loading branch information
openshift-merge-robot authored Dec 1, 2021
2 parents ab2131e + 09546d8 commit 83ff427
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
7 changes: 5 additions & 2 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,13 @@ image_copy_tmp_dir="storage"`
gomega.Expect(config.Engine.OCIRuntimes["runc"]).To(gomega.Equal(OCIRuntimeMap["runc"]))
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"))
}
if useJournald() {
gomega.Expect(config.Engine.EventsLogger).To(gomega.BeEquivalentTo("journald"))
gomega.Expect(config.Containers.LogDriver).To(gomega.BeEquivalentTo("journald"))
} else {
gomega.Expect(config.Engine.EventsLogger).To(gomega.BeEquivalentTo("file"))
gomega.Expect(config.Containers.LogDriver).To(gomega.BeEquivalentTo("k8s-file"))
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/nosystemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ func defaultLogDriver() string {
func useSystemd() bool {
return false
}

func useJournald() bool {
return false
}
20 changes: 14 additions & 6 deletions pkg/config/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ package config

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

"github.com/containers/common/pkg/cgroupv2"
"github.com/containers/storage/pkg/unshare"
"github.com/coreos/go-systemd/v22/sdjournal"
)

var (
Expand Down Expand Up @@ -67,12 +67,20 @@ func useJournald() bool {
if !useSystemd() {
return
}
journal, err := sdjournal.NewJournal()
if err != nil {
return
for _, root := range []string{"/run/log/journal", "/var/log/journal"} {
dirs, err := ioutil.ReadDir(root)
if err != nil {
continue
}
for _, d := range dirs {
if d.IsDir() {
if _, err := ioutil.ReadDir(filepath.Join(root, d.Name())); err == nil {
usesJournald = true
return
}
}
}
}
journal.Close()
usesJournald = true
return
})
return usesJournald
Expand Down

0 comments on commit 83ff427

Please sign in to comment.