Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jleong/change exit behavior #114

Merged
merged 12 commits into from
Feb 22, 2017
Prev Previous commit
Next Next commit
Fix possible minor bugs
  • Loading branch information
omegaphoenix committed Feb 20, 2017
commit 488003b1238e148f00d437084d2c0037ebbf07ef
2 changes: 1 addition & 1 deletion src/threads/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ int add_open_file(struct thread *cur, struct file *file, int fd) {
new_file->file = file;
new_file->fd = fd;

if (is_valid_fd(fd)) {
if (is_valid_fd(fd) && !is_existing_fd(cur, fd)) {
list_push_back(&cur->open_files, &new_file->file_elem);
return fd;
}
Expand Down
4 changes: 4 additions & 0 deletions src/userprog/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ void sys_exit(int status) {
printf("%s: exit(%d)\n", cur->name, status);
cur->exit_status = status;

if (lock_held_by_current_thread(&filesys_lock)) {
release_file_lock();
}

/* Free all file buffers. */
struct list_elem *e;
while (!list_empty(&cur->open_files)) {
Expand Down