From 42181a30311df0a5234b3ba48c5f04f3543f2cd8 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 21 Jul 2016 15:49:00 +0200 Subject: [PATCH] Add OpenRC-like support for sysctl.d/*.conf Signed-off-by: Joachim Nilsson --- finit.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/finit.c b/finit.c index 2c87c065..798f5992 100644 --- a/finit.c +++ b/finit.c @@ -24,10 +24,11 @@ #include "config.h" /* Generated by configure script */ -#include #include +#include #include #include +#include #include /* umask(), mkdir() */ #include @@ -70,6 +71,36 @@ static int banner(void) return 0; } +static void networking(void) +{ + size_t i; + glob_t gl; + + /* Setup kernel specific settings, e.g. allow broadcast ping, etc. */ + glob("/run/sysctl.d/*.conf", 0, NULL, &gl); + glob("/etc/sysctl.d/*.conf", GLOB_APPEND, NULL, &gl); + glob("/usr/local/lib/sysctl.d/*.conf", GLOB_APPEND, NULL, &gl); + glob("/usr/lib/sysctl.d/*.conf", GLOB_APPEND, NULL, &gl); + glob("/lib/sysctl.d/*.conf", GLOB_APPEND, NULL, &gl); + glob("/mnt/sysctl.d/*.conf", GLOB_APPEND, NULL, &gl); + glob("/etc/sysctl.conf", GLOB_APPEND, NULL, &gl); + if (gl.gl_pathc > 0) { + for (i = 0; i < gl.gl_pathc; i++) { + char cmd[160]; + + snprintf(cmd, sizeof(cmd), "/sbin/sysctl -e -p %s >/dev/null", gl.gl_pathv[i]); + run(cmd); + } + globfree(&gl); + } + + /* Run user network start script, or fall back to at least loopback */ + if (network) + run_interactive(network, "Starting networking: %s", network); + else + ifconfig("lo", "127.0.0.1", "255.0.0.0", 1); +} + /* Requires /proc to be mounted */ static int fismnt(char *dir) { @@ -220,15 +251,7 @@ int main(int argc, char* argv[]) /* * Network stuff */ - - /* Setup kernel specific settings, e.g. allow broadcast ping, etc. */ - run("/sbin/sysctl -e -p /etc/sysctl.conf >/dev/null"); - - /* Run user network start script, or fall back to at least loopback */ - if (network) - run_interactive(network, "Starting networking: %s", network); - else - ifconfig("lo", "127.0.0.1", "255.0.0.0", 1); + networking(); umask(022); /* Hooks that rely on loopback, or basic networking being up. */