提交 cae9a39b 编写于 作者: jia zhang's avatar jia zhang

rune/libenclave: Fix duplications of staging fds

It was intended to have fds without close-on-exec with the side
effect of dup(), but acutally all fds staged are already
close-on-exec clear. Thus dup() makes extra duplications of fds
passed to init-runelet.
Signed-off-by: jia zhang's avatarJia Zhang <zhang.jia@linux.alibaba.com>
上级 addc406d
......@@ -12,6 +12,7 @@ import (
"net"
"os"
"strconv"
"syscall"
"time"
"unsafe"
)
......@@ -47,24 +48,17 @@ func stageFd(env string, f interface{}) (err error) {
return fmt.Errorf("unsupported type of environment variable %s", env)
}
// We make full use of one important side effect of Dup(): The
// close-on-exec flag for the duplicate fd is off. Using fnctl()
// can also clear close-on-exec flag but it is too OS specific.
//
// flags, err := unix.FcntlInt(uintptr(fd), syscall.F_GETFD, 0)
// if flags & syscall.FD_CLOEXEC == syscall.FD_CLOEXEC {
// flags &^= syscall.FD_CLOEXEC
// unix.FcntlInt(uintptr(fd), syscall.F_SETFD, flags)
// }
fd, err = unix.Dup(fd)
flags, err := unix.FcntlInt(uintptr(fd), syscall.F_GETFD, 0)
if err != nil {
return err
}
defer func() {
if flags&syscall.FD_CLOEXEC == syscall.FD_CLOEXEC {
flags &^= syscall.FD_CLOEXEC
_, err := unix.FcntlInt(uintptr(fd), syscall.F_SETFD, flags)
if err != nil {
unix.Close(fd)
return err
}
}()
}
err = os.Setenv(env, strconv.Itoa(fd))
if err != nil {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册