diff options
Diffstat (limited to 'kernel/fork.c')
-rw-r--r-- | kernel/fork.c | 55 |
1 files changed, 35 insertions, 20 deletions
diff --git a/kernel/fork.c b/kernel/fork.c index 4d57d9e3a6e9..bf9fef6d1bfe 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; |
@@ -1079,6 +1086,10 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1079 | } | 1086 | } |
1080 | mpol_fix_fork_child_flag(p); | 1087 | mpol_fix_fork_child_flag(p); |
1081 | #endif | 1088 | #endif |
1089 | #ifdef CONFIG_CPUSETS | ||
1090 | p->cpuset_mem_spread_rotor = node_random(p->mems_allowed); | ||
1091 | p->cpuset_slab_spread_rotor = node_random(p->mems_allowed); | ||
1092 | #endif | ||
1082 | #ifdef CONFIG_TRACE_IRQFLAGS | 1093 | #ifdef CONFIG_TRACE_IRQFLAGS |
1083 | p->irq_events = 0; | 1094 | p->irq_events = 0; |
1084 | #ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW | 1095 | #ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW |
@@ -1245,8 +1256,9 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1245 | } | 1256 | } |
1246 | 1257 | ||
1247 | if (clone_flags & CLONE_THREAD) { | 1258 | if (clone_flags & CLONE_THREAD) { |
1248 | atomic_inc(¤t->signal->count); | 1259 | current->signal->nr_threads++; |
1249 | atomic_inc(¤t->signal->live); | 1260 | atomic_inc(¤t->signal->live); |
1261 | atomic_inc(¤t->signal->sigcnt); | ||
1250 | p->group_leader = current->group_leader; | 1262 | p->group_leader = current->group_leader; |
1251 | list_add_tail_rcu(&p->thread_group, &p->group_leader->thread_group); | 1263 | list_add_tail_rcu(&p->thread_group, &p->group_leader->thread_group); |
1252 | } | 1264 | } |
@@ -1259,7 +1271,6 @@ static struct task_struct *copy_process(unsigned long clone_flags, | |||
1259 | p->nsproxy->pid_ns->child_reaper = p; | 1271 | p->nsproxy->pid_ns->child_reaper = p; |
1260 | 1272 | ||
1261 | p->signal->leader_pid = pid; | 1273 | p->signal->leader_pid = pid; |
1262 | tty_kref_put(p->signal->tty); | ||
1263 | p->signal->tty = tty_kref_get(current->signal->tty); | 1274 | p->signal->tty = tty_kref_get(current->signal->tty); |
1264 | attach_pid(p, PIDTYPE_PGID, task_pgrp(current)); | 1275 | attach_pid(p, PIDTYPE_PGID, task_pgrp(current)); |
1265 | attach_pid(p, PIDTYPE_SID, task_session(current)); | 1276 | attach_pid(p, PIDTYPE_SID, task_session(current)); |
@@ -1292,7 +1303,7 @@ bad_fork_cleanup_mm: | |||
1292 | mmput(p->mm); | 1303 | mmput(p->mm); |
1293 | bad_fork_cleanup_signal: | 1304 | bad_fork_cleanup_signal: |
1294 | if (!(clone_flags & CLONE_THREAD)) | 1305 | if (!(clone_flags & CLONE_THREAD)) |
1295 | __cleanup_signal(p->signal); | 1306 | free_signal_struct(p->signal); |
1296 | bad_fork_cleanup_sighand: | 1307 | bad_fork_cleanup_sighand: |
1297 | __cleanup_sighand(p->sighand); | 1308 | __cleanup_sighand(p->sighand); |
1298 | bad_fork_cleanup_fs: | 1309 | bad_fork_cleanup_fs: |
@@ -1327,6 +1338,16 @@ noinline struct pt_regs * __cpuinit __attribute__((weak)) idle_regs(struct pt_re | |||
1327 | return regs; | 1338 | return regs; |
1328 | } | 1339 | } |
1329 | 1340 | ||
1341 | static inline void init_idle_pids(struct pid_link *links) | ||
1342 | { | ||
1343 | enum pid_type type; | ||
1344 | |||
1345 | for (type = PIDTYPE_PID; type < PIDTYPE_MAX; ++type) { | ||
1346 | INIT_HLIST_NODE(&links[type].node); /* not really needed */ | ||
1347 | links[type].pid = &init_struct_pid; | ||
1348 | } | ||
1349 | } | ||
1350 | |||
1330 | struct task_struct * __cpuinit fork_idle(int cpu) | 1351 | struct task_struct * __cpuinit fork_idle(int cpu) |
1331 | { | 1352 | { |
1332 | struct task_struct *task; | 1353 | struct task_struct *task; |
@@ -1334,8 +1355,10 @@ struct task_struct * __cpuinit fork_idle(int cpu) | |||
1334 | 1355 | ||
1335 | task = copy_process(CLONE_VM, 0, idle_regs(®s), 0, NULL, | 1356 | task = copy_process(CLONE_VM, 0, idle_regs(®s), 0, NULL, |
1336 | &init_struct_pid, 0); | 1357 | &init_struct_pid, 0); |
1337 | if (!IS_ERR(task)) | 1358 | if (!IS_ERR(task)) { |
1359 | init_idle_pids(task->pids); | ||
1338 | init_idle(task, cpu); | 1360 | init_idle(task, cpu); |
1361 | } | ||
1339 | 1362 | ||
1340 | return task; | 1363 | return task; |
1341 | } | 1364 | } |
@@ -1507,14 +1530,6 @@ static void check_unshare_flags(unsigned long *flags_ptr) | |||
1507 | *flags_ptr |= CLONE_SIGHAND; | 1530 | *flags_ptr |= CLONE_SIGHAND; |
1508 | 1531 | ||
1509 | /* | 1532 | /* |
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. | 1533 | * If unsharing namespace, must also unshare filesystem information. |
1519 | */ | 1534 | */ |
1520 | if (*flags_ptr & CLONE_NEWNS) | 1535 | if (*flags_ptr & CLONE_NEWNS) |