finit: add finit state machine

Signed-off-by: Jonas Johansson <jonas.johansson@westermo.se>
This commit is contained in:
Jonas Johansson committed 2016-05-16 15:17:02 +02:00
1 parent 6d84fd010e
commit 364f3bbafb
6 files changed
+119 -17

No files matched your search

+2 -2
View File
@@ -34,10 +34,10 @@ ARCHTOOL = `which git-archive-all`
ARCHIVE = $(PKG).tar ARCHIVE = $(PKG).tar
ARCHIVEZ = ../$(ARCHIVE).xz ARCHIVEZ = ../$(ARCHIVE).xz
EXEC = finit initctl reboot EXEC = finit initctl reboot
HEADERS = finit.h plugin.h svc.h inetd.h helpers.h queue.h cond.h HEADERS = finit.h plugin.h svc.h inetd.h helpers.h queue.h cond.h sm.h
DISTFILES = LICENSE README ChangeLog finit.conf services DISTFILES = LICENSE README ChangeLog finit.conf services
OBJS = finit.o api.o client.o conf.o exec.o helpers.o pid.o sig.o \ OBJS = finit.o api.o client.o conf.o exec.o helpers.o pid.o sig.o \
svc.o service.o plugin.o tty.o inetd.o cond.o cond-w.o svc.o service.o plugin.o tty.o inetd.o cond.o cond-w.o sm.o
DEPLIBS = DEPLIBS =
TOPDIR = $(shell pwd) TOPDIR = $(shell pwd)
-include config.mk -include config.mk
+5 -2
View File
@@ -39,6 +39,7 @@
#include "tty.h" #include "tty.h"
#include "libite/lite.h" #include "libite/lite.h"
#include "inetd.h" #include "inetd.h"
#include "sm.h"
int debug = 0; int debug = 0;
int quiet = KERNEL_QUIET; /* Delayed disable of verbose mode. */ int quiet = KERNEL_QUIET; /* Delayed disable of verbose mode. */
@@ -53,6 +54,7 @@ char *hostname = NULL;
char *rcsd = FINIT_RCSD; char *rcsd = FINIT_RCSD;
char *runparts = NULL; char *runparts = NULL;
char *console = NULL; char *console = NULL;
sm_t sm;
uev_ctx_t *ctx = NULL; /* Main loop context */ uev_ctx_t *ctx = NULL; /* Main loop context */
@@ -176,9 +178,10 @@ int main(int argc, char* argv[])
plugin_run_hooks(HOOK_BASEFS_UP); plugin_run_hooks(HOOK_BASEFS_UP);
/* /*
* Start all bootstrap tasks, no network available! * Initalize finit state machine and start all bootstrap tasks, no network available!
*/ */
service_bootstrap(); sm_init(&sm);
sm_step(&sm);
/* /*
* Network stuff * Network stuff
-1
View File
@@ -33,7 +33,6 @@ uev_ctx_t *ctx; /* Main loop context */
int api_init (uev_ctx_t *ctx); int api_init (uev_ctx_t *ctx);
int client (int argc, char *argv[]); int client (int argc, char *argv[]);
void service_bootstrap(void);
void service_monitor (pid_t lost); void service_monitor (pid_t lost);
void plugin_run_hooks (hook_point_t no); void plugin_run_hooks (hook_point_t no);
-12
View File
@@ -47,18 +47,6 @@ static int in_teardown = 0, in_dyn_teardown = 0;
static svc_t *find_inetd_svc (char *path, char *service, char *proto); static svc_t *find_inetd_svc (char *path, char *service, char *proto);
#endif #endif
/**
* service_bootstrap - Start bootstrap services and tasks
*
* System startup, runlevel S, where only services, tasks and
* run commands absolutely essential to bootstrap are located.
*/
void service_bootstrap(void)
{
_d("Bootstrapping all services in runlevel S from %s", FINIT_CONF);
service_step_all(SVC_TYPE_RUN | SVC_TYPE_TASK | SVC_TYPE_SERVICE);
}
/** /**
* service_enabled - Should the service run? * service_enabled - Should the service run?
* @svc: Pointer to &svc_t object * @svc: Pointer to &svc_t object
+66
View File
@@ -0,0 +1,66 @@
/* Finit state machine
*
* Copyright (c) 2016 xxx
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include "config.h" /* Generated by configure script */
#include <sys/types.h>
#include "finit.h"
#include "helpers.h"
#include "service.h"
#include "sm.h"
void sm_init(sm_t *sm)
{
sm->state = SM_BOOTSTRAP_STATE;
}
void sm_step(sm_t *sm)
{
sm_state_t old_state;
restart:
old_state = sm->state;
switch(sm->state) {
case SM_BOOTSTRAP_STATE:
_d("Bootstrapping all services in runlevel S from %s", FINIT_CONF);
service_step_all(SVC_TYPE_RUN | SVC_TYPE_TASK | SVC_TYPE_SERVICE);
sm->state = SM_RUNNING_STATE;
break;
case SM_RUNNING_STATE:
break;
}
if (sm->state != old_state) {
goto restart;
}
}
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/
+46
View File
@@ -0,0 +1,46 @@
/* Finit state machine
*
* Copyright (c) 2016 xxx
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef FINIT_SM_H_
#define FINIT_SM_H_
typedef enum {
SM_BOOTSTRAP_STATE = 0,
SM_RUNNING_STATE,
} sm_state_t;
typedef struct sm {
sm_state_t state;
} sm_t;
void sm_init(sm_t *sm);
void sm_step(sm_t *sm);
#endif /* FINIT_SM_H_ */
/**
* Local Variables:
* indent-tabs-mode: t
* c-file-style: "linux"
* End:
*/