From d1a15ced6c5c3d51d7011b9c9665f1810474df97 Mon Sep 17 00:00:00 2001 From: jochens Date: Fri, 13 Nov 2026 03:15:30 +0100 Subject: [PATCH] zfs: the keeper tests' socket directory is the shortest that works MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the test's temporary directory, or /tmp when the socket path would pass 100 characters, so a long TMPDIR cannot fail the bind. Builds: design 42 zfs-owns-zfs ยง18, A-37 --- modules/zfs/cmd/zfs-tools/keeper_test.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/modules/zfs/cmd/zfs-tools/keeper_test.go b/modules/zfs/cmd/zfs-tools/keeper_test.go index bd4bd1b44..d1c790a0e 100644 --- a/modules/zfs/cmd/zfs-tools/keeper_test.go +++ b/modules/zfs/cmd/zfs-tools/keeper_test.go @@ -65,6 +65,17 @@ func TestTheKeeperAnswersOnlyItsClosedListOfCalls(t *testing.T) { } } +// shortTempDir is a directory in the test's temporary directory, or in /tmp when a socket in it (`k/k.sock`) would pass 100 +// characters, the most a unix socket path takes, so a long TMPDIR cannot fail the bind. +func shortTempDir(prefix string) (string, error) { + dir, err := os.MkdirTemp("", prefix) + if err != nil || len(filepath.Join(dir, "k", "k.sock")) <= 100 { + return dir, err + } + os.RemoveAll(dir) + return os.MkdirTemp("/tmp", prefix) +} + // A-37: only root opens the socket; a root process says and reads through it as through a bus of its own, and with no // keeper answering it acts as with the bus down, with a warning (A-8). func TestOnlyRootOpensTheKeepersSocketAndANeedlessKeeperIsTheBusDown(t *testing.T) { @@ -73,7 +84,7 @@ func TestOnlyRootOpensTheKeepersSocketAndANeedlessKeeperIsTheBusDown(t *testing. k := &Keeper{Emit: func(string, any) error { return nil }, States: st, Call: func(string, any) (json.RawMessage, error) { return nil, errors.New("down") }, PeerOf: func(net.Conn) (int, error) { return uid, nil }} - dir, err := os.MkdirTemp("", "zk") + dir, err := shortTempDir("zk") if err != nil { t.Fatal(err) } @@ -148,7 +159,7 @@ func TestOnlyRootOpensTheKeepersSocketAndANeedlessKeeperIsTheBusDown(t *testing. // A-37: a root process whose keeper does not answer acts as with the bus down and says so, once, in a warning, for the // hand acts, the forgetting of applied keys and the pause alike. func TestAKeeperThatDoesNotAnswerIsWarnedOnce(t *testing.T) { - dir, err := os.MkdirTemp("", "keeper-down") + dir, err := shortTempDir("kd") if err != nil { t.Fatal(err) }