Skip to content

Commit

Permalink
Refactor order of check container function to shorten line length
Browse files Browse the repository at this point in the history
  • Loading branch information
mback2k committed Oct 12, 2018
1 parent 7fee2d6 commit 5c7ad70
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,30 @@ func checkContainer(ctx context.Context, cli *client.Client, response types.Cont
usePID bool, useCGroup bool) bool {

log.Println(logNotice, "Checking container ...")
if usePID {
log.Println(logNotice, "Checking for PID existence ...")
if checkProcess(response.State.Pid) {
if useCGroup {
log.Println(logNotice, "Checking for PID existence in CGroup ...")
cgroup := fmt.Sprintf(dockerCGroupFormat, response.ID)
if checkCGroup(response.State.Pid, cgroup) {
log.Println(logNotice, "Successfully checked for PID existence in CGroup.")
return true
} else {
log.Println(logNotice, "Failed to check for PID existence in CGroup.")
return false
}
} else {
log.Println(logNotice, "Successfully checked for PID existence, but skipped CGroup.")
return true
}
} else {
log.Println(logNotice, "Failed to check for PID existence.")
return false
}
} else {
if !usePID {
log.Println(logInfo, "Skipped check for PID existence.")
return true
}

log.Println(logNotice, "Checking for PID existence ...")
if !checkProcess(response.State.Pid) {
log.Println(logNotice, "Failed to check for PID existence.")
return false
}
if !useCGroup {
log.Println(logNotice, "Successfully checked for PID existence, but skipped CGroup.")
return true
}

log.Println(logNotice, "Checking for PID existence in CGroup ...")
cgroup := fmt.Sprintf(dockerCGroupFormat, response.ID)
if !checkCGroup(response.State.Pid, cgroup) {
log.Println(logNotice, "Failed to check for PID existence in CGroup.")
return false
}

log.Println(logNotice, "Successfully checked for PID existence in CGroup.")
return true
}

func startContainer(ctx context.Context, cli *client.Client, containerName string) bool {
Expand Down

0 comments on commit 5c7ad70

Please sign in to comment.