diff options
Diffstat (limited to 'kernel/fork.c')
-rw-r--r-- | kernel/fork.c | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/kernel/fork.c b/kernel/fork.c index 4d57d9e3a6e9..b6cce14ba047 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -165,6 +165,18 @@ void free_task(struct task_struct *tsk) | |||
165 | } | 165 | } |
166 | EXPORT_SYMBOL(free_task); | 166 | EXPORT_SYMBOL(free_task); |
167 | 167 | ||
168 | static inline void free_signal_struct(struct signal_struct *sig) | ||
169 | { | ||
170 | taskstats_tgid_free(sig); | ||
171 | kmem_cache_free(signal_cachep, sig); | ||
172 | } | ||
173 | |||
174 | static inline void put_signal_struct(struct signal_struct *sig) | ||
175 | { | ||
176 | if (atomic_dec_and_test(&sig->sigcnt)) | ||
177 | free_signal_struct(sig); | ||
178 | } | ||
179 | |||
168 | void __put_task_struct(struct task_struct *tsk) | 180 | void __put_task_struct(struct task_struct *tsk) |
169 | { | 181 | { |
170 | WARN_ON(!tsk->exit_state); | 182 | WARN_ON(!tsk->exit_state); |
@@ -173,6 +185,7 @@ void __put_task_struct(struct task_struct *tsk) | |||
173 | 185 | ||
174 | exit_creds(tsk); | 186 | exit_creds(tsk); |
175 | delayacct_tsk_free(tsk); | 187 | delayacct_tsk_free(tsk); |
188 | put_signal_struct(tsk->signal); | ||
176 | 189 | ||
177 | if (!profile_handoff_task(tsk)) | 190 | if (!profile_handoff_task(tsk)) |
178 | free_task(tsk); | 191 | free_task(tsk); |
@@ -864,8 +877,9 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) | |||
864 | if (!sig) | 877 | if (!sig) |
865 | return -ENOMEM; | 878 | return -ENOMEM; |
866 | 879 | ||
867 | atomic_set(&sig->count, 1); | 880 | sig->nr_threads = 1; |
868 | atomic_set(&sig->live, 1); | 881 | atomic_set(&sig->live, 1); |
882 | atomic_set(&sig->sigcnt, 1); | ||
869 | init_waitqueue_head(&sig->wait_chldexit); | 883 | init_waitqueue_head(&sig->wait_chldexit); |
870 | if (clone_flags & CLONE_NEWPID) | 884 | if (clone_flags & CLONE_NEWPID) |
871 | sig->flags |= SIGNAL_UNKILLABLE; | 885 | sig->flags |= SIGNAL_UNKILLABLE; |
@@ -889,13 +903,6 @@ static int copy_signal(unsigned long clone_flags, struct task_struct *tsk) | |||
889 | return 0; | 903 | return 0; |
890 | } | 904 | } |
891 | 905 | ||
892 | void __cleanup_signal(struct signal_struct *sig) | ||
893 | { | ||
894 | thread_group_cputime_free(sig); | ||
895 | tty_kref_put(sig->tty); | ||
896 | kmem_cache_free(signal_cachep, sig); | ||
897 | } | ||
898 | |||
899 | static void copy_flags(unsigned long clone_flags, struct task_struct *p) | 906 | static void copy_flags(unsigned long clone_flags, struct task_struct *p) |
900 | { | 907 | { |
901 | unsigned long new_flags = p->flags; | 908 | unsigned long new_flags = p->flags; |
@@ -1245,8 +1252,9 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1245 | } | 1252 | } |
1246 | 1253 | ||
1247 | if (clone_flags & CLONE_THREAD) { | 1254 | if (clone_flags & CLONE_THREAD) { |
1248 | atomic_inc(¤t->signal->count); | 1255 | current->signal->nr_threads++; |
1249 | atomic_inc(¤t->signal->live); | 1256 | atomic_inc(¤t->signal->live); |
1257 | atomic_inc(¤t->signal->sigcnt); | ||
1250 | p->group_leader = current->group_leader; | 1258 | p->group_leader = current->group_leader; |
1251 | list_add_tail_rcu(&p->thread_group, &p->group_leader->thread_group); | 1259 | list_add_tail_rcu(&p->thread_group, &p->group_leader->thread_group); |
1252 | } | 1260 | } |
@@ -1259,7 +1267,6 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1259 | p->nsproxy->pid_ns->child_reaper = p; | 1267 | p->nsproxy->pid_ns->child_reaper = p; |
1260 | 1268 | ||
1261 | p->signal->leader_pid = pid; | 1269 | p->signal->leader_pid = pid; |
1262 | tty_kref_put(p->signal->tty); | ||
1263 | p->signal->tty = tty_kref_get(current->signal->tty); | 1270 | p->signal->tty = tty_kref_get(current->signal->tty); |
1264 | attach_pid(p, PIDTYPE_PGID, task_pgrp(current)); | 1271 | attach_pid(p, PIDTYPE_PGID, task_pgrp(current)); |
1265 | attach_pid(p, PIDTYPE_SID, task_session(current)); | 1272 | attach_pid(p, PIDTYPE_SID, task_session(current)); |
@@ -1292,7 +1299,7 @@ bad_fork_cleanup_mm: | |||
1292 | mmput(p->mm); | 1299 | mmput(p->mm); |
1293 | bad_fork_cleanup_signal: | 1300 | bad_fork_cleanup_signal: |
1294 | if (!(clone_flags & CLONE_THREAD)) | 1301 | if (!(clone_flags & CLONE_THREAD)) |
1295 | __cleanup_signal(p->signal); | 1302 | free_signal_struct(p->signal); |
1296 | bad_fork_cleanup_sighand: | 1303 | bad_fork_cleanup_sighand: |
1297 | __cleanup_sighand(p->sighand); | 1304 | __cleanup_sighand(p->sighand); |
1298 | bad_fork_cleanup_fs: | 1305 | bad_fork_cleanup_fs: |
@@ -1327,6 +1334,16 @@ noinline struct pt_regs * __cpuinit __attribute__((weak)) idle_regs(struct pt_re | |||
1327 | return regs; | 1334 | return regs; |
1328 | } | 1335 | } |
1329 | 1336 | ||
1337 | static inline void init_idle_pids(struct pid_link *links) | ||
1338 | { | ||
1339 | enum pid_type type; | ||
1340 | |||
1341 | for (type = PIDTYPE_PID; type < PIDTYPE_MAX; ++type) { | ||
1342 | INIT_HLIST_NODE(&links[type].node); /* not really needed */ | ||
1343 | links[type].pid = &init_struct_pid; | ||
1344 | } | ||
1345 | } | ||
1346 | |||
1330 | struct task_struct * __cpuinit fork_idle(int cpu) | 1347 | struct task_struct * __cpuinit fork_idle(int cpu) |
1331 | { | 1348 | { |
1332 | struct task_struct *task; | 1349 | struct task_struct *task; |
@@ -1334,8 +1351,10 @@ struct task_struct * __cpuinit fork_idle(int cpu) | |||
1334 | 1351 | ||
1335 | task = copy_process(CLONE_VM, 0, idle_regs(®s), 0, NULL, | 1352 | task = copy_process(CLONE_VM, 0, idle_regs(®s), 0, NULL, |
1336 | &init_struct_pid, 0); | 1353 | &init_struct_pid, 0); |
1337 | if (!IS_ERR(task)) | 1354 | if (!IS_ERR(task)) { |
1355 | init_idle_pids(task->pids); | ||
1338 | init_idle(task, cpu); | 1356 | init_idle(task, cpu); |
1357 | } | ||
1339 | 1358 | ||
1340 | return task; | 1359 | return task; |
1341 | } | 1360 | } |
@@ -1507,14 +1526,6 @@ static void check_unshare_flags(unsigned long *flags_ptr) | |||
1507 | *flags_ptr |= CLONE_SIGHAND; | 1526 | *flags_ptr |= CLONE_SIGHAND; |
1508 | 1527 | ||
1509 | /* | 1528 | /* |
1510 | * If unsharing signal handlers and the task was created | ||
1511 | * using CLONE_THREAD, then must unshare the thread | ||
1512 | */ | ||
1513 | if ((*flags_ptr & CLONE_SIGHAND) && | ||
1514 | (atomic_read(¤t->signal->count) > 1)) | ||
1515 | *flags_ptr |= CLONE_THREAD; | ||
1516 | |||
1517 | /* | ||
1518 | * If unsharing namespace, must also unshare filesystem information. | 1529 | * If unsharing namespace, must also unshare filesystem information. |
1519 | */ | 1530 | */ |
1520 | if (*flags_ptr & CLONE_NEWNS) | 1531 | if (*flags_ptr & CLONE_NEWNS) |