diff --git a/Makefile b/Makefile index 5282ec03..49efa087 100644 --- a/Makefile +++ b/Makefile @@ -34,10 +34,10 @@ ARCHTOOL = `which git-archive-all` ARCHIVE = $(PKG).tar ARCHIVEZ = ../$(ARCHIVE).xz 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 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 = TOPDIR = $(shell pwd) -include config.mk diff --git a/finit.c b/finit.c index 67c936b2..71338f49 100644 --- a/finit.c +++ b/finit.c @@ -39,6 +39,7 @@ #include "tty.h" #include "libite/lite.h" #include "inetd.h" +#include "sm.h" int debug = 0; int quiet = KERNEL_QUIET; /* Delayed disable of verbose mode. */ @@ -53,6 +54,7 @@ char *hostname = NULL; char *rcsd = FINIT_RCSD; char *runparts = NULL; char *console = NULL; +sm_t sm; uev_ctx_t *ctx = NULL; /* Main loop context */ @@ -176,9 +178,10 @@ int main(int argc, char* argv[]) 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 diff --git a/private.h b/private.h index 9f3bde86..60565cc4 100644 --- a/private.h +++ b/private.h @@ -33,7 +33,6 @@ uev_ctx_t *ctx; /* Main loop context */ int api_init (uev_ctx_t *ctx); int client (int argc, char *argv[]); -void service_bootstrap(void); void service_monitor (pid_t lost); void plugin_run_hooks (hook_point_t no); diff --git a/service.c b/service.c index c47634df..e84b9797 100644 --- a/service.c +++ b/service.c @@ -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); #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? * @svc: Pointer to &svc_t object diff --git a/sm.c b/sm.c new file mode 100644 index 00000000..5c35d159 --- /dev/null +++ b/sm.c @@ -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 + +#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: + */ diff --git a/sm.h b/sm.h new file mode 100644 index 00000000..2450b809 --- /dev/null +++ b/sm.h @@ -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: + */