Skip to content

Commit cd143ee

Browse files
author
Tibor Vass
committed
fstest: have CreateSocket actually create a socket
Using syscall package to create socket file, because net.Listen's Close() method removes the socket file and not closing the listener would result in leaking an fd. Signed-off-by: Tibor Vass <[email protected]>
1 parent f2a389a commit cd143ee

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

fs/fstest/file.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import (
2020
"bytes"
2121
"io"
2222
"math/rand"
23-
"net"
2423
"os"
2524
"path/filepath"
25+
"syscall"
2626
"time"
2727
)
2828

@@ -158,11 +158,15 @@ func Link(oldname, newname string) Applier {
158158
func CreateSocket(name string, perm os.FileMode) Applier {
159159
return applyFn(func(root string) error {
160160
fullPath := filepath.Join(root, name)
161-
ln, err := net.Listen("unix", fullPath)
161+
fd, err := syscall.Socket(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)
162162
if err != nil {
163163
return err
164164
}
165-
defer ln.Close()
165+
defer syscall.Close(fd)
166+
sa := &syscall.SockaddrUnix{Name: fullPath}
167+
if err := syscall.Bind(fd, sa); err != nil {
168+
return err
169+
}
166170
return os.Chmod(fullPath, perm)
167171
})
168172
}

fs/fstest/testsuite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ var (
9090
Symlink("libnothing.so", "/usr/local/lib/libnothing.so.2"),
9191
CreateDir("/home", 0755),
9292
CreateDir("/home/derek", 0700),
93-
CreateDir("/var/run/socket", 0700),
93+
// TODO: CreateSocket: how should Sockets be handled in continuity?
9494
)
9595

9696
// basicTest covers basic operations

0 commit comments

Comments
 (0)