mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 10:53:16 +01:00
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:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user