systemd_linux.go 1005 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11
package main

import (
	"net"

	"github.com/coreos/go-systemd/activation"
	"github.com/coreos/go-systemd/daemon"
	"github.com/jedisct1/dlog"
)

func (proxy *Proxy) SystemDListeners() error {
12 13
	files := activation.Files(true)

14 15 16 17
	if len(files) > 0 && (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.")
	}

18 19 20 21 22 23 24
	for i, file := range files {
		if listener, err := net.FileListener(file); err == nil {
			dlog.Noticef("Wiring systemd TCP socket #%d, %s, %s", i, file.Name(), listener.Addr())
			go 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())
			go proxy.udpListener(pc.(*net.UDPConn))
25
		}
26
		file.Close()
27
	}
28

29 30 31 32 33 34
	return nil
}

func SystemDNotify() {
	daemon.SdNotify(false, "READY=1")
}