From 59731dd69bb4be66c721b3de66fb2ab80bec3e7e Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 22 Apr 2018 01:02:27 +0200 Subject: Add helper program for running services We no longer need to keep entire scripts in init program (i.e. saving space) and reduce the code and complexity of the init program. The runsvc tool can later be extended to do more complex child setup, such as configuring namespaces or seccomp without adding complexity or memory footprint to init. Signed-off-by: David Oberhollenzer --- initd/init.h | 39 ++++++++------------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) (limited to 'initd/init.h') diff --git a/initd/init.h b/initd/init.h index 3510073..d07f310 100644 --- a/initd/init.h +++ b/initd/init.h @@ -27,7 +27,7 @@ #include "telinit.h" #include "util.h" -#define ENVFILE ETCPATH "/initd.env" +#define RUNSVCBIN SCRIPTDIR "/runsvc" enum { STATUS_OK = 0, @@ -36,35 +36,20 @@ enum { STATUS_STARTED, }; -/********** runlst.c **********/ +/********** runsvc.c **********/ /* - Plow through an array of strings and execute each one, i.e. do - a fork() and exec(). + Invoke the runsvc command to execute the comands of a service. - In the parent process, wait() until the child is done before - continuing through the list. - - If ctty is not NULL, open it and redirect all I/O of the child - process to that file. - - If everyhing works, the function returns EXIT_SUCCESS. If one child - does not exit with EXIT_SUCCESS, processing of the list is aborted - and the function returns the exit status of the failed process. + Returns the pid of the child process containing the runsvc instance. */ -int runlst_wait(exec_t *list, const char *ctty); +pid_t runsvc(service_t *svc); /* - Does basically the same as runlst_wait, but asynchronously. - - A child process is created that calls runlst_wait exits with the - result of runlst_wait. In the parent process, the function returns - immediately with the PID of the child process. - - Alternatively, if num is 1, the child process directly exec()s the - given command. + Start a service using runsvc, but wait until the child process + terminats and return its exit status. */ -pid_t runlst(exec_t *list, const char *ctty); +int runsvc_wait(service_t *svc); /********** status.c **********/ @@ -111,14 +96,6 @@ void svclist_add(service_t *svc); */ service_t *svclist_remove(pid_t pid); -/********** env.c **********/ - -/* - Read /etc/initd.env (actually ENVFILE defined above) - and setup environment variables for init. -*/ -int initenv(void); - /********** signal_.c **********/ /* -- cgit v1.2.3