Skip to content

Commit

Permalink
Remove non-ipv4 entry from /etc/hosts (#20341)
Browse files Browse the repository at this point in the history
* Remove none ipv4 entry from /etc/hosts

* Fix
  • Loading branch information
iQQBot authored Nov 4, 2024
1 parent a495f52 commit b1c42d6
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions components/workspacekit/cmd/rings.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,22 +695,33 @@ func makeHostnameLocal(ring2root string) error {
if err != nil {
return err
}
b, err := ioutil.ReadFile(path)
b, err := os.ReadFile(path)
if err != nil {
return err
}
bStr := string(b)
lines := strings.Split(bStr, "\n")
for i, line := range lines {
newLines := []string{}
for _, line := range lines {
fields := strings.Fields(line)
if len(fields) != 2 {
if len(fields) < 1 {
newLines = append(newLines, line)
continue
}
if strings.HasPrefix(fields[0], "#") {
newLines = append(newLines, line)
}
ip := net.ParseIP(fields[0]).To4()
if len(ip) != net.IPv4len {
continue
}
if fields[1] == hostname {
lines[i] = "127.0.0.1 " + hostname
newLines = append(newLines, "127.0.0.1 "+hostname)
} else {
newLines = append(newLines, line)
}
}
return ioutil.WriteFile(path, []byte(strings.Join(lines, "\n")), stat.Mode())
return os.WriteFile(path, []byte(strings.Join(newLines, "\n")), stat.Mode())
}

func receiveSeccmpFd(conn *net.UnixConn) (libseccomp.ScmpFd, error) {
Expand Down

0 comments on commit b1c42d6

Please sign in to comment.