@@ -695,22 +695,33 @@ func makeHostnameLocal(ring2root string) error {
695
695
if err != nil {
696
696
return err
697
697
}
698
- b , err := ioutil .ReadFile (path )
698
+ b , err := os .ReadFile (path )
699
699
if err != nil {
700
700
return err
701
701
}
702
702
bStr := string (b )
703
703
lines := strings .Split (bStr , "\n " )
704
- for i , line := range lines {
704
+ newLines := []string {}
705
+ for _ , line := range lines {
705
706
fields := strings .Fields (line )
706
- if len (fields ) != 2 {
707
+ if len (fields ) < 1 {
708
+ newLines = append (newLines , line )
709
+ continue
710
+ }
711
+ if strings .HasPrefix (fields [0 ], "#" ) {
712
+ newLines = append (newLines , line )
713
+ }
714
+ ip := net .ParseIP (fields [0 ]).To4 ()
715
+ if len (ip ) != net .IPv4len {
707
716
continue
708
717
}
709
718
if fields [1 ] == hostname {
710
- lines [i ] = "127.0.0.1 " + hostname
719
+ newLines = append (newLines , "127.0.0.1 " + hostname )
720
+ } else {
721
+ newLines = append (newLines , line )
711
722
}
712
723
}
713
- return ioutil .WriteFile (path , []byte (strings .Join (lines , "\n " )), stat .Mode ())
724
+ return os .WriteFile (path , []byte (strings .Join (newLines , "\n " )), stat .Mode ())
714
725
}
715
726
716
727
func receiveSeccmpFd (conn * net.UnixConn ) (libseccomp.ScmpFd , error ) {
0 commit comments