Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/systemd/snapd.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ SuccessExitStatus=42
RestartPreventExitStatus=42
KillMode=process
KeyringMode=shared
FileDescriptorStoreMax=1024

[Install]
WantedBy=multi-user.target
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ require (
github.com/canonical/go-sp800.90a-drbg v0.0.0-20210314144037-6eeb1040d6c3 // indirect
github.com/canonical/go-tpm2 v1.15.0
github.com/chai2010/gettext-go v1.0.3
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
github.com/godbus/dbus/v5 v5.1.0
github.com/gorilla/mux v1.8.0
github.com/gvalkov/golang-evdev v0.0.0-20191114124502-287e62b94bcb
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ github.com/canonical/tcglog-parser v0.0.0-20240924110432-d15eaf652981 h1:vrUzSfb
github.com/canonical/tcglog-parser v0.0.0-20240924110432-d15eaf652981/go.mod h1:ywdPBqUGkuuiitPpVWCfilf2/gq+frhq4CNiNs9KyHU=
github.com/chai2010/gettext-go v1.0.3 h1:9liNh8t+u26xl5ddmWLmsOsdNLwkdRTg5AG+JnTiM80=
github.com/chai2010/gettext-go v1.0.3/go.mod h1:y+wnP2cHYaVj19NZhYKAwEMH2CI1gNHeQQ+5AjwawxA=
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf h1:iW4rZ826su+pqaw19uhpSCzhj44qo35pNgKFGqzDKkU=
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/frankban/quicktest v1.2.2 h1:xfmOhhoH5fGPgbEAlhLpJH9p0z/0Qizio9osmvn9IUY=
Expand Down
25 changes: 11 additions & 14 deletions netutil/activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ import (
"net"
"os"

"github.com/coreos/go-systemd/activation"

"github.com/snapcore/snapd/logger"
"github.com/snapcore/snapd/systemd/fdstore"
)

// GetListener tries to get a listener for the given socket path from the
Expand Down Expand Up @@ -73,18 +72,16 @@ func GetListener(socketPath string, listenerMap map[string]net.Listener) (net.Li

// ActivationListeners builds a map of addresses to listeners that were passed
// during systemd activation
func ActivationListeners() (lns map[string]net.Listener, err error) {
// pass false to keep LISTEN_* environment variables passed by systemd
files := activation.Files(false)
lns = make(map[string]net.Listener, len(files))
func ActivationListeners() (listenerByAddr map[string]net.Listener, err error) {
listeners, err := fdstore.ActivationListeners()
if err != nil {
return nil, err
}

for _, f := range files {
ln, err := net.FileListener(f)
if err != nil {
return nil, err
}
addr := ln.Addr().String()
lns[addr] = ln
listenerByAddr = make(map[string]net.Listener, len(listeners))
for _, listener := range listeners {
addr := listener.Addr().String()
listenerByAddr[addr] = listener
}
return lns, nil
return listenerByAddr, nil
}
1 change: 0 additions & 1 deletion packaging/debian-sid/control
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Build-Depends: debhelper (>= 13),
golang-github-bmatcuk-doublestar-dev,
golang-github-chai2010-gettext-go-dev,
golang-github-coreos-bbolt-dev,
golang-github-coreos-go-systemd-dev,
golang-github-gorilla-mux-dev,
golang-github-jessevdk-go-flags-dev,
golang-github-juju-ratelimit-dev,
Expand Down
3 changes: 0 additions & 3 deletions packaging/fedora/snapd.spec
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ Provides: %{name}-login-service%{?_isa} = 1.33
%if ! 0%{?with_bundled}
BuildRequires: golang(github.com/bmatcuk/doublestar/v4)
BuildRequires: golang(github.com/chai2010/gettext-go)
BuildRequires: golang(github.com/coreos/go-systemd/activation)
BuildRequires: golang(github.com/godbus/dbus/v5)
BuildRequires: golang(github.com/godbus/dbus/v5/introspect)
BuildRequires: golang(github.com/gorilla/mux)
Expand Down Expand Up @@ -277,7 +276,6 @@ BuildArch: noarch
%if ! 0%{?with_bundled}
Requires: golang(github.com/bmatcuk/doublestar/v4)
Requires: golang(github.com/chai2010/gettext-go)
Requires: golang(github.com/coreos/go-systemd/activation)
Requires: golang(github.com/godbus/dbus/v5)
Requires: golang(github.com/godbus/dbus/v5/introspect)
Requires: golang(github.com/gorilla/mux)
Expand Down Expand Up @@ -309,7 +307,6 @@ Requires: golang(gopkg.in/yaml.v3)
# *sigh*... I hate golang...
Provides: bundled(golang(github.com/bmatcuk/doublestar/v4))
Provides: bundled(golang(github.com/chai2010/gettext-go))
Provides: bundled(golang(github.com/coreos/go-systemd/activation))
Provides: bundled(golang(github.com/godbus/dbus/v5))
Provides: bundled(golang(github.com/godbus/dbus/v5/introspect))
Provides: bundled(golang(github.com/gorilla/mux))
Expand Down
63 changes: 63 additions & 0 deletions systemd/fdstore/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// -*- Mode: Go; indent-tabs-mode: t -*-

/*
* Copyright (C) 2025 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

package fdstore

import (
"net"
"os"

"github.com/snapcore/snapd/testutil"
)

func MockOsGetpid(f func() int) (restore func()) {
return testutil.Mock(&osGetpid, f)
}

func MockUnixCloseOnExec(f func(fd int)) (restore func()) {
return testutil.Mock(&unixCloseOnExec, f)
}

func MockUnixDup(f func(oldfd int) (fd int, err error)) (restore func()) {
return testutil.Mock(&unixDup, f)
}

func MockSdNotify(f func(notifyState string) error) (restore func()) {
return testutil.Mock(&sdNotify, f)
}

func MockSdNotifyWithFds(f func(notifyState string, files ...*os.File) error) (restore func()) {
return testutil.Mock(&sdNotifyWithFds, f)
}

func MockNetFileListener(f func(f *os.File) (ln net.Listener, err error)) (restore func()) {
return testutil.Mock(&netFileListener, f)
}

func MockOsFileClose(f func(*os.File) error) (restore func()) {
return testutil.Mock(&osFileClose, f)
}

func KnownFdNames() map[FdName]bool {
return knownFdNames
}

func Clear() {
fdstore = nil
}
Loading
Loading