dnscrypt-proxy/dnscrypt-proxy/systemd_linux.go

36 lines
1.0 KiB
Go
Raw Permalink Normal View History

2021-09-23 19:16:26 +02:00
//go:build !android
// +build !android
package main
import (
"net"
"github.com/coreos/go-systemd/activation"
"github.com/jedisct1/dlog"
)
func (proxy *Proxy) addSystemDListeners() error {
files := activation.Files(true)
2019-09-16 15:46:39 +02:00
if len(files) > 0 {
2019-10-03 15:46:37 +02:00
if len(proxy.userName) > 0 || proxy.child {
dlog.Fatal(
"Systemd activated sockets are incompatible with privilege dropping. Remove activated sockets and fill `listen_addresses` in the dnscrypt-proxy configuration file instead.",
)
2019-09-16 15:46:39 +02:00
}
dlog.Warn("Systemd sockets are untested and unsupported - use at your own risk")
}
for i, file := range files {
defer file.Close()
if listener, err := net.FileListener(file); err == nil {
2020-06-19 20:16:21 +02:00
proxy.registerTCPListener(listener.(*net.TCPListener))
dlog.Noticef("Wiring systemd TCP socket #%d, %s, %s", i, file.Name(), listener.Addr())
} else if pc, err := net.FilePacketConn(file); err == nil {
2020-06-19 20:16:21 +02:00
proxy.registerUDPListener(pc.(*net.UDPConn))
dlog.Noticef("Wiring systemd UDP socket #%d, %s, %s", i, file.Name(), pc.LocalAddr())
}
}
return nil
}