From 52f87aee8ec88858dcda6465cad6a9265def6699 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 26 Apr 2020 14:57:18 +0200 Subject: [PATCH] Accept data from systemd sockets at the same time as everything else --- dnscrypt-proxy/config.go | 7 +++---- dnscrypt-proxy/systemd_android.go | 2 +- dnscrypt-proxy/systemd_free.go | 2 +- dnscrypt-proxy/systemd_linux.go | 14 +++----------- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/dnscrypt-proxy/config.go b/dnscrypt-proxy/config.go index 0d85865a..384ac000 100644 --- a/dnscrypt-proxy/config.go +++ b/dnscrypt-proxy/config.go @@ -557,16 +557,15 @@ func ConfigLoad(proxy *Proxy, flags *ConfigFlags) error { for _, listenAddrStr := range proxy.localDoHListenAddresses { proxy.addLocalDoHListener(listenAddrStr) } + if err := proxy.addSystemDListeners(); err != nil { + dlog.Fatal(err) + } _ = pidfile.Write() // if 'userName' is set and we are the parent process drop privilege and exit if len(proxy.userName) > 0 && !proxy.child { proxy.dropPrivilege(proxy.userName, FileDescriptors) dlog.Fatal("Dropping privileges is not supporting on this operating system. Unset `user_name` in the configuration file.") } - if err := proxy.SystemDListeners(); err != nil { - dlog.Fatal(err) - } - if !config.OfflineMode { if err := config.loadSources(proxy); err != nil { return err diff --git a/dnscrypt-proxy/systemd_android.go b/dnscrypt-proxy/systemd_android.go index 8b806ba3..6467acaf 100644 --- a/dnscrypt-proxy/systemd_android.go +++ b/dnscrypt-proxy/systemd_android.go @@ -1,5 +1,5 @@ package main -func (proxy *Proxy) SystemDListeners() error { +func (proxy *Proxy) addSystemDListeners() error { return nil } diff --git a/dnscrypt-proxy/systemd_free.go b/dnscrypt-proxy/systemd_free.go index b18f1b62..ae6f99e5 100644 --- a/dnscrypt-proxy/systemd_free.go +++ b/dnscrypt-proxy/systemd_free.go @@ -2,6 +2,6 @@ package main -func (proxy *Proxy) SystemDListeners() error { +func (proxy *Proxy) addSystemDListeners() error { return nil } diff --git a/dnscrypt-proxy/systemd_linux.go b/dnscrypt-proxy/systemd_linux.go index 6cf91e22..9b4eafd3 100644 --- a/dnscrypt-proxy/systemd_linux.go +++ b/dnscrypt-proxy/systemd_linux.go @@ -3,14 +3,13 @@ package main import ( - "fmt" "net" "github.com/coreos/go-systemd/activation" "github.com/jedisct1/dlog" ) -func (proxy *Proxy) SystemDListeners() error { +func (proxy *Proxy) addSystemDListeners() error { files := activation.Files(true) if len(files) > 0 { @@ -21,20 +20,13 @@ func (proxy *Proxy) SystemDListeners() error { } for i, file := range files { defer file.Close() - ok := false if listener, err := net.FileListener(file); err == nil { dlog.Noticef("Wiring systemd TCP socket #%d, %s, %s", i, file.Name(), listener.Addr()) - ok = true - go proxy.tcpListener(listener.(*net.TCPListener)) + proxy.tcpListener = append(proxy.tcpListener, listener.(*net.TCPListener)) } else if pc, err := net.FilePacketConn(file); err == nil { dlog.Noticef("Wiring systemd UDP socket #%d, %s, %s", i, file.Name(), pc.LocalAddr()) - ok = true - go proxy.udpListener(pc.(*net.UDPConn)) - } - if !ok { - return fmt.Errorf("Could not wire systemd socket #%d, %s", i, file.Name()) + proxy.udpListener = append(proxy.udpListener, listener.(*net.UDPConn)) } } - return nil }