Skip to content

Commit

Permalink
libcontainer/notify_linux*: adjust the file mode
Browse files Browse the repository at this point in the history
This commit adjusts the file mode to use the latest golang style
In addition to that, I changed those modes from 0700 to 0600
as same as opencontainers#2636

Related to opencontainers#2625

Signed-off-by: Kenta Tada <[email protected]>
  • Loading branch information
Kenta Tada authored and Kenta Tada committed Jul 5, 2021
1 parent 5547b57 commit a41b75d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions libcontainer/notify_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ package libcontainer
import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/opencontainers/runc/libcontainer/cgroups"
"golang.org/x/sys/unix"
)

Expand All @@ -33,13 +33,14 @@ func registerMemoryEvent(cgDir string, evName string, arg string) (<-chan struct

eventfd := os.NewFile(uintptr(fd), "eventfd")

eventControlPath := filepath.Join(cgDir, "cgroup.event_control")
const cgEvCtlFile = "cgroup.event_control"
data := fmt.Sprintf("%d %d %s", eventfd.Fd(), evFile.Fd(), arg)
if err := ioutil.WriteFile(eventControlPath, []byte(data), 0o700); err != nil {
if err := cgroups.WriteFile(cgDir, cgEvCtlFile, data); err != nil {
eventfd.Close()
evFile.Close()
return nil, err
}
eventControlPath := filepath.Join(cgDir, cgEvCtlFile)
ch := make(chan struct{})
go func() {
defer func() {
Expand Down
4 changes: 2 additions & 2 deletions libcontainer/notify_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ func testMemoryNotification(t *testing.T, evName string, notify notifyFunc, targ
}
evFile := filepath.Join(memoryPath, evName)
eventPath := filepath.Join(memoryPath, "cgroup.event_control")
if err := ioutil.WriteFile(evFile, []byte{}, 0o700); err != nil {
if err := ioutil.WriteFile(evFile, []byte{}, 0o600); err != nil {
t.Fatal(err)
}
if err := ioutil.WriteFile(eventPath, []byte{}, 0o700); err != nil {
if err := ioutil.WriteFile(eventPath, []byte{}, 0o600); err != nil {
t.Fatal(err)
}
ch, err := notify(memoryPath)
Expand Down

0 comments on commit a41b75d

Please sign in to comment.