summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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) **********************/