From 8a86ad75938a5ec3988d8f0d7deed79f29d3e1c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 9 Jun 2015 22:37:09 +0200 Subject: [PATCH] libbe: Fixed current_team() to work after a fork. * This allows to start a valid looper in the forked child, for example. --- headers/private/app/AppMisc.h | 1 + src/kits/app/AppMisc.cpp | 19 ++++++++++++++----- src/kits/app/InitTerminateLibBe.cpp | 2 ++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/headers/private/app/AppMisc.h b/headers/private/app/AppMisc.h index 2fcfd4fa2f..52295757f7 100644 --- a/headers/private/app/AppMisc.h +++ b/headers/private/app/AppMisc.h @@ -25,6 +25,7 @@ status_t get_app_ref(team_id team, entry_ref *ref, bool traverse = true); status_t get_app_ref(entry_ref *ref, bool traverse = true); team_id current_team(); +void init_team_after_fork(); thread_id main_thread_for(team_id team); bool is_app_showing_modal_window(team_id team); diff --git a/src/kits/app/AppMisc.cpp b/src/kits/app/AppMisc.cpp index d5fe963aea..3306364b6a 100644 --- a/src/kits/app/AppMisc.cpp +++ b/src/kits/app/AppMisc.cpp @@ -25,6 +25,9 @@ namespace BPrivate { +static team_id sCurrentTeam = -1; + + /*! \brief Returns the path to an application's executable. \param team The application's team ID. \param buffer A pointer to a pre-allocated character array of at least @@ -123,13 +126,19 @@ get_app_ref(entry_ref *ref, bool traverse) team_id current_team() { - static team_id team = -1; - if (team < 0) { + if (sCurrentTeam < 0) { thread_info info; if (get_thread_info(find_thread(NULL), &info) == B_OK) - team = info.team; + sCurrentTeam = info.team; } - return team; + return sCurrentTeam; +} + + +void +init_team_after_fork() +{ + sCurrentTeam = -1; } @@ -147,7 +156,7 @@ main_thread_for(team_id team) // a team info to verify the existence of the team. team_info info; status_t error = get_team_info(team, &info); - return (error == B_OK ? team : error); + return error == B_OK ? team : error; } diff --git a/src/kits/app/InitTerminateLibBe.cpp b/src/kits/app/InitTerminateLibBe.cpp index 469e270498..03f4a02e42 100644 --- a/src/kits/app/InitTerminateLibBe.cpp +++ b/src/kits/app/InitTerminateLibBe.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -35,6 +36,7 @@ initialize_forked_child() BMessage::Private::StaticReInitForkedChild(); BPrivate::gLooperList.InitAfterFork(); BPrivate::gDefaultTokens.InitAfterFork(); + BPrivate::init_team_after_fork(); DBG(OUT("initialize_forked_child() done\n")); }