Add OpenRC-like support for sysctl.d/*.conf

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2016-07-21 15:49:00 +02:00
1 parent 77b32ebff0
commit 42181a3031
1 file changed
+33 -10
+33 -10
View File
@@ -24,10 +24,11 @@
#include "config.h" /* Generated by configure script */
#include <sys/mount.h>
#include <ctype.h>
#include <glob.h>
#include <dirent.h>
#include <mntent.h>
#include <sys/mount.h>
#include <sys/stat.h> /* umask(), mkdir() */
#include <lite/lite.h>
@@ -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. */