* load_image() now has exec() semantics wrt file descriptors; before each team

would always inherit them all, causing quite a number of open files.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34247 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2009-11-25 16:16:22 +00:00
parent 3a6fc6d0aa
commit 1ba04177d3
3 changed files with 11 additions and 6 deletions

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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");