mirror of
https://github.com/containers/podman.git
synced 2025-06-23 10:38:20 +08:00
Merge pull request #10416 from tych0/activation-drop-FDNAMES
pkg/systemd: don't require LISTEN_FDNAMES for socket activation
This commit is contained in:
@ -25,11 +25,5 @@ func SocketActivated() bool {
|
||||
if err != nil || nfds == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
// "github.com/coreos/go-systemd/v22/activation" will use and validate this variable's
|
||||
// value. We're just providing a fast fail
|
||||
if _, found = os.LookupEnv("LISTEN_FDNAMES"); !found {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
32
pkg/systemd/activation_test.go
Normal file
32
pkg/systemd/activation_test.go
Normal file
@ -0,0 +1,32 @@
|
||||
package systemd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSocketActivated(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
assert.False(SocketActivated())
|
||||
|
||||
// different pid
|
||||
assert.NoError(os.Setenv("LISTEN_PID", "1"))
|
||||
assert.False(SocketActivated())
|
||||
|
||||
// same pid no fds
|
||||
assert.NoError(os.Setenv("LISTEN_PID", fmt.Sprintf("%d", os.Getpid())))
|
||||
assert.NoError(os.Setenv("LISTEN_FDS", "0"))
|
||||
assert.False(SocketActivated())
|
||||
|
||||
// same pid some fds
|
||||
assert.NoError(os.Setenv("LISTEN_FDS", "1"))
|
||||
assert.True(SocketActivated())
|
||||
|
||||
// FDNAME is ok too (but not required)
|
||||
assert.NoError(os.Setenv("LISTEN_FDNAMES", "/meshuggah/rocks"))
|
||||
assert.True(SocketActivated())
|
||||
}
|
Reference in New Issue
Block a user