From 885056a6c9d8cf4872647aef672762ac248a8ae8 Mon Sep 17 00:00:00 2001 From: crazy Date: Tue, 21 Mar 2017 12:12:06 +0100 Subject: [PATCH] networking(): check first ifup exists Check first ifup exists before using it since this is really something only exits on some distros an in different ways. Debian/Ubunu has an package for this while others have it in the initscripts package(s) , meaning the file can be around even without the prog. Signed-off-by: crazy --- src/finit.c | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/src/finit.c b/src/finit.c index 66be9f82..c9b9abf6 100644 --- a/src/finit.c +++ b/src/finit.c @@ -155,36 +155,39 @@ static void networking(void) return; } - /* Debian/Ubuntu/Busybox interfaces file */ - fp = fopen("/etc/network/interfaces", "r"); - if (fp) { - int i = 0; - char buf[160]; + /* Debian/Ubuntu/Busybox/RH/Suse */ + if (fexist("/sbin/ifup")) { + /* interfaces file */ + fp = fopen("/etc/network/interfaces", "r"); + if (fp) { + int i = 0; + char buf[160]; - /* Bring up all 'auto' interfaces */ - while (fgets(buf, sizeof(buf), fp)) { - char cmd[80]; - char *line, *ifname = NULL; + /* Bring up all 'auto' interfaces */ + while (fgets(buf, sizeof(buf), fp)) { + char cmd[80]; + char *line, *ifname = NULL; - chomp(buf); - line = strip_line(buf); + chomp(buf); + line = strip_line(buf); - if (!strncmp(line, "auto", 4)) - ifname = &line[5]; - if (!strncmp(line, "allow-hotplug", 13)) - ifname = &line[14]; + if (!strncmp(line, "auto", 4)) + ifname = &line[5]; + if (!strncmp(line, "allow-hotplug", 13)) + ifname = &line[14]; - if (!ifname) - continue; + if (!ifname) + continue; - snprintf(cmd, 80, "/sbin/ifup %s", ifname); - run_interactive(cmd, "Bringing up interface %s", ifname); - i++; + snprintf(cmd, 80, "/sbin/ifup %s", ifname); + run_interactive(cmd, "Bringing up interface %s", ifname); + i++; + } + + fclose(fp); + if (i) + return; } - - fclose(fp); - if (i) - return; } /* Fall back to bring up at least loopback */