mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-07-16 13:17:19 +02:00
8704db2476
- Skip systemd-resolved initialization on Android (ChromeOS crash fix) - Skip system DNS discovery commands on iOS mobile (sandbox restrictions) - Skip route-based DNS discovery on Android - Skip systemd resolver on Android - Add mobile platform checks to prevent sandbox access violations These changes ensure ctrld works correctly in mobile sandboxed environments where system commands and file access are restricted.
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package cli
|
|
|
|
import (
|
|
"bufio"
|
|
"bytes"
|
|
"io"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"github.com/kardianos/service"
|
|
|
|
"github.com/Control-D-Inc/ctrld/internal/router"
|
|
)
|
|
|
|
func init() {
|
|
if isAndroid() {
|
|
return
|
|
}
|
|
if r, err := newLoopbackOSConfigurator(); err == nil {
|
|
useSystemdResolved = r.Mode() == "systemd-resolved"
|
|
}
|
|
// Disable quic-go's ECN support by default, see https://github.com/quic-go/quic-go/issues/3911
|
|
if os.Getenv("QUIC_GO_DISABLE_ECN") == "" {
|
|
os.Setenv("QUIC_GO_DISABLE_ECN", "true")
|
|
}
|
|
}
|
|
|
|
func setDependencies(svc *service.Config) {
|
|
svc.Dependencies = []string{
|
|
"Wants=network-online.target",
|
|
"After=network-online.target",
|
|
"Wants=NetworkManager-wait-online.service",
|
|
"After=NetworkManager-wait-online.service",
|
|
"Wants=nss-lookup.target",
|
|
"After=nss-lookup.target",
|
|
}
|
|
if out, _ := exec.Command("networkctl", "--no-pager").CombinedOutput(); len(out) > 0 {
|
|
if wantsSystemDNetworkdWaitOnline(bytes.NewReader(out)) {
|
|
svc.Dependencies = append(svc.Dependencies, "Wants=systemd-networkd-wait-online.service")
|
|
}
|
|
}
|
|
if routerDeps := router.ServiceDependencies(); len(routerDeps) > 0 {
|
|
svc.Dependencies = append(svc.Dependencies, routerDeps...)
|
|
}
|
|
}
|
|
|
|
func setWorkingDirectory(svc *service.Config, dir string) {
|
|
svc.WorkingDirectory = dir
|
|
}
|
|
|
|
// wantsSystemDNetworkdWaitOnline reports whether "systemd-networkd-wait-online" service
|
|
// is required to be added to ctrld dependencies services.
|
|
// The input reader r is the output of "networkctl --no-pager" command.
|
|
func wantsSystemDNetworkdWaitOnline(r io.Reader) bool {
|
|
scanner := bufio.NewScanner(r)
|
|
// Skip header
|
|
scanner.Scan()
|
|
configured := false
|
|
for scanner.Scan() {
|
|
fields := strings.Fields(scanner.Text())
|
|
if len(fields) > 0 && fields[len(fields)-1] == "configured" {
|
|
configured = true
|
|
break
|
|
}
|
|
}
|
|
return configured
|
|
}
|