1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
//go:build !windows
// +build !windows
package main
import (
"crypto/tls"
"net"
"os"
"syscall"
"github.com/containerd/containerd/sys"
"github.com/coreos/go-systemd/v22/activation"
"github.com/pkg/errors"
)
const socketScheme = "unix://"
func init() {
syscall.Umask(0)
}
func listenFD(addr string, tlsConfig *tls.Config) (net.Listener, error) {
var (
err error
listeners []net.Listener
)
// socket activation
if tlsConfig != nil {
listeners, err = activation.TLSListeners(tlsConfig)
} else {
listeners, err = activation.Listeners()
}
if err != nil {
return nil, err
}
if len(listeners) == 0 {
return nil, errors.New("no sockets found via socket activation: make sure the service was started by systemd")
}
// default to first fd
if addr == "" {
return listeners[0], nil
}
//TODO: systemd fd selection (default is 3)
return nil, errors.New("not supported yet")
}
func getLocalListener(listenerPath, _ string) (net.Listener, error) {
uid := os.Getuid()
l, err := sys.GetLocalListener(listenerPath, uid, uid)
if err != nil {
return nil, err
}
if err := os.Chmod(listenerPath, 0666); err != nil {
l.Close()
return nil, err
}
return l, nil
}
func groupToSecurityDescriptor(_ string) (string, error) {
return "", nil
}
|