@@ -8,24 +8,14 @@ import (
15− "github.com/coreos/go-systemd/activation"
14+ "golang.org/x/sync/errgroup"
16 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
16 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
17 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options/util"
17 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options/util"
18 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/logger"
18 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/logger"
19− "golang.org/x/sync/errgroup"
22−// listenFdsStart corresponds to `SD_LISTEN_FDS_START`.
23−// Since the 3 first file descriptors in every linux process is
24−// stdin, stdout and stderr. The first usable file descriptor is 3.
25−// systemd-socket-activate will always assume that the first socket will be
26−// 3 and the rest follow.
31// Server represents an HTTP or HTTPS server.
21// Server represents an HTTP or HTTPS server.
@@ -83,27 +73,6 @@ type server struct {
83 fdFiles []*os.File
73 fdFiles []*os.File
86−// convert a string filedescriptor to an actual listener
87−func (s *server) fdToListener(bindAddress string) (net.Listener, error) {
88− fd, err := strconv.Atoi(bindAddress)
90− return nil, fmt.Errorf("listen failed: fd with name is not implemented yet")
92− fdIndex := fd - listenFdsStart
94− if len(s.fdFiles) == 0 {
95− s.fdFiles = activation.Files(true)
100− if fdIndex < 0 || fdIndex >= l || l == 0 {
101− return nil, fmt.Errorf("listen failed: fd outside of range of available file descriptors")
104− return net.FileListener(s.fdFiles[fdIndex])
107// setupListener sets the server listener if the HTTP server is enabled.
76// setupListener sets the server listener if the HTTP server is enabled.
108// The HTTP server can be disabled by setting the BindAddress to "-" or by
77// The HTTP server can be disabled by setting the BindAddress to "-" or by
109// leaving it empty.
78// leaving it empty.
@@ -120,13 +89,7 @@ func (s *server) setupListener(opts Opts) error {
120 // to the program is indeed a net.Listener and starts using it
89 // to the program is indeed a net.Listener and starts using it
121 // without setting up a new listener.
90 // without setting up a new listener.
122 if strings.HasPrefix(strings.ToLower(opts.BindAddress), "fd:") {
91 if strings.HasPrefix(strings.ToLower(opts.BindAddress), "fd:") {
123− listenAddr := opts.BindAddress[3:]
92+ return s.checkSystemdSocketSupport(opts)
124− listener, err := s.fdToListener(listenAddr)
126− err = fmt.Errorf("listen (%s, %s) failed: %v", "file", listenAddr, err)
128− s.listener = listener
132 networkType := getNetworkScheme(opts.BindAddress)
95 networkType := getNetworkScheme(opts.BindAddress)
@@ -134,7 +97,7 @@ func (s *server) setupListener(opts Opts) error {
135 listener, err := net.Listen(networkType, listenAddr)
98 listener, err := net.Listen(networkType, listenAddr)
136 if err != nil {
99 if err != nil {
137− return fmt.Errorf("listen (%s, %s) failed: %v", networkType, listenAddr, err)
100+ return fmt.Errorf("listen (%s, %s) failed: %w", networkType, listenAddr, err)
139 s.listener = listener
102 s.listener = listener