Skip to content

Commit

Permalink
Use O_CLOEXEC in util packages
Browse files Browse the repository at this point in the history
This prevents fd's from leaking to subprocesses.
  • Loading branch information
cpuguy83 committed Jul 9, 2019
1 parent 0051db8 commit 7077bbd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/util/flock/flock_unix.go
Expand Up @@ -23,7 +23,7 @@ import "golang.org/x/sys/unix"
// Acquire acquires a lock on a file for the duration of the process. This method
// is reentrant.
func Acquire(path string) error {
fd, err := unix.Open(path, unix.O_CREAT|unix.O_RDWR, 0600)
fd, err := unix.Open(path, unix.O_CREAT|unix.O_RDWR|unix.O_CLOEXEC, 0600)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/mount/mount_linux.go
Expand Up @@ -497,7 +497,7 @@ func ExclusiveOpenFailsOnDevice(pathname string) (bool, error) {
klog.Errorf("Path %q is not referring to a device.", pathname)
return false, nil
}
fd, errno := unix.Open(pathname, unix.O_RDONLY|unix.O_EXCL, 0)
fd, errno := unix.Open(pathname, unix.O_RDONLY|unix.O_EXCL|unix.O_CLOEXEC, 0)
// If the device is in use, open will return an invalid fd.
// When this happens, it is expected that Close will fail and throw an error.
defer unix.Close(fd)
Expand Down

0 comments on commit 7077bbd

Please sign in to comment.