From 892ac2edb2ea2db2aa27201b727a6b269cc95f9e Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 8 Dec 2016 08:17:38 +0100 Subject: [PATCH] Fix #47: Relocate sysctl.conf setup to procps plugin Signed-off-by: Joachim Nilsson --- finit.c | 23 ++------------ plugins/Makefile.am | 4 +-- plugins/procps.c | 74 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 23 deletions(-) create mode 100644 plugins/procps.c diff --git a/finit.c b/finit.c index 92b1b9c0..edb9cf52 100644 --- a/finit.c +++ b/finit.c @@ -25,7 +25,6 @@ #include "config.h" /* Generated by configure script */ #include -#include #include #ifdef HAVE_FSTAB_H #include @@ -121,26 +120,7 @@ static int fsck(int pass) static void networking(void) { - size_t i; - glob_t gl; FILE *fp; - char buf[160]; - - /* 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++) { - snprintf(buf, sizeof(buf), "/sbin/sysctl -e -p %s >/dev/null", gl.gl_pathv[i]); - run(buf); - } - globfree(&gl); - } /* Run user network start script if enabled */ if (network) { @@ -151,7 +131,8 @@ static void networking(void) /* Debian/Ubuntu/Busybox interfaces file */ fp = fopen("/etc/network/interfaces", "r"); if (fp) { - i = 0; + int i = 0; + char buf[160]; /* Bring up all 'auto' interfaces */ while (fgets(buf, sizeof(buf), fp)) { diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 00f72b0c..616ee071 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -6,7 +6,7 @@ AM_CPPFLAGS += $(lite_CFLAGS) if STATIC noinst_LTLIBRARIES = libplug.la -libplug_la_SOURCES = bootmisc.c hwclock.c initctl.c pidfile.c tty.c urandom.c +libplug_la_SOURCES = bootmisc.c hwclock.c initctl.c pidfile.c procps.c tty.c urandom.c if BUILD_ALSA_UTILS_PLUGIN libplug_la_SOURCES += alsa-utils.c @@ -51,7 +51,7 @@ libplug_la_SOURCES += resolvconf.c endif else -pkglib_LTLIBRARIES = bootmisc.la hwclock.la initctl.la pidfile.la tty.la urandom.la +pkglib_LTLIBRARIES = bootmisc.la hwclock.la initctl.la pidfile.la procps.la tty.la urandom.la if BUILD_ALSA_UTILS_PLUGIN pkglib_LTLIBRARIES += alsa-utils.la diff --git a/plugins/procps.c b/plugins/procps.c new file mode 100644 index 00000000..5159f4aa --- /dev/null +++ b/plugins/procps.c @@ -0,0 +1,74 @@ +/* Set kernel variables from /etc/sysctl.conf et al + * + * Copyright (c) 2016 Joachim Nilsson + * + * 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 +#include +#include "../plugin.h" + +static void setup(void *UNUSED(arg)) +{ + size_t i; + glob_t gl; + char buf[160]; + + 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++) { + snprintf(buf, sizeof(buf), "/sbin/sysctl -e -p %s >/dev/null", gl.gl_pathv[i]); + run(buf); + } + globfree(&gl); + } + +} + +static plugin_t plugin = { + .name = __FILE__, + .hook[HOOK_BASEFS_UP] = { + .cb = setup + }, + .depends = { "bootmisc", }, +}; + +PLUGIN_INIT(plugin_init) +{ + plugin_register(&plugin); +} + +PLUGIN_EXIT(plugin_exit) +{ + plugin_unregister(&plugin); +} + +/** + * Local Variables: + * indent-tabs-mode: t + * c-file-style: "linux" + * End: + */