diff --git a/headers/private/kernel/vfs.h b/headers/private/kernel/vfs.h index fe4b2f103b..76483a0244 100644 --- a/headers/private/kernel/vfs.h +++ b/headers/private/kernel/vfs.h @@ -73,7 +73,8 @@ status_t vfs_init(struct kernel_args *args); status_t vfs_bootstrap_file_systems(void); void vfs_mount_boot_file_system(struct kernel_args *args); void vfs_exec_io_context(io_context *context); -io_context *vfs_new_io_context(io_context *parentContext); +io_context* vfs_new_io_context(io_context* parentContext, + bool purgeCloseOnExec); void vfs_get_io_context(io_context *context); void vfs_put_io_context(io_context *context); diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp index c13187dcbb..992a427891 100644 --- a/src/system/kernel/fs/vfs.cpp +++ b/src/system/kernel/fs/vfs.cpp @@ -4653,7 +4653,7 @@ vfs_exec_io_context(io_context* context) of the parent io_control if it is given. */ io_context* -vfs_new_io_context(io_context* parentContext) +vfs_new_io_context(io_context* parentContext, bool purgeCloseOnExec) { size_t tableSize; struct io_context* context; @@ -4710,12 +4710,16 @@ vfs_new_io_context(io_context* parentContext) struct file_descriptor* descriptor = parentContext->fds[i]; if (descriptor != NULL) { + bool closeOnExec = fd_close_on_exec(parentContext, i); + if (closeOnExec && purgeCloseOnExec) + continue; + context->fds[i] = descriptor; context->num_used_fds++; atomic_add(&descriptor->ref_count, 1); atomic_add(&descriptor->open_count, 1); - if (fd_close_on_exec(parentContext, i)) + if (closeOnExec) fd_set_close_on_exec(context, i, true); } } diff --git a/src/system/kernel/team.cpp b/src/system/kernel/team.cpp index c17b058b61..67cfd8c340 100644 --- a/src/system/kernel/team.cpp +++ b/src/system/kernel/team.cpp @@ -1203,7 +1203,7 @@ load_image_internal(char**& _flatArgs, size_t flatArgsSize, int32 argCount, // args are owned by the team_arg structure now // create a new io_context for this team - team->io_context = vfs_new_io_context(parentIOContext); + team->io_context = vfs_new_io_context(parentIOContext, true); if (!team->io_context) { status = B_NO_MEMORY; goto err2; @@ -1536,7 +1536,7 @@ fork_team(void) } // create a new io_context for this team - team->io_context = vfs_new_io_context(parentTeam->io_context); + team->io_context = vfs_new_io_context(parentTeam->io_context, false); if (!team->io_context) { status = B_NO_MEMORY; goto err2; @@ -2064,7 +2064,7 @@ team_init(kernel_args *args) insert_team_into_group(group, sKernelTeam); - sKernelTeam->io_context = vfs_new_io_context(NULL); + sKernelTeam->io_context = vfs_new_io_context(NULL, false); if (sKernelTeam->io_context == NULL) panic("could not create io_context for kernel team!\n");