Skip to content

Commit

Permalink
exit/kthread: Move the exit code for kernel threads into struct kthread
Browse files Browse the repository at this point in the history
The exit code of kernel threads has different semantics than the
exit_code of userspace tasks.  To avoid confusion and allow
the userspace implementation to change as needed move
the kernel thread exit code into struct kthread.

Signed-off-by: "Eric W. Biederman" <[email protected]>
  • Loading branch information
ebiederm committed Dec 13, 2021
1 parent 40966e3 commit 6b12487
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions kernel/kthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct kthread_create_info
struct kthread {
unsigned long flags;
unsigned int cpu;
int result;
int (*threadfn)(void *);
void *data;
mm_segment_t oldfs;
Expand Down Expand Up @@ -287,7 +288,9 @@ EXPORT_SYMBOL_GPL(kthread_parkme);
*/
void __noreturn kthread_exit(long result)
{
do_exit(result);
struct kthread *kthread = to_kthread(current);
kthread->result = result;
do_exit(0);
}

/**
Expand Down Expand Up @@ -679,7 +682,7 @@ int kthread_stop(struct task_struct *k)
kthread_unpark(k);
wake_up_process(k);
wait_for_completion(&kthread->exited);
ret = k->exit_code;
ret = kthread->result;
put_task_struct(k);

trace_sched_kthread_stop_ret(ret);
Expand Down

0 comments on commit 6b12487

Please sign in to comment.