From 986b8284d6e9b770113dd39599b429202dc2a236 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Mon, 13 May 2024 21:13:10 +0200 Subject: [PATCH] lib/sd-activation: wrap coreos/go-systemd It fails to build on plan9, which is part of the rclone CI matrix, and the PR fixing it upstream doesn't seem to be getting traction. Stub it on our side, we can still remove this once it gets merged. --- cmd/serve/sftp/server.go | 2 +- lib/http/server.go | 2 +- lib/sdactivation/sdactivation_stub.go | 24 ++++++++++++++++++++++++ lib/sdactivation/sdactivation_unix.go | 24 ++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 lib/sdactivation/sdactivation_stub.go create mode 100644 lib/sdactivation/sdactivation_unix.go diff --git a/cmd/serve/sftp/server.go b/cmd/serve/sftp/server.go index 0b89e03cc8037..843b3c640df9b 100644 --- a/cmd/serve/sftp/server.go +++ b/cmd/serve/sftp/server.go @@ -21,13 +21,13 @@ import ( "path/filepath" "strings" - sdActivation "github.com/coreos/go-systemd/v22/activation" "github.com/rclone/rclone/cmd/serve/proxy" "github.com/rclone/rclone/cmd/serve/proxy/proxyflags" "github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs/config" "github.com/rclone/rclone/lib/env" "github.com/rclone/rclone/lib/file" + sdActivation "github.com/rclone/rclone/lib/sdactivation" "github.com/rclone/rclone/vfs" "github.com/rclone/rclone/vfs/vfscommon" "golang.org/x/crypto/ssh" diff --git a/lib/http/server.go b/lib/http/server.go index 945925d9c9b03..34bf791719712 100644 --- a/lib/http/server.go +++ b/lib/http/server.go @@ -18,11 +18,11 @@ import ( "sync" "time" - sdActivation "github.com/coreos/go-systemd/v22/activation" "github.com/go-chi/chi/v5" "github.com/rclone/rclone/fs" "github.com/rclone/rclone/fs/config/flags" "github.com/rclone/rclone/lib/atexit" + sdActivation "github.com/rclone/rclone/lib/sdactivation" "github.com/spf13/pflag" ) diff --git a/lib/sdactivation/sdactivation_stub.go b/lib/sdactivation/sdactivation_stub.go new file mode 100644 index 0000000000000..a39babe590651 --- /dev/null +++ b/lib/sdactivation/sdactivation_stub.go @@ -0,0 +1,24 @@ +//go:build windows || plan9 +// +build windows plan9 + +// Package sd_activate provides support for systemd socket activation, +// wrapping the coreos/go-systemd package. +// This wraps the underlying go-systemd binary, as it fails to build on plan9 +// https://github.com/coreos/go-systemd/pull/440 +package sdactivation + +import ( + "net" +) + +// ListenersWithNames maps a listener name to a set of net.Listener instances. +// This wraps the underlying go-systemd binary, as it fails to build on plan9 +// https://github.com/coreos/go-systemd/pull/440 +func ListenersWithNames() (map[string][]net.Listener, error) { + return make(map[string][]net.Listener), nil +} + +// Listeners returns a slice containing a net.Listener for each matching socket type passed to this process. +func Listeners() ([]net.Listener, error) { + return nil, nil +} diff --git a/lib/sdactivation/sdactivation_unix.go b/lib/sdactivation/sdactivation_unix.go new file mode 100644 index 0000000000000..523321bcf9785 --- /dev/null +++ b/lib/sdactivation/sdactivation_unix.go @@ -0,0 +1,24 @@ +//go:build !windows && !plan9 +// +build !windows,!plan9 + +// Package sdactivation provides support for systemd socket activation, wrapping +// the coreos/go-systemd package. +// This wraps the underlying go-systemd library, as it fails to build on plan9 +// https://github.com/coreos/go-systemd/pull/440 +package sdactivation + +import ( + "net" + + sdActivation "github.com/coreos/go-systemd/v22/activation" +) + +// ListenersWithNames maps a listener name to a set of net.Listener instances. +func ListenersWithNames() (map[string][]net.Listener, error) { + return sdActivation.ListenersWithNames() +} + +// Listeners returns a slice containing a net.Listener for each matching socket type passed to this process. +func Listeners() ([]net.Listener, error) { + return sdActivation.Listeners() +}