From 62d30c763174bb3741e1e63f258aff9fa4221b95 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Mon, 23 Mar 2015 10:27:22 +1100 Subject: [PATCH] Fixed a deadlock in FlushFSTest.Dup2. --- samples/flushfs/flush_fs_test.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/samples/flushfs/flush_fs_test.go b/samples/flushfs/flush_fs_test.go index 23c4679..db824d1 100644 --- a/samples/flushfs/flush_fs_test.go +++ b/samples/flushfs/flush_fs_test.go @@ -122,6 +122,19 @@ func (t *FlushFSTest) setFsyncError(err error) { t.fsyncErr = err } +// Like syscall.Dup2, but correctly annotates the syscall as blocking. See here +// for more info: https://github.com/golang/go/issues/10202 +func dup2(oldfd int, newfd int) (err error) { + _, _, e1 := syscall.Syscall( + syscall.SYS_DUP2, uintptr(oldfd), uintptr(newfd), 0) + + if e1 != 0 { + err = e1 + } + + return +} + //////////////////////////////////////////////////////////////////////// // Tests //////////////////////////////////////////////////////////////////////// @@ -575,7 +588,7 @@ func (t *FlushFSTest) Dup2() { // Duplicate the temporary file descriptor on top of the file from our file // system. We should see a flush. - err = syscall.Dup2(int(f2.Fd()), int(f1.Fd())) + err = dup2(int(f2.Fd()), int(f1.Fd())) ExpectEq(nil, err) ExpectThat(t.getFlushes(), ElementsAre("taco"))