terminate(): clean-up and formatting

This commit is contained in:
Balazs Gerofi
2017-08-08 11:12:55 +09:00
parent 9194742de8
commit 6d4d6440aa

View File

@ -784,8 +784,7 @@ SYSCALL_DECLARE(waitid)
return 0;
}
void
terminate(int rc, int sig)
void terminate(int rc, int sig)
{
struct resource_set *resource_set = cpu_local_var(resource_set);
struct thread *mythread = cpu_local_var(current);
@ -808,6 +807,7 @@ terminate(int rc, int sig)
// sync perf info
if (proc->monitoring_event)
sync_child_event(proc->monitoring_event);
// clean up threads
mcs_rwlock_reader_lock(&proc->threads_lock, &lock); // conflict clone
mcs_rwlock_writer_lock_noirq(&proc->update_lock, &updatelock);
@ -822,6 +822,7 @@ terminate(int rc, int sig)
// no return
return;
}
exit_status = mythread->exit_status = ((rc & 0x00ff) << 8) | (sig & 0xff);
proc->status = PS_EXITED;
mcs_rwlock_writer_unlock_noirq(&proc->update_lock, &updatelock);
@ -836,6 +837,7 @@ terminate(int rc, int sig)
list_for_each_entry(thread, &proc->threads_list, siblings_list) {
n++;
}
if (n) {
ids = kmalloc(sizeof(int) * n, IHK_MC_AP_NOWAIT);
i = 0;
@ -849,6 +851,7 @@ terminate(int rc, int sig)
}
}
mcs_rwlock_reader_unlock(&proc->threads_lock, &lock);
if (ids) {
for (i = 0; i < n; i++) {
do_kill(mythread, proc->pid, ids[i], SIGKILL, NULL, 0);
@ -885,9 +888,11 @@ terminate(int rc, int sig)
if (child->ptrace & PT_TRACED)
n++;
}
if (n) {
ids = kmalloc(sizeof(int) * n, IHK_MC_AP_NOWAIT);
i = 0;
if (ids) {
list_for_each_entry(child, &proc->children_list, siblings_list) {
if (child->ptrace & PT_TRACED) {
@ -898,11 +903,13 @@ terminate(int rc, int sig)
}
}
mcs_rwlock_reader_unlock(&proc->children_lock, &lock);
if (ids) {
for (i = 0; i < n; i++) {
ptrace_detach(ids[i], 0);
}
kfree(ids);
ids = NULL;
}
if (!list_empty(&proc->children_list)) {
@ -916,6 +923,7 @@ terminate(int rc, int sig)
int free_child = 0;
mcs_rwlock_writer_lock_noirq(&child->update_lock,
&updatelock);
if (child->ppid_parent == proc &&
child->status == PS_ZOMBIE) {
list_del(&child->hash_list);
@ -944,8 +952,10 @@ terminate(int rc, int sig)
mcs_rwlock_writer_unlock_noirq(&proc->children_lock,
&childlock);
}
mcs_rwlock_writer_unlock_noirq(&child->update_lock,
&updatelock);
if (free_child)
kfree(child);
}