From 9437559db1ae72a12b0edec44d4c538a08ceac0f Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 14 Jun 2011 13:04:31 +0000 Subject: [PATCH] * Added function team_init_exit_info_on_error() which initializes the team's exit info with some generic status. * team_create_thread_start(), common_thread_entry(): Initializes the team's exit info (if that's the main thread) before calling thread_exit(). Fixes #7686. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42183 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/team.h | 1 + src/system/kernel/team.cpp | 22 ++++++++++++++++++++++ src/system/kernel/thread.cpp | 4 ++++ 3 files changed, 27 insertions(+) diff --git a/headers/private/kernel/team.h b/headers/private/kernel/team.h index 50afdee411..ce09ea470a 100644 --- a/headers/private/kernel/team.h +++ b/headers/private/kernel/team.h @@ -36,6 +36,7 @@ char **user_team_get_arguments(void); int user_team_get_arg_count(void); struct job_control_entry* team_get_death_entry(Team *team, thread_id child, bool* _deleteEntry); +void team_init_exit_info_on_error(Team* team); bool team_is_valid(team_id id); Team *team_get_team_struct_locked(team_id id); int32 team_max_teams(void); diff --git a/src/system/kernel/team.cpp b/src/system/kernel/team.cpp index e2a1f29d39..a4b37e25d5 100644 --- a/src/system/kernel/team.cpp +++ b/src/system/kernel/team.cpp @@ -1577,6 +1577,7 @@ static status_t team_create_thread_start(void* args) { team_create_thread_start_internal(args); + team_init_exit_info_on_error(thread_get_current_thread()->team); thread_exit(); // does not return return B_OK; @@ -3243,6 +3244,27 @@ team_set_job_control_state(Team* team, job_control_state newState, } +/*! Inits the given team's exit information, if not yet initialized, to some + generic "killed" status. + The caller must not hold the team's lock. Interrupts must be enabled. + + \param team The team whose exit info shall be initialized. +*/ +void +team_init_exit_info_on_error(Team* team) +{ + TeamLocker teamLocker(team); + + if (!team->exit.initialized) { + team->exit.reason = CLD_KILLED; + team->exit.signal = SIGKILL; + team->exit.signaling_user = geteuid(); + team->exit.status = 0; + team->exit.initialized = true; + } +} + + /*! Adds a hook to the team that is called as soon as this team goes away. This call might get public in the future. */ diff --git a/src/system/kernel/thread.cpp b/src/system/kernel/thread.cpp index 382c600c4b..02a6acad67 100644 --- a/src/system/kernel/thread.cpp +++ b/src/system/kernel/thread.cpp @@ -721,6 +721,10 @@ common_thread_entry(void* _args) if (args->enterUserland) { enter_userspace(thread, (UserThreadEntryArguments*)args); // only returns or error + + // If that's the team's main thread, init the team exit info. + if (thread == thread->team->main_thread) + team_init_exit_info_on_error(thread->team); } // we're done