Skip to content

Commit

Permalink
incusd/main_forknet: Make it so our DHCP client never fails
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
  • Loading branch information
stgraber committed Aug 9, 2024
1 parent 98bf4f2 commit 2e72dca
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions cmd/incusd/main_forknet.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ func (c *cmdForknet) RunDHCP(cmd *cobra.Command, args []string) error {

err = addr.Add()
if err != nil {
return err
fmt.Fprintf(os.Stderr, "Giving up on DHCP, couldn't add IP to %q\n", iface)
return nil
}

route := &ip.Route{
Expand All @@ -295,35 +296,40 @@ func (c *cmdForknet) RunDHCP(cmd *cobra.Command, args []string) error {

err = route.Add()
if err != nil {
return err
fmt.Fprintf(os.Stderr, "Giving up on DHCP, couldn't add default route to %q\n", iface)
return nil
}

// DNS configuration.
f, err := os.Create(filepath.Join(args[0], "resolv.conf"))
if err != nil {
return err
fmt.Fprintf(os.Stderr, "Giving up on DHCP, couldn't prepare resolv.conf: %v\n", iface, err)

Check failure on line 306 in cmd/incusd/main_forknet.go

View workflow job for this annotation

GitHub Actions / Code (oldstable)

printf: fmt.Fprintf call needs 1 arg but has 2 args (govet)

Check failure on line 306 in cmd/incusd/main_forknet.go

View workflow job for this annotation

GitHub Actions / Code (stable)

printf: fmt.Fprintf call needs 1 arg but has 2 args (govet)

Check failure on line 306 in cmd/incusd/main_forknet.go

View workflow job for this annotation

GitHub Actions / Code (tip)

printf: fmt.Fprintf call needs 1 arg but has 2 args (govet)
return nil
}

defer f.Close()

for _, nameserver := range reply.DNS() {
_, err = f.Write([]byte(fmt.Sprintf("nameserver %s\n", nameserver)))
if err != nil {
return err
fmt.Fprintf(os.Stderr, "Giving up on DHCP, couldn't prepare resolv.conf: %v\n", iface, err)

Check failure on line 315 in cmd/incusd/main_forknet.go

View workflow job for this annotation

GitHub Actions / Code (oldstable)

printf: fmt.Fprintf call needs 1 arg but has 2 args (govet)

Check failure on line 315 in cmd/incusd/main_forknet.go

View workflow job for this annotation

GitHub Actions / Code (stable)

printf: fmt.Fprintf call needs 1 arg but has 2 args (govet)

Check failure on line 315 in cmd/incusd/main_forknet.go

View workflow job for this annotation

GitHub Actions / Code (tip)

printf: fmt.Fprintf call needs 1 arg but has 2 args (govet)
return nil
}
}

if reply.DomainName() != "" {
_, err = f.Write([]byte(fmt.Sprintf("domain %s\n", reply.DomainName())))
if err != nil {
return err
fmt.Fprintf(os.Stderr, "Giving up on DHCP, couldn't prepare resolv.conf: %v\n", iface, err)

Check failure on line 323 in cmd/incusd/main_forknet.go

View workflow job for this annotation

GitHub Actions / Code (oldstable)

printf: fmt.Fprintf call needs 1 arg but has 2 args (govet)

Check failure on line 323 in cmd/incusd/main_forknet.go

View workflow job for this annotation

GitHub Actions / Code (stable)

printf: fmt.Fprintf call needs 1 arg but has 2 args (govet)

Check failure on line 323 in cmd/incusd/main_forknet.go

View workflow job for this annotation

GitHub Actions / Code (tip)

printf: fmt.Fprintf call needs 1 arg but has 2 args (govet)
return nil
}
}

if reply.DomainSearch() != nil && len(reply.DomainSearch().Labels) > 0 {
_, err = f.Write([]byte(fmt.Sprintf("search %s\n", strings.Join(reply.DomainSearch().Labels, ", "))))
if err != nil {
return err
fmt.Fprintf(os.Stderr, "Giving up on DHCP, couldn't prepare resolv.conf: %v\n", iface, err)
return nil
}
}

Expand Down

0 comments on commit 2e72dca

Please sign in to comment.