From 26128dd78899552bcffe810c3f74684efbd2cf2b Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sat, 24 Apr 2021 19:44:59 +0200 Subject: [PATCH] plugins: skip plugin in rescue mode These plugins should not run in rescue mode, because the system may be in a very bad state and we do not want to make the situation any worse than it already is. Essentially, only services in rescue.conf should run in rescue mode. Signed-off-by: Joachim Wiberg --- plugins/alsa-utils.c | 10 ++++++++++ plugins/dbus.c | 5 +++++ plugins/hotplug.c | 5 +++++ plugins/procps.c | 8 ++++++++ plugins/rtc.c | 10 ++++++++++ plugins/urandom.c | 10 ++++++++++ plugins/x11-common.c | 5 +++++ 7 files changed, 53 insertions(+) diff --git a/plugins/alsa-utils.c b/plugins/alsa-utils.c index e2052a34..b4654371 100644 --- a/plugins/alsa-utils.c +++ b/plugins/alsa-utils.c @@ -30,6 +30,11 @@ static void save(void *arg) { + if (rescue) { + _d("Skipping %s plugin in rescue mode.", __FILE__); + return; + } + if (whichp(ALSACTL)) { _d("Saving sound settings ..."); run_interactive(ALSACTL " -g store", "Saving sound settings"); @@ -38,6 +43,11 @@ static void save(void *arg) static void restore(void *arg) { + if (rescue) { + _d("Skipping %s plugin in rescue mode.", __FILE__); + return; + } + if (whichp(ALSACTL)) { _d("Restoring sound settings ..."); run_interactive(ALSACTL " -g restore", "Restoring sound settings"); diff --git a/plugins/dbus.c b/plugins/dbus.c index aa231bfd..19dcc756 100644 --- a/plugins/dbus.c +++ b/plugins/dbus.c @@ -43,6 +43,11 @@ static void setup(void *arg) mode_t prev; char *cmd; + if (rescue) { + _d("Skipping %s plugin in rescue mode.", __FILE__); + return; + } + cmd = which(DAEMON); if (!cmd) { _d("Skipping plugin, %s is not installed.", DAEMON); diff --git a/plugins/hotplug.c b/plugins/hotplug.c index 35f3c7b9..11d15b35 100644 --- a/plugins/hotplug.c +++ b/plugins/hotplug.c @@ -34,6 +34,11 @@ static void setup(void *arg) char cmd[256]; char *path; + if (rescue) { + _d("Skipping %s plugin in rescue mode.", __FILE__); + return; + } + /* * Populate /dev and prepare for runtime events from kernel. * Prefer udev if mdev is also available on the system. diff --git a/plugins/procps.c b/plugins/procps.c index aba459ba..8f382200 100644 --- a/plugins/procps.c +++ b/plugins/procps.c @@ -23,6 +23,9 @@ #include #include + +#include "finit.h" +#include "helpers.h" #include "plugin.h" static void setup(void *arg) @@ -31,6 +34,11 @@ static void setup(void *arg) glob_t gl; char buf[160]; + if (rescue) { + _d("Skipping %s plugin in rescue mode.", __FILE__); + return; + } + 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); diff --git a/plugins/rtc.c b/plugins/rtc.c index b8252b31..b77f5839 100644 --- a/plugins/rtc.c +++ b/plugins/rtc.c @@ -84,6 +84,11 @@ static void rtc_save(void *arg) int fd, rc = 0; char tz[128]; + if (rescue) { + _d("Skipping %s plugin in rescue mode.", __FILE__); + return; + } + fd = rtc_open(); if (fd < 0) return; @@ -121,6 +126,11 @@ static void rtc_restore(void *arg) int fd, rc = 0; char tz[128]; + if (rescue) { + _d("Skipping %s plugin in rescue mode.", __FILE__); + return; + } + fd = rtc_open(); if (fd < 0) return; diff --git a/plugins/urandom.c b/plugins/urandom.c index fa179065..1a3adbf7 100644 --- a/plugins/urandom.c +++ b/plugins/urandom.c @@ -35,6 +35,11 @@ static void setup(void *arg) { #ifdef RANDOMSEED + if (rescue) { + _d("Skipping %s plugin in rescue mode.", __FILE__); + return; + } + if (!fexist(RANDOMSEED)) { int ret = 1; mode_t prev; @@ -71,6 +76,11 @@ static void save(void *arg) #ifdef RANDOMSEED mode_t prev; + if (rescue) { + _d("Skipping %s plugin in rescue mode.", __FILE__); + return; + } + prev = umask(077); print_desc("Saving random seed", NULL); diff --git a/plugins/x11-common.c b/plugins/x11-common.c index 5eb5be50..84025f9a 100644 --- a/plugins/x11-common.c +++ b/plugins/x11-common.c @@ -39,6 +39,11 @@ static void setup(void *arg) int fd; #endif + if (rescue) { + _d("Skipping %s plugin in rescue mode.", __FILE__); + return; + } + prev = umask(0); makedir("/var/run/console", 01777);