diff options
Diffstat (limited to 'kernel/exit.c')
| -rw-r--r-- | kernel/exit.c | 100 |
1 files changed, 4 insertions, 96 deletions
diff --git a/kernel/exit.c b/kernel/exit.c index f65345f9e5bb..346616c0092c 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
| @@ -457,108 +457,13 @@ void daemonize(const char *name, ...) | |||
| 457 | /* Become as one with the init task */ | 457 | /* Become as one with the init task */ |
| 458 | 458 | ||
| 459 | daemonize_fs_struct(); | 459 | daemonize_fs_struct(); |
| 460 | exit_files(current); | 460 | daemonize_descriptors(); |
| 461 | current->files = init_task.files; | ||
| 462 | atomic_inc(¤t->files->count); | ||
| 463 | 461 | ||
| 464 | reparent_to_kthreadd(); | 462 | reparent_to_kthreadd(); |
| 465 | } | 463 | } |
| 466 | 464 | ||
| 467 | EXPORT_SYMBOL(daemonize); | 465 | EXPORT_SYMBOL(daemonize); |
| 468 | 466 | ||
| 469 | static void close_files(struct files_struct * files) | ||
| 470 | { | ||
| 471 | int i, j; | ||
| 472 | struct fdtable *fdt; | ||
| 473 | |||
| 474 | j = 0; | ||
| 475 | |||
| 476 | /* | ||
| 477 | * It is safe to dereference the fd table without RCU or | ||
| 478 | * ->file_lock because this is the last reference to the | ||
| 479 | * files structure. But use RCU to shut RCU-lockdep up. | ||
| 480 | */ | ||
| 481 | rcu_read_lock(); | ||
| 482 | fdt = files_fdtable(files); | ||
| 483 | rcu_read_unlock(); | ||
| 484 | for (;;) { | ||
| 485 | unsigned long set; | ||
| 486 | i = j * BITS_PER_LONG; | ||
| 487 | if (i >= fdt->max_fds) | ||
| 488 | break; | ||
| 489 | set = fdt->open_fds[j++]; | ||
| 490 | while (set) { | ||
| 491 | if (set & 1) { | ||
| 492 | struct file * file = xchg(&fdt->fd[i], NULL); | ||
| 493 | if (file) { | ||
| 494 | filp_close(file, files); | ||
| 495 | cond_resched(); | ||
| 496 | } | ||
| 497 | } | ||
| 498 | i++; | ||
| 499 | set >>= 1; | ||
| 500 | } | ||
| 501 | } | ||
| 502 | } | ||
| 503 | |||
| 504 | struct files_struct *get_files_struct(struct task_struct *task) | ||
| 505 | { | ||
| 506 | struct files_struct *files; | ||
| 507 | |||
| 508 | task_lock(task); | ||
| 509 | files = task->files; | ||
| 510 | if (files) | ||
| 511 | atomic_inc(&files->count); | ||
| 512 | task_unlock(task); | ||
| 513 | |||
| 514 | return files; | ||
| 515 | } | ||
| 516 | |||
| 517 | void put_files_struct(struct files_struct *files) | ||
| 518 | { | ||
| 519 | struct fdtable *fdt; | ||
| 520 | |||
| 521 | if (atomic_dec_and_test(&files->count)) { | ||
| 522 | close_files(files); | ||
| 523 | /* | ||
| 524 | * Free the fd and fdset arrays if we expanded them. | ||
| 525 | * If the fdtable was embedded, pass files for freeing | ||
| 526 | * at the end of the RCU grace period. Otherwise, | ||
| 527 | * you can free files immediately. | ||
| 528 | */ | ||
| 529 | rcu_read_lock(); | ||
| 530 | fdt = files_fdtable(files); | ||
| 531 | if (fdt != &files->fdtab) | ||
| 532 | kmem_cache_free(files_cachep, files); | ||
| 533 | free_fdtable(fdt); | ||
| 534 | rcu_read_unlock(); | ||
| 535 | } | ||
| 536 | } | ||
| 537 | |||
| 538 | void reset_files_struct(struct files_struct *files) | ||
| 539 | { | ||
| 540 | struct task_struct *tsk = current; | ||
| 541 | struct files_struct *old; | ||
| 542 | |||
| 543 | old = tsk->files; | ||
| 544 | task_lock(tsk); | ||
| 545 | tsk->files = files; | ||
| 546 | task_unlock(tsk); | ||
| 547 | put_files_struct(old); | ||
| 548 | } | ||
| 549 | |||
| 550 | void exit_files(struct task_struct *tsk) | ||
| 551 | { | ||
| 552 | struct files_struct * files = tsk->files; | ||
| 553 | |||
| 554 | if (files) { | ||
| 555 | task_lock(tsk); | ||
| 556 | tsk->files = NULL; | ||
| 557 | task_unlock(tsk); | ||
| 558 | put_files_struct(files); | ||
| 559 | } | ||
| 560 | } | ||
| 561 | |||
| 562 | #ifdef CONFIG_MM_OWNER | 467 | #ifdef CONFIG_MM_OWNER |
| 563 | /* | 468 | /* |
| 564 | * A task is exiting. If it owned this mm, find a new owner for the mm. | 469 | * A task is exiting. If it owned this mm, find a new owner for the mm. |
| @@ -1046,6 +951,9 @@ void do_exit(long code) | |||
| 1046 | if (tsk->splice_pipe) | 951 | if (tsk->splice_pipe) |
| 1047 | __free_pipe_info(tsk->splice_pipe); | 952 | __free_pipe_info(tsk->splice_pipe); |
| 1048 | 953 | ||
| 954 | if (tsk->task_frag.page) | ||
| 955 | put_page(tsk->task_frag.page); | ||
| 956 | |||
| 1049 | validate_creds_for_do_exit(tsk); | 957 | validate_creds_for_do_exit(tsk); |
| 1050 | 958 | ||
| 1051 | preempt_disable(); | 959 | preempt_disable(); |
