aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2016-02-15 22:36:36 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2016-02-15 22:38:15 +0100
commit8b2d99196b24fc9ae54b0a9ac86ceaaf1b6b4164 (patch)
tree325321c19c825305d9515ef785eac00338c22b37
parenta46591da9fa2313f3dc5e3f4a8774b2780d851ac (diff)
afm-run: fix bug in handling pids
Change-Id: If5d750a56ef7229769c46cc33d40faeb8ea76ece Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--src/afm-run.c45
1 files changed, 24 insertions, 21 deletions
diff --git a/src/afm-run.c b/src/afm-run.c
index 360f29d..915230d 100644
--- a/src/afm-run.c
+++ b/src/afm-run.c
@@ -64,9 +64,23 @@ static int runnerid = 0;
static const char fwk_user_app_dir[] = FWK_USER_APP_DIR;
static char *homeappdir;
+/****************** manages pids **********************/
+
+/* get a runner by its pid */
+static struct apprun *runner_of_pid(pid_t pid)
+{
+ int i;
+ struct apprun *result;
+
+ for (i = 0 ; i < ROOT_RUNNERS_COUNT ; i++)
+ for (result = runners_by_pgid[i] ; result != NULL ; result = result->next_by_pgid)
+ if (result->pids[0] == pid || result->pids[1] == pid)
+ return result;
+ return NULL;
+}
+
/****************** manages pgids **********************/
-#if 0
/* get a runner by its pgid */
static struct apprun *runner_of_pgid(pid_t pgid)
{
@@ -75,12 +89,11 @@ static struct apprun *runner_of_pgid(pid_t pgid)
result = result->next_by_pgid;
return result;
}
-#endif
/* insert a runner for its pgid */
static void pgid_insert(struct apprun *runner)
{
- struct apprun **prev = &runners_by_runid[(int)(runner->pids[0] & (ROOT_RUNNERS_COUNT - 1))];
+ struct apprun **prev = &runners_by_pgid[(int)(runner->pids[0] & (ROOT_RUNNERS_COUNT - 1))];
runner->next_by_pgid = *prev;
*prev = runner;
}
@@ -88,24 +101,14 @@ static void pgid_insert(struct apprun *runner)
/* remove a runner for its pgid */
static void pgid_remove(struct apprun *runner)
{
- struct apprun **prev = &runners_by_runid[(int)(runner->pids[0] & (ROOT_RUNNERS_COUNT - 1))];
- runner->next_by_pgid = *prev;
- *prev = runner;
-}
-
-/****************** manages pids **********************/
-
-/* get a runner by its pid */
-static struct apprun *runner_of_pid(pid_t pid)
-{
- int i;
- struct apprun *result;
-
- for (i = 0 ; i < ROOT_RUNNERS_COUNT ; i++)
- for (result = runners_by_pgid[i] ; result != NULL ; result = result->next_by_pgid)
- if (result->pids[0] == pid || result->pids[1] == pid)
- return result;
- return NULL;
+ struct apprun **prev = &runners_by_pgid[(int)(runner->pids[0] & (ROOT_RUNNERS_COUNT - 1))];
+ while (*prev) {
+ if (*prev == runner) {
+ *prev = runner->next_by_pgid;
+ break;
+ }
+ prev = &(*prev)->next_by_pgid;
+ }
}
/****************** manages runners (by runid) **********************/