mirror of
https://github.com/tailscale/tailscale.git
synced 2024-12-01 14:05:39 +00:00
net/dns: log more info when openresolv commands fail
Updates #11129 Signed-off-by: Andrew Dunham <andrew@du.nham.ca> Change-Id: Ic594868ba3bc31f6d3b0721ecba4090749a81f7f
This commit is contained in:
parent
7c0651aea6
commit
b0e96a6c39
@ -27,7 +27,7 @@ func NewOSConfigurator(logf logger.Logf, _ string) (OSConfigurator, error) {
|
|||||||
case "debian":
|
case "debian":
|
||||||
return newDebianResolvconfManager(logf)
|
return newDebianResolvconfManager(logf)
|
||||||
case "openresolv":
|
case "openresolv":
|
||||||
return newOpenresolvManager()
|
return newOpenresolvManager(logf)
|
||||||
default:
|
default:
|
||||||
logf("[unexpected] got unknown flavor of resolvconf %q, falling back to direct manager", resolvconfStyle())
|
logf("[unexpected] got unknown flavor of resolvconf %q, falling back to direct manager", resolvconfStyle())
|
||||||
return newDirectManager(logf), nil
|
return newDirectManager(logf), nil
|
||||||
|
@ -60,7 +60,7 @@ func NewOSConfigurator(logf logger.Logf, interfaceName string) (ret OSConfigurat
|
|||||||
case "debian-resolvconf":
|
case "debian-resolvconf":
|
||||||
return newDebianResolvconfManager(logf)
|
return newDebianResolvconfManager(logf)
|
||||||
case "openresolv":
|
case "openresolv":
|
||||||
return newOpenresolvManager()
|
return newOpenresolvManager(logf)
|
||||||
default:
|
default:
|
||||||
logf("[unexpected] detected unknown DNS mode %q, using direct manager as last resort", mode)
|
logf("[unexpected] detected unknown DNS mode %q, using direct manager as last resort", mode)
|
||||||
return newDirectManagerOnFS(logf, env.fs), nil
|
return newDirectManagerOnFS(logf, env.fs), nil
|
||||||
|
@ -10,20 +10,40 @@
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"tailscale.com/types/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// openresolvManager manages DNS configuration using the openresolv
|
// openresolvManager manages DNS configuration using the openresolv
|
||||||
// implementation of the `resolvconf` program.
|
// implementation of the `resolvconf` program.
|
||||||
type openresolvManager struct{}
|
type openresolvManager struct {
|
||||||
|
logf logger.Logf
|
||||||
|
}
|
||||||
|
|
||||||
func newOpenresolvManager() (openresolvManager, error) {
|
func newOpenresolvManager(logf logger.Logf) (openresolvManager, error) {
|
||||||
return openresolvManager{}, nil
|
return openresolvManager{logf}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m openresolvManager) logCmdErr(cmd *exec.Cmd, err error) {
|
||||||
|
if err == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
commandStr := fmt.Sprintf("path=%q args=%q", cmd.Path, cmd.Args)
|
||||||
|
exerr, ok := err.(*exec.ExitError)
|
||||||
|
if !ok {
|
||||||
|
m.logf("error running command %s: %v", commandStr, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
m.logf("error running command %s stderr=%q exitCode=%d: %v", commandStr, exerr.Stderr, exerr.ExitCode(), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m openresolvManager) deleteTailscaleConfig() error {
|
func (m openresolvManager) deleteTailscaleConfig() error {
|
||||||
cmd := exec.Command("resolvconf", "-f", "-d", "tailscale")
|
cmd := exec.Command("resolvconf", "-f", "-d", "tailscale")
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
m.logCmdErr(cmd, err)
|
||||||
return fmt.Errorf("running %s: %s", cmd, out)
|
return fmt.Errorf("running %s: %s", cmd, out)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -41,6 +61,7 @@ func (m openresolvManager) SetDNS(config OSConfig) error {
|
|||||||
cmd.Stdin = &stdin
|
cmd.Stdin = &stdin
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
m.logCmdErr(cmd, err)
|
||||||
return fmt.Errorf("running %s: %s", cmd, out)
|
return fmt.Errorf("running %s: %s", cmd, out)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -83,6 +104,7 @@ func (m openresolvManager) GetBaseConfig() (OSConfig, error) {
|
|||||||
cmd := exec.Command("resolvconf", args...)
|
cmd := exec.Command("resolvconf", args...)
|
||||||
cmd.Stdout = &buf
|
cmd.Stdout = &buf
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
|
m.logCmdErr(cmd, err)
|
||||||
return OSConfig{}, err
|
return OSConfig{}, err
|
||||||
}
|
}
|
||||||
return readResolv(&buf)
|
return readResolv(&buf)
|
||||||
|
Loading…
Reference in New Issue
Block a user