From cfc99c4e8b91ca791954218408f269c682cc9274 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Tue, 12 Apr 2022 21:38:16 +0200 Subject: [PATCH] Follow-up to ef9e9ec, run ifdown also in background, with --force Turns out that on Debian `ifdown -a` can block for quite a while at shutdown/reboot. So we'd like to use the --force option. However, the BusyBox ifdown tool doesn't support --force, only -f, which in turn the regular ifdown tool doesn't support. Regardless, we can allow network shutdown to run in the background like bring-up, at reboot we want to reboot quickly and don't care so much, and on runlevel change to single-user mode we can allow for some lagging behind in the background. Signed-off-by: Joachim Wiberg --- src/helpers.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/helpers.c b/src/helpers.c index 1fb28247..1fd80ca7 100644 --- a/src/helpers.c +++ b/src/helpers.c @@ -500,20 +500,25 @@ 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) { int rc = EX_OSERR; + const char *cmd; FILE *pp; setsid(); sig_unblock(); - pp = popen("ifup -a 2>&1", "r"); + if (updown) + cmd = "ifup -a 2>&1"; + else if (whichp("ifquery")) + /* Regular ifodwn supports --force but not -f */ + cmd = "ifdown -a --force 2>&1"; + else + /* Busybox ifdown support -f, but not --force */ + cmd = "ifdown -a -f 2>&1"; + + pp = popen(cmd, "r"); if (pp) { char buf[256]; @@ -526,7 +531,8 @@ void networking(int updown) _exit(rc); } cgroup_service("network", pid, NULL); - print(pid > 0 ? 0 : 1, "Bringing up network interfaces ..."); + print(pid > 0 ? 0 : 1, "%s network interfaces ...", + updown ? "Bringing up" : "Taking down"); goto done; }