Skip to content

Commit 1b5a42d

Browse files
committed
taskstats: Cleanup the use of task->exit_code
In the function bacct_add_task the code reading task->exit_code was introduced in commit f3cef7a ("[PATCH] csa: basic accounting over taskstats"), and it is not entirely clear what the taskstats interface is trying to return as only returning the exit_code of the first task in a process doesn't make a lot of sense. As best as I can figure the intent is to return task->exit_code after a task exits. The field is returned with per task fields, so the exit_code of the entire process is not wanted. Only the value of the first task is returned so this is not a useful way to get the per task ptrace stop code. The ordinary case of returning this value is returning after a task exits, which also precludes use for getting a ptrace value. It is common to for the first task of a process to also be the last task of a process so this field may have done something reasonable by accident in testing. Make ac_exitcode a reliable per task value by always returning it for every exited task. Setting ac_exitcode in a sensible mannter makes it possible to continue to provide this value going forward. Cc: Balbir Singh <[email protected]> Fixes: f3cef7a ("[PATCH] csa: basic accounting over taskstats") Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: "Eric W. Biederman" <[email protected]>
1 parent 2d18f7f commit 1b5a42d

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

kernel/tsacct.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ void bacct_add_tsk(struct user_namespace *user_ns,
3838
stats->ac_btime = clamp_t(time64_t, btime, 0, U32_MAX);
3939
stats->ac_btime64 = btime;
4040

41-
if (thread_group_leader(tsk)) {
41+
if (tsk->flags & PF_EXITING)
4242
stats->ac_exitcode = tsk->exit_code;
43-
if (tsk->flags & PF_FORKNOEXEC)
44-
stats->ac_flag |= AFORK;
45-
}
43+
if (thread_group_leader(tsk) && (tsk->flags & PF_FORKNOEXEC))
44+
stats->ac_flag |= AFORK;
4645
if (tsk->flags & PF_SUPERPRIV)
4746
stats->ac_flag |= ASU;
4847
if (tsk->flags & PF_DUMPCORE)

0 commit comments

Comments
 (0)