Add some logging

This commit is contained in:
Owen
2025-11-30 14:28:25 -05:00
parent e10e8077ea
commit 5d129b4fce

View File

@@ -9,6 +9,8 @@ import (
"net/netip"
"os/exec"
"strings"
"github.com/fosrl/newt/logger"
)
const (
@@ -209,11 +211,14 @@ func (d *DarwinDNSConfigurator) parseServerAddresses(output []byte) []netip.Addr
// flushDNSCache flushes the system DNS cache
func (d *DarwinDNSConfigurator) flushDNSCache() error {
logger.Debug("Flushing dscacheutil cache")
cmd := exec.Command(dscacheutilPath, "-flushcache")
if err := cmd.Run(); err != nil {
return fmt.Errorf("flush cache: %w", err)
}
logger.Debug("Flushing mDNSResponder cache")
cmd = exec.Command("killall", "-HUP", "mDNSResponder")
if err := cmd.Run(); err != nil {
// Non-fatal, mDNSResponder might not be running
@@ -228,6 +233,8 @@ func (d *DarwinDNSConfigurator) runScutil(commands string) ([]byte, error) {
// Wrap commands with open/quit
wrapped := fmt.Sprintf("open\n%squit\n", commands)
logger.Debug("Running scutil with commands:\n%s\n", wrapped)
cmd := exec.Command(scutilPath)
cmd.Stdin = strings.NewReader(wrapped)
@@ -236,5 +243,7 @@ func (d *DarwinDNSConfigurator) runScutil(commands string) ([]byte, error) {
return nil, fmt.Errorf("scutil command failed: %w, output: %s", err, output)
}
logger.Debug("scutil output:\n%s\n", output)
return output, nil
}