mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-27 12:05:40 +00:00
3511d1f8a2
When we're starting child processes on Windows that are CLI programs that don't need to output to a console, we should pass in DETACHED_PROCESS as a CreationFlag on SysProcAttr. This prevents the OS from even creating a console for the child (and paying the associated time/space penalty for new conhost processes). This is more efficient than letting the OS create the console window and then subsequently trying to hide it, which we were doing at a few callsites. Fixes #12270 Signed-off-by: Aaron Klotz <aaron@tailscale.com>
35 lines
788 B
Go
35 lines
788 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package dns
|
|
|
|
import (
|
|
"fmt"
|
|
"os/exec"
|
|
"syscall"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
func flushCaches() error {
|
|
cmd := exec.Command("ipconfig", "/flushdns")
|
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
|
CreationFlags: windows.DETACHED_PROCESS,
|
|
}
|
|
out, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
return fmt.Errorf("%v (output: %s)", err, out)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Flush clears the local resolver cache.
|
|
//
|
|
// Only Windows has a public dns.Flush, needed in router_windows.go. Other
|
|
// platforms like Linux need a different flush implementation depending on
|
|
// the DNS manager. There is a FlushCaches method on the manager which
|
|
// can be used on all platforms.
|
|
func Flush() error {
|
|
return flushCaches()
|
|
}
|