How do I clear the close-on-exec checkbox?

When os.OpenFile is called on Centos6, the O_CLOEXEC flag is set on the file descriptor. I don't think there is a way to avoid setting the flag. For example, the following call:

f, err := os.OpenFile( "lockfile", os.O_CREATE|os.O_RDWR, 0666 )

      

as follows:

[pid  2928] open("lockfile", O_RDWR|O_CREAT|O_CLOEXEC, 0666) = 3

      

syscall.CloseOnExec is provided to set the close-on-exec flag for a given file descriptor, but I cannot find an appropriate function to clear the close-on-exec flag.

How can I remove the close-on-exec flag for a file?

+3


source to share


1 answer


I found a hint at https://golang.org/src/pkg/syscall/exec_linux.go :

        _, _, err1 = RawSyscall(SYS_FCNTL, uintptr(fd[i]), F_SETFD, 0)
        if err1 != 0 {
                goto childerror
        }

      



Elsewhere, I read that I should be using Syscall and not RawSyscall , and so I rewrote it as:

    _, _, err = syscall.Syscall(syscall.SYS_FCNTL, f.Fd(), syscall.F_SETFD, 0)
    if err != syscall.Errno(0x0) {
            log.Fatal(err)
    }

      

+3


source







All Articles