Author: axeld Date: 2009-11-25 17:16:22 +0100 (Wed, 25 Nov 2009) New Revision: 34247 Changeset: http://dev.haiku-os.org/changeset/34247/haiku Modified: haiku/trunk/headers/private/kernel/vfs.h haiku/trunk/src/system/kernel/fs/vfs.cpp haiku/trunk/src/system/kernel/team.cpp Log: * load_image() now has exec() semantics wrt file descriptors; before each team would always inherit them all, causing quite a number of open files. Modified: haiku/trunk/headers/private/kernel/vfs.h =================================================================== --- haiku/trunk/headers/private/kernel/vfs.h 2009-11-25 16:14:52 UTC (rev 34246) +++ haiku/trunk/headers/private/kernel/vfs.h 2009-11-25 16:16:22 UTC (rev 34247) @@ -73,7 +73,8 @@ 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); Modified: haiku/trunk/src/system/kernel/fs/vfs.cpp =================================================================== --- haiku/trunk/src/system/kernel/fs/vfs.cpp 2009-11-25 16:14:52 UTC (rev 34246) +++ haiku/trunk/src/system/kernel/fs/vfs.cpp 2009-11-25 16:16:22 UTC (rev 34247) @@ -4653,7 +4653,7 @@ 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 @@ 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); } } Modified: haiku/trunk/src/system/kernel/team.cpp =================================================================== --- haiku/trunk/src/system/kernel/team.cpp 2009-11-25 16:14:52 UTC (rev 34246) +++ haiku/trunk/src/system/kernel/team.cpp 2009-11-25 16:16:22 UTC (rev 34247) @@ -1203,7 +1203,7 @@ // 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 @@ } // 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 @@ 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");