Fix #18: Add support for calling run/tasks on HOOK points

This patch implements support for calling run/task jobs on the built-in
`HOOK_*` points in Finit.  To map each HOOK point to a condition a new
classification was made, as shown in plugin.h and in the example below.

task <hook/mount/root> /sbin/attachubi.sh      # run in parallel with other tasks/services
run  <hook/net/up>     /sbin/dosomething.sh    # run in sequence with other commands

Please note, only rudimentary tested.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2017-12-13 17:58:48 +01:00
parent e841984a4e
commit 9e31bd8a23
4 changed files with 60 additions and 22 deletions
+32 -1
View File
@@ -30,10 +30,12 @@
#include <lite/queue.h> /* BSD sys/queue.h API */
#include "config.h"
#include "cond.h"
#include "finit.h"
#include "private.h"
#include "helpers.h"
#include "plugin.h"
#include "private.h"
#include "service.h"
#define is_io_plugin(p) ((p)->io.cb && (p)->io.fd > 0)
#define SEARCH_PLUGIN(str) \
@@ -163,6 +165,15 @@ plugin_t *plugin_find(char *name)
}
/* Private daemon API *******************************************************/
#define CHOOSE(x, y) y
static const char *hook_cond[] = HOOK_TYPES;
#undef CHOOSE
const char *plugin_hook_str(hook_point_t no)
{
return hook_cond[no];
}
int plugin_exists(hook_point_t no)
{
plugin_t *p, *tmp;
@@ -178,14 +189,34 @@ int plugin_exists(hook_point_t no)
/* Some hooks are called with a fixed argument, like HOOK_SVC_LOST */
void plugin_run_hook(hook_point_t no, void *arg)
{
static int last = -1;
plugin_t *p, *tmp;
/*
* End recursion: any plugin hook => start service => SVC start
* hook => start service ... err ... wait a second
*/
if (HOOK_SVC_START == last) {
_d("End plugin recursion in our lifetime!");
return;
}
PLUGIN_ITERATOR(p, tmp) {
if (p->hook[no].cb) {
_d("Calling %s hook n:o %d (arg: %p) ...", basename(p->name), no, arg);
p->hook[no].cb(arg ? arg : p->hook[no].arg);
}
}
/* Guard against infinite recursion */
if (HOOK_SVC_START == no)
last = no;
cond_set(hook_cond[no]);
service_step_all(SVC_TYPE_RUNTASK);
if (HOOK_SVC_START == no)
last = -1;
}
/* Regular hooks are called with the registered plugin's argument */