Skip to content

Commit

Permalink
Merge pull request containers#2117 from anderbubble/dircopy-leave-socket
Browse files Browse the repository at this point in the history
Update copy.DirCopy to leave sockets in the file system
  • Loading branch information
openshift-merge-bot[bot] authored Nov 4, 2024
2 parents 5958b09 + 6e4298e commit 960e8dd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 1 addition & 4 deletions drivers/copy/copy_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"errors"
"fmt"
"io"
"net"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -199,11 +198,9 @@ func DirCopy(srcDir, dstDir string, copyMode Mode, copyXattrs bool) error {
}

case mode&os.ModeSocket != 0:
s, err := net.Listen("unix", dstPath)
if err != nil {
if err := unix.Mknod(dstPath, stat.Mode, int(stat.Rdev)); err != nil {
return err
}
s.Close()

case mode&os.ModeDevice != 0:
if unshare.IsRootless() {
Expand Down
6 changes: 6 additions & 0 deletions drivers/copy/copy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package copy
import (
"fmt"
"math/rand"
"net"
"os"
"path/filepath"
"syscall"
Expand Down Expand Up @@ -83,6 +84,11 @@ func randomMode(baseMode int) os.FileMode {

func populateSrcDir(t *testing.T, srcDir string, remainingDepth int) {
if remainingDepth == 0 {
socketPath := filepath.Join(srcDir, "srcsocket")
s, err := net.ListenUnix("unix", &net.UnixAddr{Name: socketPath, Net: "unix"})
assert.NilError(t, err)
s.SetUnlinkOnClose(false)
s.Close()
return
}
aTime := time.Unix(rand.Int63(), 0)
Expand Down

0 comments on commit 960e8dd

Please sign in to comment.