From ef9e9ec786cac4135a2f8f299cf97b80f6b11d29 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sun, 27 Feb 2022 23:56:53 +0100 Subject: [PATCH] networking: log output from 'ifup -a', run 'ifdown -a' interactively We've been discussing, over the years, that we'd like to have an easier way to debug bringup with Finit. Network bringup is one such case where it's hard to debug if/what you've misspelled in /etc/network/interfaces Signed-off-by: Joachim Wiberg --- src/helpers.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/helpers.c b/src/helpers.c index 5f85ad75..716bd16e 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #ifdef _LIBITE_LITE # include @@ -40,6 +41,7 @@ #include "finit.h" #include "helpers.h" #include "private.h" +#include "sig.h" #include "util.h" #include "utmp-api.h" @@ -498,17 +500,35 @@ void networking(int updown) if (fexist("/etc/network/interfaces")) { pid_t pid; + if (!updown) { + run_interactive("ifdown -a", "Stopping networking"); + goto done; + } + pid = fork(); if (pid == 0) { - if (updown) - run("ifup -a"); - else - run("ifdown -a"); - _exit(0); + int rc = EX_OSERR; + FILE *pp; + + setsid(); + sig_unblock(); + + pp = popen("ifup -a 2>&1", "r"); + if (pp) { + char buf[256]; + + while (fgets(buf, sizeof(buf), pp)) + logit(LOG_NOTICE, "network: %s", buf); + + rc = pclose(pp); + } + + _exit(rc); } cgroup_service("network", pid, NULL); + print(pid > 0 ? 0 : 1, "Bringing up network interfaces ..."); - print(pid > 0 ? 0 : 1, "%s networking", updown ? "Starting" : "Stopping"); + goto done; } fallback: