Another kernel bug less:

* send_signal_etc() (among others) used team::main_thread in an unsafe way; it is
  possible for a team to be part of the team list and a group without having
  a main thread very early in its creation process.
* Replaced most occurences of team->main_thread->id with team->id since the team
  always inherits the ID of its main thread in Haiku for quite some time now.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19781 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-01-12 22:54:21 +00:00
parent 43792b9eed
commit b129e4cee1
3 changed files with 35 additions and 35 deletions
+3 -3
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2006, Axel Dörfler, [email protected]. * Copyright 2002-2007, Axel Dörfler, [email protected].
* Copyright 2002, Angelo Mottola, [email protected]. * Copyright 2002, Angelo Mottola, [email protected].
* *
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
@@ -316,7 +316,7 @@ send_signal_etc(pid_t id, uint signal, uint32 flags)
// TODO: handle -1 correctly // TODO: handle -1 correctly
if (id == 0 || id == -1) { if (id == 0 || id == -1) {
// send a signal to the current team // send a signal to the current team
id = thread_get_current_thread()->team->main_thread->id; id = thread_get_current_thread()->team->id;
} else } else
id = -id; id = -id;
@@ -330,7 +330,7 @@ send_signal_etc(pid_t id, uint signal, uint32 flags)
for (team = group->teams; team != NULL; team = next) { for (team = group->teams; team != NULL; team = next) {
next = team->group_next; next = team->group_next;
id = team->main_thread->id; id = team->id;
GRAB_THREAD_LOCK(); GRAB_THREAD_LOCK();
+28 -28
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2006, Axel Dörfler, [email protected]. * Copyright 2002-2007, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
@@ -404,7 +404,7 @@ reparent_children(struct team *team)
static bool static bool
is_process_group_leader(struct team *team) is_process_group_leader(struct team *team)
{ {
return team->group_id == team->main_thread->id; return team->group_id == team->id;
} }
@@ -1961,7 +1961,7 @@ wait_for_team(team_id id, status_t *_returnCode)
GRAB_TEAM_LOCK(); GRAB_TEAM_LOCK();
team = team_get_team_struct_locked(id); team = team_get_team_struct_locked(id);
if (team && team->main_thread) if (team != NULL && team->main_thread != NULL)
thread = team->main_thread->id; thread = team->main_thread->id;
else else
thread = B_BAD_THREAD_ID; thread = B_BAD_THREAD_ID;
@@ -1979,33 +1979,33 @@ wait_for_team(team_id id, status_t *_returnCode)
status_t status_t
kill_team(team_id id) kill_team(team_id id)
{ {
cpu_status state; status_t status = B_OK;
thread_id threadID = -1;
struct team *team; struct team *team;
// struct thread *t; cpu_status state;
thread_id tid = -1;
int retval = 0;
state = disable_interrupts(); state = disable_interrupts();
GRAB_TEAM_LOCK(); GRAB_TEAM_LOCK();
team = team_get_team_struct_locked(id); team = team_get_team_struct_locked(id);
if (team != NULL) { if (team != NULL) {
if (team == sKernelTeam) if (team != sKernelTeam) {
retval = B_NOT_ALLOWED; threadID = team->id;
else // the team ID is the same as the ID of its main thread
tid = team->main_thread->id; } else
status = B_NOT_ALLOWED;
} else } else
retval = B_BAD_THREAD_ID; status = B_BAD_THREAD_ID;
RELEASE_TEAM_LOCK(); RELEASE_TEAM_LOCK();
restore_interrupts(state); restore_interrupts(state);
if (retval < 0) if (status < B_OK)
return retval; return status;
// just kill the main thread in the team. The cleanup code there will // just kill the main thread in the team. The cleanup code there will
// take care of the team // take care of the team
return kill_thread(tid); return kill_thread(threadID);
} }
@@ -2013,7 +2013,7 @@ status_t
_get_team_info(team_id id, team_info *info, size_t size) _get_team_info(team_id id, team_info *info, size_t size)
{ {
cpu_status state; cpu_status state;
status_t rc = B_OK; status_t status = B_OK;
struct team *team; struct team *team;
state = disable_interrupts(); state = disable_interrupts();
@@ -2025,17 +2025,17 @@ _get_team_info(team_id id, team_info *info, size_t size)
team = team_get_team_struct_locked(id); team = team_get_team_struct_locked(id);
if (team == NULL) { if (team == NULL) {
rc = B_BAD_TEAM_ID; status = B_BAD_TEAM_ID;
goto err; goto err;
} }
rc = fill_team_info(team, info, size); status = fill_team_info(team, info, size);
err: err:
RELEASE_TEAM_LOCK(); RELEASE_TEAM_LOCK();
restore_interrupts(state); restore_interrupts(state);
return rc; return status;
} }
@@ -2152,7 +2152,7 @@ out:
pid_t pid_t
getpid(void) getpid(void)
{ {
return thread_get_current_thread()->team->main_thread->id; return thread_get_current_thread()->team->id;
} }
@@ -2166,7 +2166,7 @@ getppid(void)
state = disable_interrupts(); state = disable_interrupts();
GRAB_TEAM_LOCK(); GRAB_TEAM_LOCK();
parent = team->parent->main_thread->id; parent = team->parent->id;
RELEASE_TEAM_LOCK(); RELEASE_TEAM_LOCK();
restore_interrupts(state); restore_interrupts(state);
@@ -2183,7 +2183,7 @@ getpgid(pid_t process)
cpu_status state; cpu_status state;
if (process == 0) if (process == 0)
process = thread_get_current_thread()->team->main_thread->id; process = thread_get_current_thread()->team->id;
state = disable_interrupts(); state = disable_interrupts();
GRAB_THREAD_LOCK(); GRAB_THREAD_LOCK();
@@ -2207,7 +2207,7 @@ getsid(pid_t process)
cpu_status state; cpu_status state;
if (process == 0) if (process == 0)
process = thread_get_current_thread()->team->main_thread->id; process = thread_get_current_thread()->team->id;
state = disable_interrupts(); state = disable_interrupts();
GRAB_THREAD_LOCK(); GRAB_THREAD_LOCK();
@@ -2281,7 +2281,7 @@ _user_process_info(pid_t process, int32 which)
{ {
// we only allow to return the parent of the current process // we only allow to return the parent of the current process
if (which == PARENT_ID if (which == PARENT_ID
&& process != 0 && process != thread_get_current_thread()->team->main_thread->id) && process != 0 && process != thread_get_current_thread()->team->id)
return B_BAD_VALUE; return B_BAD_VALUE;
switch (which) { switch (which) {
@@ -2312,9 +2312,9 @@ _user_setpgid(pid_t processID, pid_t groupID)
return B_BAD_VALUE; return B_BAD_VALUE;
if (processID == 0) if (processID == 0)
processID = currentTeam->main_thread->id; processID = currentTeam->id;
if (processID == currentTeam->main_thread->id) { if (processID == currentTeam->id) {
// we set our own group // we set our own group
teamID = currentTeam->id; teamID = currentTeam->id;
@@ -2420,7 +2420,7 @@ _user_setsid(void)
if (is_process_group_leader(team)) if (is_process_group_leader(team))
return B_NOT_ALLOWED; return B_NOT_ALLOWED;
group = create_process_group(team->main_thread->id); group = create_process_group(team->id);
if (group == NULL) if (group == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
+4 -4
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2006, Axel Dörfler, [email protected]. * Copyright 2002-2007, Axel Dörfler, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved. * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
@@ -898,7 +898,7 @@ thread_exit(void)
struct process_group *freeGroup = NULL; struct process_group *freeGroup = NULL;
struct team *team = thread->team; struct team *team = thread->team;
struct death_entry *death = NULL; struct death_entry *death = NULL;
thread_id mainParentThread = -1; thread_id parentID = -1;
bool deleteTeam = false; bool deleteTeam = false;
sem_id cachedDeathSem = -1; sem_id cachedDeathSem = -1;
status_t status; status_t status;
@@ -991,7 +991,7 @@ thread_exit(void)
struct team *parent = team->parent; struct team *parent = team->parent;
// remember who our parent was so we can send a signal // remember who our parent was so we can send a signal
mainParentThread = parent->main_thread->id; parentID = parent->id;
if (death != NULL) { if (death != NULL) {
// insert death entry into the parent's list // insert death entry into the parent's list
@@ -1033,7 +1033,7 @@ thread_exit(void)
if (death != NULL) if (death != NULL)
free(death); free(death);
send_signal_etc(mainParentThread, SIGCHLD, B_DO_NOT_RESCHEDULE); send_signal_etc(parentID, SIGCHLD, B_DO_NOT_RESCHEDULE);
cachedDeathSem = -1; cachedDeathSem = -1;
} }