mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
chore(systemd): use activation.Listeners instead of Files
Use this Listeners() API that was exposed to save a few more lines of boiler plate code. Docker-DCO-1.1-Signed-off-by: Brandon Philips <brandon.philips@coreos.com> (github: philips)
This commit is contained in:
parent
f82d1291cc
commit
def0952606
1 changed files with 8 additions and 14 deletions
|
@ -2,7 +2,6 @@ package systemd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
@ -12,8 +11,13 @@ import (
|
||||||
// ListenFD returns the specified socket activated files as a slice of
|
// ListenFD returns the specified socket activated files as a slice of
|
||||||
// net.Listeners or all of the activated files if "*" is given.
|
// net.Listeners or all of the activated files if "*" is given.
|
||||||
func ListenFD(addr string) ([]net.Listener, error) {
|
func ListenFD(addr string) ([]net.Listener, error) {
|
||||||
files := activation.Files(false)
|
// socket activation
|
||||||
if files == nil || len(files) == 0 {
|
listeners, err := activation.Listeners(false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if listeners == nil || len(listeners) == 0 {
|
||||||
return nil, errors.New("No sockets found")
|
return nil, errors.New("No sockets found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,20 +28,10 @@ func ListenFD(addr string) ([]net.Listener, error) {
|
||||||
|
|
||||||
fdNum, _ := strconv.Atoi(addr)
|
fdNum, _ := strconv.Atoi(addr)
|
||||||
fdOffset := fdNum - 3
|
fdOffset := fdNum - 3
|
||||||
if (addr != "*") && (len(files) < int(fdOffset)+1) {
|
if (addr != "*") && (len(listeners) < int(fdOffset)+1) {
|
||||||
return nil, errors.New("Too few socket activated files passed in")
|
return nil, errors.New("Too few socket activated files passed in")
|
||||||
}
|
}
|
||||||
|
|
||||||
// socket activation
|
|
||||||
listeners := make([]net.Listener, len(files))
|
|
||||||
for i, f := range files {
|
|
||||||
var err error
|
|
||||||
listeners[i], err = net.FileListener(f)
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("Error setting up FileListener for fd %d: %s", f.Fd(), err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if addr == "*" {
|
if addr == "*" {
|
||||||
return listeners, nil
|
return listeners, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue