mirror of
https://github.com/troglobit/finit.git
synced 2026-11-09 16:21:24 +00:00
Prototype support for /etc/netork/interfaces
This patch adds prototype support for the Debian/Ubuntu/Busybox network configuration file /etc/netork/interfaces. If this file exists Finit will call `ifup` for each (non-commented-out) interface marked `auto`. With this implementation we block boot until all ifup commands have returned, which is less than ideal. A better approach would be to ifup only loopback and create deferred tasklets to be run in parallel with the rest of the boot. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
42181a3031
commit
6380f17d1f
4 files changed
+53
-26
No files matched your search
@@ -23,7 +23,6 @@
|
|||||||
|
|
||||||
#include "config.h" /* Generated by configure script */
|
#include "config.h" /* Generated by configure script */
|
||||||
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
@@ -41,23 +40,6 @@
|
|||||||
static int parse_conf(char *file);
|
static int parse_conf(char *file);
|
||||||
|
|
||||||
|
|
||||||
static char *strip_line(char *line)
|
|
||||||
{
|
|
||||||
char *ptr;
|
|
||||||
|
|
||||||
/* Trim leading whitespace */
|
|
||||||
while (*line && isblank(*line))
|
|
||||||
line++;
|
|
||||||
|
|
||||||
/* Strip any comment at end of line */
|
|
||||||
ptr = line;
|
|
||||||
while (*ptr && *ptr != '#')
|
|
||||||
ptr++;
|
|
||||||
*ptr = 0;
|
|
||||||
|
|
||||||
return line;
|
|
||||||
}
|
|
||||||
|
|
||||||
void conf_parse_cmdline(void)
|
void conf_parse_cmdline(void)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ static void networking(void)
|
|||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
glob_t gl;
|
glob_t gl;
|
||||||
|
FILE *fp;
|
||||||
|
char buf[160];
|
||||||
|
|
||||||
/* Setup kernel specific settings, e.g. allow broadcast ping, etc. */
|
/* Setup kernel specific settings, e.g. allow broadcast ping, etc. */
|
||||||
glob("/run/sysctl.d/*.conf", 0, NULL, &gl);
|
glob("/run/sysctl.d/*.conf", 0, NULL, &gl);
|
||||||
@@ -86,19 +88,42 @@ static void networking(void)
|
|||||||
glob("/etc/sysctl.conf", GLOB_APPEND, NULL, &gl);
|
glob("/etc/sysctl.conf", GLOB_APPEND, NULL, &gl);
|
||||||
if (gl.gl_pathc > 0) {
|
if (gl.gl_pathc > 0) {
|
||||||
for (i = 0; i < gl.gl_pathc; i++) {
|
for (i = 0; i < gl.gl_pathc; i++) {
|
||||||
char cmd[160];
|
snprintf(buf, sizeof(buf), "/sbin/sysctl -e -p %s >/dev/null", gl.gl_pathv[i]);
|
||||||
|
run(buf);
|
||||||
snprintf(cmd, sizeof(cmd), "/sbin/sysctl -e -p %s >/dev/null", gl.gl_pathv[i]);
|
|
||||||
run(cmd);
|
|
||||||
}
|
}
|
||||||
globfree(&gl);
|
globfree(&gl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Run user network start script, or fall back to at least loopback */
|
/* Run user network start script if enabled */
|
||||||
if (network)
|
if (network) {
|
||||||
run_interactive(network, "Starting networking: %s", network);
|
run_interactive(network, "Starting networking: %s", network);
|
||||||
else
|
return;
|
||||||
ifconfig("lo", "127.0.0.1", "255.0.0.0", 1);
|
}
|
||||||
|
|
||||||
|
/* Debian/Ubuntu/Busybox interfaces file */
|
||||||
|
fp = fopen("/etc/network/interfaces", "r");
|
||||||
|
if (fp) {
|
||||||
|
i = 0;
|
||||||
|
|
||||||
|
/* Bring up all 'auto' interfaces */
|
||||||
|
while (fgets(buf, sizeof(buf), fp)) {
|
||||||
|
chomp(buf);
|
||||||
|
strip_line(buf);
|
||||||
|
|
||||||
|
if (!strncmp(buf, "auto", 4)) {
|
||||||
|
memcpy(buf, "ifup", 4);
|
||||||
|
run_interactive(buf, "Bringing up interface %s", buf[5]);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fp);
|
||||||
|
if (i)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fall back to bring up at least loopback */
|
||||||
|
ifconfig("lo", "127.0.0.1", "255.0.0.0", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Requires /proc to be mounted */
|
/* Requires /proc to be mounted */
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <ctype.h> /* isblank() */
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
@@ -39,6 +40,23 @@
|
|||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "private.h"
|
#include "private.h"
|
||||||
|
|
||||||
|
char *strip_line(char *line)
|
||||||
|
{
|
||||||
|
char *ptr;
|
||||||
|
|
||||||
|
/* Trim leading whitespace */
|
||||||
|
while (*line && isblank(*line))
|
||||||
|
line++;
|
||||||
|
|
||||||
|
/* Strip any comment at end of line */
|
||||||
|
ptr = line;
|
||||||
|
while (*ptr && *ptr != '#')
|
||||||
|
ptr++;
|
||||||
|
*ptr = 0;
|
||||||
|
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
static int encode(int lvl)
|
static int encode(int lvl)
|
||||||
{
|
{
|
||||||
if (!lvl) return 0;
|
if (!lvl) return 0;
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ do { \
|
|||||||
#define _e(fmt, args...) do { fprintf(stderr, "finit:%s:%s() - " fmt "\n", __FILE__, __func__, ##args); } while (0)
|
#define _e(fmt, args...) do { fprintf(stderr, "finit:%s:%s() - " fmt "\n", __FILE__, __func__, ##args); } while (0)
|
||||||
#define _pe(fmt, args...) do { fprintf(stderr, "finit:%s:%s() - " fmt ". Error %d: %s\n", __FILE__, __func__, ##args, errno, strerror(errno)); } while (0)
|
#define _pe(fmt, args...) do { fprintf(stderr, "finit:%s:%s() - " fmt ". Error %d: %s\n", __FILE__, __func__, ##args, errno, strerror(errno)); } while (0)
|
||||||
|
|
||||||
|
char *strip_line (char *line);
|
||||||
|
|
||||||
void runlevel_set (int pre, int now);
|
void runlevel_set (int pre, int now);
|
||||||
char *runlevel_string (int levels);
|
char *runlevel_string (int levels);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user