mirror of
https://github.com/troglobit/finit.git
synced 2026-12-04 21:58:19 +00:00
Refactor: Cleanup internal API
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
d8b331d737
commit
a05f920292
9 files changed
+65
-57
No files matched your search
@@ -207,7 +207,7 @@ static void cb(uev_t *w, void *UNUSED(arg), int UNUSED(events))
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case INIT_CMD_RELOAD:
|
case INIT_CMD_RELOAD:
|
||||||
reload_finit_d();
|
service_reload_dynamic();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case INIT_CMD_START_SVC:
|
case INIT_CMD_START_SVC:
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ static char *strip_line(char *line)
|
|||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse_kernel_cmdline(void)
|
void conf_parse_cmdline(void)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char line[LINE_SIZE];
|
char line[LINE_SIZE];
|
||||||
@@ -78,7 +78,7 @@ void parse_kernel_cmdline(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Convert optional "[!123456789S]" string into a bitmask */
|
/* Convert optional "[!123456789S]" string into a bitmask */
|
||||||
int parse_runlevels(char *runlevels)
|
int conf_parse_runlevels(char *runlevels)
|
||||||
{
|
{
|
||||||
int i, not = 0, bitmask = 0;
|
int i, not = 0, bitmask = 0;
|
||||||
|
|
||||||
@@ -340,11 +340,16 @@ static int parse_conf(char *file)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_finit_d(char *dir)
|
/* Reload all *.conf in /etc/finit.d/ */
|
||||||
|
int conf_reload_dynamic(void)
|
||||||
{
|
{
|
||||||
int i, num;
|
int i, num;
|
||||||
|
char *dir = rcsd;
|
||||||
struct dirent **e;
|
struct dirent **e;
|
||||||
|
|
||||||
|
/* Mark and sweep */
|
||||||
|
svc_mark_dynamic();
|
||||||
|
|
||||||
num = scandir(dir, &e, NULL, alphasort);
|
num = scandir(dir, &e, NULL, alphasort);
|
||||||
if (num < 0) {
|
if (num < 0) {
|
||||||
_d("No files found in %s, skipping ...", dir);
|
_d("No files found in %s, skipping ...", dir);
|
||||||
@@ -382,14 +387,14 @@ int parse_finit_d(char *dir)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int parse_finit_conf(char *file)
|
int conf_parse_config(void)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
username = strdup(DEFUSER);
|
username = strdup(DEFUSER);
|
||||||
hostname = strdup(DEFHOST);
|
hostname = strdup(DEFHOST);
|
||||||
|
|
||||||
result = parse_conf(file);
|
result = parse_conf(FINIT_CONF);
|
||||||
if (!tty_num()) {
|
if (!tty_num()) {
|
||||||
char *fallback = FALLBACK_SHELL;
|
char *fallback = FALLBACK_SHELL;
|
||||||
|
|
||||||
@@ -402,22 +407,6 @@ int parse_finit_conf(char *file)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called on SIGHUP or 'init q' */
|
|
||||||
void reload_finit_d(void)
|
|
||||||
{
|
|
||||||
/* Mark and sweep */
|
|
||||||
svc_mark_dynamic();
|
|
||||||
|
|
||||||
/* Reload all *.conf in /etc/finit.d/ */
|
|
||||||
parse_finit_d(rcsd);
|
|
||||||
|
|
||||||
/* Reload dirty services */
|
|
||||||
service_reload_dynamic();
|
|
||||||
|
|
||||||
/* Cleanup stale services */
|
|
||||||
svc_clean_dynamic(service_unregister);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Local Variables:
|
* Local Variables:
|
||||||
|
|||||||
@@ -24,11 +24,10 @@
|
|||||||
#ifndef FINIT_CONF_H_
|
#ifndef FINIT_CONF_H_
|
||||||
#define FINIT_CONF_H_
|
#define FINIT_CONF_H_
|
||||||
|
|
||||||
void parse_kernel_cmdline (void);
|
void conf_parse_cmdline (void);
|
||||||
int parse_runlevels (char *runlevels);
|
int conf_parse_runlevels (char *runlevels);
|
||||||
int parse_finit_conf (char *file);
|
int conf_parse_config (void);
|
||||||
int parse_finit_d (char *dir);
|
int conf_reload_dynamic (void);
|
||||||
void reload_finit_d (void);
|
|
||||||
|
|
||||||
#endif /* FINIT_CONF_H_ */
|
#endif /* FINIT_CONF_H_ */
|
||||||
|
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ int main(int argc, char* argv[])
|
|||||||
/*
|
/*
|
||||||
* Parse kernel parameters
|
* Parse kernel parameters
|
||||||
*/
|
*/
|
||||||
parse_kernel_cmdline();
|
conf_parse_cmdline();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Hello world.
|
* Hello world.
|
||||||
@@ -127,9 +127,9 @@ int main(int argc, char* argv[])
|
|||||||
plugin_load_all(&loop, PLUGIN_PATH);
|
plugin_load_all(&loop, PLUGIN_PATH);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse configuration file
|
* Parse /etc/finit.conf, main configuration file
|
||||||
*/
|
*/
|
||||||
parse_finit_conf(FINIT_CONF);
|
conf_parse_config();
|
||||||
|
|
||||||
/* Set hostname as soon as possible, for syslog et al. */
|
/* Set hostname as soon as possible, for syslog et al. */
|
||||||
set_hostname(&hostname);
|
set_hostname(&hostname);
|
||||||
@@ -182,10 +182,8 @@ int main(int argc, char* argv[])
|
|||||||
plugin_run_hooks(HOOK_NETWORK_UP);
|
plugin_run_hooks(HOOK_NETWORK_UP);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Load .conf files from /etc/finit.d and start all
|
* Start all tasks/services in the configured runlevel
|
||||||
* tasks/services in the configured runlevel
|
|
||||||
*/
|
*/
|
||||||
parse_finit_d(rcsd);
|
|
||||||
service_runlevel(cfglevel);
|
service_runlevel(cfglevel);
|
||||||
|
|
||||||
_d("Running svc up hooks ...");
|
_d("Running svc up hooks ...");
|
||||||
|
|||||||
+1
-1
@@ -119,7 +119,7 @@ static void parse(void *UNUSED(arg), int fd, int UNUSED(events))
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case INIT_CMD_RELOAD:
|
case INIT_CMD_RELOAD:
|
||||||
reload_finit_d();
|
service_reload_dynamic();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -334,6 +334,37 @@ exit:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* service_start_dynamic - Start or reload modified dynamic services
|
||||||
|
*/
|
||||||
|
void service_start_dynamic(void)
|
||||||
|
{
|
||||||
|
svc_t *svc;
|
||||||
|
|
||||||
|
_d("Starting enabled/added services ...");
|
||||||
|
for (svc = svc_dynamic_iterator(1); svc; svc = svc_dynamic_iterator(0)) {
|
||||||
|
if (svc->dirty > 0)
|
||||||
|
svc_dance(svc);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cleanup stale services */
|
||||||
|
svc_clean_dynamic(service_unregister);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* service_stop_dynamic - Stop disabled/removed dynamic services
|
||||||
|
*/
|
||||||
|
void service_stop_dynamic(void)
|
||||||
|
{
|
||||||
|
svc_t *svc;
|
||||||
|
|
||||||
|
_d("Stopping disabled/removed services ...");
|
||||||
|
for (svc = svc_dynamic_iterator(1); svc; svc = svc_dynamic_iterator(0)) {
|
||||||
|
if (svc->dirty != 0)
|
||||||
|
service_stop(svc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* stop + start */
|
/* stop + start */
|
||||||
int service_restart(svc_t *svc)
|
int service_restart(svc_t *svc)
|
||||||
{
|
{
|
||||||
@@ -381,7 +412,7 @@ int service_reload(svc_t *svc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* service_reload_dynamic - Reload modifued dynamic services
|
* service_reload_dynamic - Called on SIGHUP, 'init q' or 'initctl reload'
|
||||||
*
|
*
|
||||||
* This function is called when Finit has recieved SIGHUP to reload
|
* This function is called when Finit has recieved SIGHUP to reload
|
||||||
* .conf files in /etc/finit.d. It is responsible for starting,
|
* .conf files in /etc/finit.d. It is responsible for starting,
|
||||||
@@ -389,25 +420,17 @@ int service_reload(svc_t *svc)
|
|||||||
*/
|
*/
|
||||||
void service_reload_dynamic(void)
|
void service_reload_dynamic(void)
|
||||||
{
|
{
|
||||||
int num = 0;
|
/* First reload all *.conf in /etc/finit.d/ */
|
||||||
svc_t *svc;
|
conf_reload_dynamic();
|
||||||
|
|
||||||
_d("Stopping disabled/removed services ...");
|
/* Then stop any disabled/removed services and non-reloadable */
|
||||||
for (svc = svc_dynamic_iterator(1); svc; svc = svc_dynamic_iterator(0)) {
|
service_stop_dynamic();
|
||||||
if (svc->dirty != 0) {
|
|
||||||
service_stop(svc);
|
|
||||||
num++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_d("All disabled/removed services have been stoppped, calling reconf hooks ...");
|
_d("All disabled/removed services have been stoppped, calling reconf hooks ...");
|
||||||
plugin_run_hooks(HOOK_SVC_RECONF); /* Reconfigure HW/VLANs/etc here */
|
plugin_run_hooks(HOOK_SVC_RECONF); /* Reconfigure HW/VLANs/etc here */
|
||||||
|
|
||||||
_d("Starting enabled/added services ...");
|
/* Finish off by starting/reload modified/new services */
|
||||||
for (svc = svc_dynamic_iterator(1); svc; svc = svc_dynamic_iterator(0)) {
|
service_start_dynamic();
|
||||||
if (svc->dirty > 0)
|
|
||||||
svc_dance(svc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -433,9 +456,8 @@ void service_runlevel(int newlevel)
|
|||||||
_d("Setting new runlevel --> %d <-- previous %d", runlevel, prevlevel);
|
_d("Setting new runlevel --> %d <-- previous %d", runlevel, prevlevel);
|
||||||
runlevel_set(prevlevel, newlevel);
|
runlevel_set(prevlevel, newlevel);
|
||||||
|
|
||||||
/* Make sure to reload all *.conf in /etc/finit.d/ */
|
/* Make sure to (re)load all *.conf in /etc/finit.d/ */
|
||||||
svc_mark_dynamic();
|
conf_reload_dynamic();
|
||||||
parse_finit_d(rcsd);
|
|
||||||
|
|
||||||
_d("Stopping services services not allowed in new runlevel ...");
|
_d("Stopping services services not allowed in new runlevel ...");
|
||||||
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
|
for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
|
||||||
@@ -671,7 +693,7 @@ int service_register(int type, char *line, time_t mtime, char *username)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
svc->runlevels = parse_runlevels(runlevels);
|
svc->runlevels = conf_parse_runlevels(runlevels);
|
||||||
_d("Service %s runlevel 0x%2x", svc->cmd, svc->runlevels);
|
_d("Service %s runlevel 0x%2x", svc->cmd, svc->runlevels);
|
||||||
|
|
||||||
#ifndef INETD_DISABLED
|
#ifndef INETD_DISABLED
|
||||||
|
|||||||
@@ -34,12 +34,12 @@ svc_cmd_t service_enabled (svc_t *svc, int event, void *arg);
|
|||||||
|
|
||||||
int service_start (svc_t *svc);
|
int service_start (svc_t *svc);
|
||||||
int service_stop (svc_t *svc);
|
int service_stop (svc_t *svc);
|
||||||
|
void service_start_dynamic (void);
|
||||||
|
void service_stop_dynamic (void);
|
||||||
int service_restart (svc_t *svc);
|
int service_restart (svc_t *svc);
|
||||||
int service_reload (svc_t *svc);
|
int service_reload (svc_t *svc);
|
||||||
void service_reload_dynamic (void);
|
void service_reload_dynamic (void);
|
||||||
|
|
||||||
void service_cleanup (void);
|
|
||||||
|
|
||||||
#endif /* FINIT_SERVICE_H_ */
|
#endif /* FINIT_SERVICE_H_ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ void do_shutdown(int sig)
|
|||||||
*/
|
*/
|
||||||
static void sighup_cb(uev_t *UNUSED(w), void *UNUSED(arg), int UNUSED(events))
|
static void sighup_cb(uev_t *UNUSED(w), void *UNUSED(arg), int UNUSED(events))
|
||||||
{
|
{
|
||||||
reload_finit_d();
|
service_reload_dynamic();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ int tty_register(char *line)
|
|||||||
baud = BAUDRATE;
|
baud = BAUDRATE;
|
||||||
entry->data.baud = baud;
|
entry->data.baud = baud;
|
||||||
entry->data.term = term ? strdup(term) : NULL;
|
entry->data.term = term ? strdup(term) : NULL;
|
||||||
entry->data.runlevels = parse_runlevels(runlevels);
|
entry->data.runlevels = conf_parse_runlevels(runlevels);
|
||||||
_d("Registering tty %s at %d baud with term=%s on runlevels %s", dev, baud, term ?: "N/A", runlevels);
|
_d("Registering tty %s at %d baud with term=%s on runlevels %s", dev, baud, term ?: "N/A", runlevels);
|
||||||
|
|
||||||
if (insert)
|
if (insert)
|
||||||
|
|||||||
Reference in new issue
Block a user