Skip to content

Commit

Permalink
Defensive programming: make sure that a process is actually running b…
Browse files Browse the repository at this point in the history
…efore we try to kill it.
  • Loading branch information
adamdunkels committed Oct 20, 2010
1 parent 37a4200 commit 06123fe
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/sys/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: process.c,v 1.11 2010/09/14 18:55:04 dak664 Exp $
* @(#)$Id: process.c,v 1.12 2010/10/20 22:24:46 adamdunkels Exp $
*/

/**
Expand Down Expand Up @@ -129,6 +129,13 @@ exit_process(struct process *p, struct process *fromprocess)

PRINTF("process: exit_process '%s'\n", PROCESS_NAME_STRING(p));

/* Make sure the process is in the process list before we try to
exit it. */
for(q = process_list; q != p && q != NULL; q = q->next);
if(q == NULL) {
return;
}

if(process_is_running(p)) {
/* Process was running */
p->state = PROCESS_STATE_NONE;
Expand All @@ -150,7 +157,7 @@ exit_process(struct process *p, struct process *fromprocess)
p->thread(&p->pt, PROCESS_EVENT_EXIT, NULL);
}
}

if(p == process_list) {
process_list = process_list->next;
} else {
Expand Down

0 comments on commit 06123fe

Please sign in to comment.