Skip to content

Commit 2d19196

Browse files
Merge pull request containers#10416 from tych0/activation-drop-FDNAMES
pkg/systemd: don't require LISTEN_FDNAMES for socket activation
2 parents 8c7ce94 + 364e8a2 commit 2d19196

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

pkg/systemd/activation.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,5 @@ func SocketActivated() bool {
2525
if err != nil || nfds == 0 {
2626
return false
2727
}
28-
29-
// "github.com/coreos/go-systemd/v22/activation" will use and validate this variable's
30-
// value. We're just providing a fast fail
31-
if _, found = os.LookupEnv("LISTEN_FDNAMES"); !found {
32-
return false
33-
}
3428
return true
3529
}

pkg/systemd/activation_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package systemd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"testing"
7+
8+
"github.com/stretchr/testify/assert"
9+
)
10+
11+
func TestSocketActivated(t *testing.T) {
12+
assert := assert.New(t)
13+
14+
assert.False(SocketActivated())
15+
16+
// different pid
17+
assert.NoError(os.Setenv("LISTEN_PID", "1"))
18+
assert.False(SocketActivated())
19+
20+
// same pid no fds
21+
assert.NoError(os.Setenv("LISTEN_PID", fmt.Sprintf("%d", os.Getpid())))
22+
assert.NoError(os.Setenv("LISTEN_FDS", "0"))
23+
assert.False(SocketActivated())
24+
25+
// same pid some fds
26+
assert.NoError(os.Setenv("LISTEN_FDS", "1"))
27+
assert.True(SocketActivated())
28+
29+
// FDNAME is ok too (but not required)
30+
assert.NoError(os.Setenv("LISTEN_FDNAMES", "/meshuggah/rocks"))
31+
assert.True(SocketActivated())
32+
}

0 commit comments

Comments
 (0)