2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2020-07-14 14:12:00 +01:00
|
|
|
|
2021-08-05 23:42:39 +01:00
|
|
|
//go:build linux || freebsd || openbsd
|
2021-04-29 20:34:34 +01:00
|
|
|
|
2020-07-31 21:27:09 +01:00
|
|
|
package dns
|
2020-07-14 14:12:00 +01:00
|
|
|
|
|
|
|
import (
|
2023-10-11 16:08:08 +01:00
|
|
|
"bytes"
|
2020-07-14 14:12:00 +01:00
|
|
|
"os/exec"
|
|
|
|
)
|
|
|
|
|
2021-09-05 07:40:48 +01:00
|
|
|
func resolvconfStyle() string {
|
|
|
|
if _, err := exec.LookPath("resolvconf"); err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
2023-10-11 16:08:08 +01:00
|
|
|
output, err := exec.Command("resolvconf", "--version").CombinedOutput()
|
|
|
|
if err != nil {
|
2021-09-05 07:40:48 +01:00
|
|
|
// Debian resolvconf doesn't understand --version, and
|
|
|
|
// exits with a specific error code.
|
2021-04-11 07:31:00 +01:00
|
|
|
if exitErr, ok := err.(*exec.ExitError); ok && exitErr.ExitCode() == 99 {
|
2021-09-05 07:40:48 +01:00
|
|
|
return "debian"
|
2021-04-11 06:37:13 +01:00
|
|
|
}
|
|
|
|
}
|
2023-10-11 16:08:08 +01:00
|
|
|
if bytes.HasPrefix(output, []byte("Debian resolvconf")) {
|
|
|
|
return "debian"
|
|
|
|
}
|
2021-09-05 07:40:48 +01:00
|
|
|
// Treat everything else as openresolv, by far the more popular implementation.
|
|
|
|
return "openresolv"
|
2020-07-14 14:12:00 +01:00
|
|
|
}
|