Skip to content

Commit

Permalink
Fix nits on chan direction and defer
Browse files Browse the repository at this point in the history
Closes #9
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@docker.com> (github: crosbymichael)
  • Loading branch information
Michael Crosby committed Jun 24, 2014
1 parent 9fa6481 commit 775666b
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions cgroups/fs/notify_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

// NotifyOnOOM sends signals on the returned channel when the cgroup reaches
// its memory limit. The channel is closed when the cgroup is removed.
func NotifyOnOOM(c *cgroups.Cgroup) (chan struct{}, error) {
func NotifyOnOOM(c *cgroups.Cgroup) (<-chan struct{}, error) {
d, err := getCgroupData(c, 0)
if err != nil {
return nil, err
Expand All @@ -22,7 +22,7 @@ func NotifyOnOOM(c *cgroups.Cgroup) (chan struct{}, error) {
return notifyOnOOM(d)
}

func notifyOnOOM(d *data) (chan struct{}, error) {
func notifyOnOOM(d *data) (<-chan struct{}, error) {
dir, err := d.path("memory")
if err != nil {
return nil, err
Expand All @@ -43,8 +43,7 @@ func notifyOnOOM(d *data) (chan struct{}, error) {

var (
eventControlPath = filepath.Join(dir, "cgroup.event_control")

data = fmt.Sprintf("%d %d", eventfd.Fd(), oomControl.Fd())
data = fmt.Sprintf("%d %d", eventfd.Fd(), oomControl.Fd())
)

if err := writeFile(dir, "cgroup.event_control", data); err != nil {
Expand All @@ -56,11 +55,13 @@ func notifyOnOOM(d *data) (chan struct{}, error) {
ch := make(chan struct{})

go func() {
defer close(ch)
defer eventfd.Close()
defer oomControl.Close()
defer func() {
close(ch)
eventfd.Close()
oomControl.Close()
}()

var buf = make([]byte, 8)
buf := make([]byte, 8)

for {
if _, err := eventfd.Read(buf); err != nil {
Expand Down

0 comments on commit 775666b

Please sign in to comment.