mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-02 15:18:19 +00:00
new helper: daemonize_descriptors()
descriptor-related parts of daemonize, done right. As the result we simplify the locking rules for ->files - we hold task_lock in *all* cases when we modify ->files. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
2be7fd55d4
commit
864bdb3b6c
3 changed files with 8 additions and 3 deletions
|
@ -519,6 +519,12 @@ struct files_struct init_files = {
|
||||||
.file_lock = __SPIN_LOCK_UNLOCKED(init_task.file_lock),
|
.file_lock = __SPIN_LOCK_UNLOCKED(init_task.file_lock),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void daemonize_descriptors(void)
|
||||||
|
{
|
||||||
|
atomic_inc(&init_files.count);
|
||||||
|
reset_files_struct(&init_files);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* allocate a file descriptor, mark it busy.
|
* allocate a file descriptor, mark it busy.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -95,6 +95,7 @@ struct task_struct;
|
||||||
struct files_struct *get_files_struct(struct task_struct *);
|
struct files_struct *get_files_struct(struct task_struct *);
|
||||||
void put_files_struct(struct files_struct *fs);
|
void put_files_struct(struct files_struct *fs);
|
||||||
void reset_files_struct(struct files_struct *);
|
void reset_files_struct(struct files_struct *);
|
||||||
|
void daemonize_descriptors(void);
|
||||||
int unshare_files(struct files_struct **);
|
int unshare_files(struct files_struct **);
|
||||||
struct files_struct *dup_fd(struct files_struct *, int *);
|
struct files_struct *dup_fd(struct files_struct *, int *);
|
||||||
void do_close_on_exec(struct files_struct *);
|
void do_close_on_exec(struct files_struct *);
|
||||||
|
|
|
@ -457,9 +457,7 @@ void daemonize(const char *name, ...)
|
||||||
/* Become as one with the init task */
|
/* Become as one with the init task */
|
||||||
|
|
||||||
daemonize_fs_struct();
|
daemonize_fs_struct();
|
||||||
exit_files(current);
|
daemonize_descriptors();
|
||||||
current->files = init_task.files;
|
|
||||||
atomic_inc(¤t->files->count);
|
|
||||||
|
|
||||||
reparent_to_kthreadd();
|
reparent_to_kthreadd();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue