Skip to content

Commit

Permalink
simplify file reading (#4010)
Browse files Browse the repository at this point in the history
Signed-off-by: zhangzujian <[email protected]>
  • Loading branch information
zhangzujian authored May 13, 2024
1 parent aaf5736 commit 41cb044
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions pkg/ovn_leader_checker/ovn.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"flag"
"fmt"
"io"
"net"
"os"
"os/exec"
Expand Down Expand Up @@ -183,22 +182,15 @@ func isDBLeader(dbName string, port int) bool {
}

func checkNorthdActive() bool {
var command []string
file, err := os.OpenFile(OvnNorthdPid, os.O_RDWR, 0o600)
pid, err := os.ReadFile(OvnNorthdPid)
if err != nil {
klog.Errorf("failed to open %s err = %v", OvnNorthdPid, err)
return false
}
defer file.Close()
fileByte, err := io.ReadAll(file)
if err != nil {
klog.Errorf("failed to read %s err = %v", OvnNorthdPid, err)
klog.Errorf("failed to read file %q: %v", OvnNorthdPid, err)
return false
}

command = []string{
command := []string{
"-t",
fmt.Sprintf("/var/run/ovn/ovn-northd.%s.ctl", strings.TrimSpace(string(fileByte))),
fmt.Sprintf("/var/run/ovn/ovn-northd.%s.ctl", strings.TrimSpace(string(pid))),
"status",
}
output, err := exec.Command("ovs-appctl", command...).CombinedOutput()
Expand Down

0 comments on commit 41cb044

Please sign in to comment.