diff mbox series

[v2,07/13] btrfs-progs: receive: open files with O_CLOEXEC

Message ID 41f3e3f92372f48037c7cee18af808d4cc5352c5.1605723745.git.osandov@osandov.com (mailing list archive)
State New, archived
Headers show
Series btrfs: implement send/receive of compressed extents without decompressing | expand

Commit Message

Omar Sandoval Nov. 18, 2020, 7:18 p.m. UTC
From: Omar Sandoval <osandov@fb.com>

Opening with O_ALLOW_ENCODED also requires O_CLOEXEC. Let's add
O_CLOEXEC now in preparation. btrfs receive doesn't exec anything, so
this should be a no-op.

Signed-off-by: Omar Sandoval <osandov@fb.com>
---
 cmds/receive.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/cmds/receive.c b/cmds/receive.c
index 2aaba3ff..2c56cea6 100644
--- a/cmds/receive.c
+++ b/cmds/receive.c
@@ -654,7 +654,11 @@  static int open_inode_for_write(struct btrfs_receive *rctx, const char *path)
 		rctx->write_fd = -1;
 	}
 
-	rctx->write_fd = open(path, O_RDWR);
+	/*
+	 * When opening with O_ALLOW_ENCODED, O_CLOEXEC must also be specified.
+	 * We might as well always use it even though we don't exec anything.
+	 */
+	rctx->write_fd = open(path, O_RDWR | O_CLOEXEC);
 	if (rctx->write_fd < 0) {
 		ret = -errno;
 		error("cannot open %s: %m", path);