main, syscallcompat: use Dup3 instead of Dup2

Dup2 is not implemented on linux/arm64.

Fixes https://github.com/rfjakob/gocryptfs/issues/121 .

Also adds cross-compilation to CI.
This commit is contained in:
Jakob Unterwurzacher 2017-06-18 15:40:38 +02:00
parent afc3a8252b
commit a4563e21ec
5 changed files with 32 additions and 3 deletions

View File

@ -21,6 +21,7 @@ script:
- ./build.bash
- ./gocryptfs -speed
- ./test.bash
- ./crossbuild.bash
# fuse on travis
sudo: required

12
crossbuild.bash Executable file
View File

@ -0,0 +1,12 @@
#!/bin/bash -eux
cd "$(dirname "$0")"
B="go build -tags without_openssl"
GOOS=linux GOARCH=arm $B
GOOS=linux GOARCH=arm64 $B
GOOS=darwin GOARCH=amd64 $B
# The cross-built binary is not useful on the compile host.
rm gocryptfs

View File

@ -1,6 +1,7 @@
package syscallcompat
import (
"log"
"os"
"path/filepath"
"sync"
@ -122,3 +123,11 @@ func dirfdAbs(dirfd int, path string) (string, error) {
}
return filepath.Join(wd, path), nil
}
// Dup3 is not available on Darwin, so we use Dup2 instead.
func Dup3(oldfd int, newfd int, flags int) (err error) {
if flags != 0 {
log.Panic("darwin does not support dup3 flags")
}
return syscall.Dup2(oldfd, newfd)
}

View File

@ -62,3 +62,9 @@ func Unlinkat(dirfd int, path string) error {
func Mknodat(dirfd int, path string, mode uint32, dev int) (err error) {
return syscall.Mknodat(dirfd, path, mode, dev)
}
// Dup3 wraps the Dup3 syscall. We want to use Dup3 rather than Dup2 because Dup2
// is not implemented on arm64.
func Dup3(oldfd int, newfd int, flags int) (err error) {
return syscall.Dup3(oldfd, newfd, flags)
}

View File

@ -25,6 +25,7 @@ import (
"github.com/rfjakob/gocryptfs/internal/fusefrontend"
"github.com/rfjakob/gocryptfs/internal/fusefrontend_reverse"
"github.com/rfjakob/gocryptfs/internal/readpassword"
"github.com/rfjakob/gocryptfs/internal/syscallcompat"
"github.com/rfjakob/gocryptfs/internal/tlog"
)
@ -162,11 +163,11 @@ func redirectStdFds() {
tlog.Warn.Printf("redirectStdFds: could not start logger: %v\n", err)
}
pr.Close()
err = syscall.Dup2(int(pw.Fd()), 1)
err = syscallcompat.Dup3(int(pw.Fd()), 1, 0)
if err != nil {
tlog.Warn.Printf("redirectStdFds: stdout dup error: %v\n", err)
}
syscall.Dup2(int(pw.Fd()), 2)
syscallcompat.Dup3(int(pw.Fd()), 2, 0)
if err != nil {
tlog.Warn.Printf("redirectStdFds: stderr dup error: %v\n", err)
}
@ -178,7 +179,7 @@ func redirectStdFds() {
tlog.Warn.Printf("redirectStdFds: could not open /dev/null: %v\n", err)
return
}
err = syscall.Dup2(int(nullFd.Fd()), 0)
err = syscallcompat.Dup3(int(nullFd.Fd()), 0, 0)
if err != nil {
tlog.Warn.Printf("redirectStdFds: stdin dup error: %v\n", err)
}