Forgot to increase file open count when forking a task. Now fixed.

Also now a file can only be deleted if both open count and map count is zero.
This commit is contained in:
Bahadir Balban
2008-11-07 17:20:11 +02:00
parent 122214f9b5
commit 93ca3f88a8
2 changed files with 10 additions and 2 deletions

View File

@@ -410,7 +410,10 @@ int do_close(struct tcb *task, int fd)
/* Reduce file's opener count */
if (!(--task->files->fd[fd].vmfile->openers))
vm_file_delete(task->files->fd[fd].vmfile);
/* No openers left, check any mappers */
if (!task->files->fd[fd].vmfile->vm_obj.nlinks)
/* No links or openers, delete the file */
vm_file_delete(task->files->fd[fd].vmfile);
task->files->fd[fd].vnum = 0;
task->files->fd[fd].cursor = 0;

View File

@@ -219,8 +219,13 @@ int copy_tcb(struct tcb *to, struct tcb *from, unsigned int flags)
to->files = from->files;
to->files->tcb_refs++;
} else {
/* Copy all file descriptors */
/* Bulk copy all file descriptors */
memcpy(to->files, from->files, sizeof(*to->files));
/* Increase refcount for all open files */
for (int i = 0; i < TASK_FILES_MAX; i++)
if (to->files->fd[i].vmfile)
to->files->fd[i].vmfile->openers++;
}
return 0;