diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/backlight/backlight.c | 3 | ||||
-rw-r--r-- | src/rfkill/rfkill.c | 3 | ||||
-rw-r--r-- | src/shared/util.c | 23 | ||||
-rw-r--r-- | src/shared/util.h | 2 |
4 files changed, 29 insertions, 2 deletions
diff --git a/src/backlight/backlight.c b/src/backlight/backlight.c index e8cdad61ed..6c00b00d82 100644 --- a/src/backlight/backlight.c +++ b/src/backlight/backlight.c @@ -24,6 +24,7 @@ #include "fileio.h" #include "libudev.h" #include "udev-util.h" +#include "util.h" static struct udev_device *find_pci_or_platform_parent(struct udev_device *device) { struct udev_device *parent; @@ -290,7 +291,7 @@ int main(int argc, char *argv[]) { * device probing should be complete), so that the validity * check at boot time doesn't have to be reliable. */ - if (streq(argv[1], "load")) { + if (streq(argv[1], "load") && restore_state()) { _cleanup_free_ char *value = NULL; if (!validate_device(udev, device)) diff --git a/src/rfkill/rfkill.c b/src/rfkill/rfkill.c index 812cf408fb..b814e5c5fc 100644 --- a/src/rfkill/rfkill.c +++ b/src/rfkill/rfkill.c @@ -24,6 +24,7 @@ #include "fileio.h" #include "libudev.h" #include "udev-util.h" +#include "utils.h" int main(int argc, char *argv[]) { _cleanup_udev_unref_ struct udev *udev = NULL; @@ -95,7 +96,7 @@ int main(int argc, char *argv[]) { return EXIT_FAILURE; } - if (streq(argv[1], "load")) { + if (streq(argv[1], "load") && restore_state()) { _cleanup_free_ char *value = NULL; r = read_one_line_file(saved, &value); diff --git a/src/shared/util.c b/src/shared/util.c index 1822770304..d086fac7f8 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -76,6 +76,7 @@ #include "device-nodes.h" #include "utf8.h" #include "gunicode.h" +#include "virt.h" int saved_argc = 0; char **saved_argv = NULL; @@ -5990,3 +5991,25 @@ int split_pair(const char *s, const char *sep, char **l, char **r) { return 0; } + +bool restore_state(void) { + _cleanup_free_ char *line; + char *w, *state; + int r; + size_t l; + + if (detect_container(NULL) > 0) + return true; + + r = read_one_line_file("/proc/cmdline", &line); + if (r < 0) { + log_warning("Failed to read /proc/cmdline, ignoring: %s", strerror(-r)); + return 0; + } + + FOREACH_WORD_QUOTED(w, l, line, state) + if (strneq(w, "systemd.restore_state=0", l)) + return false; + + return true; +} diff --git a/src/shared/util.h b/src/shared/util.h index 63cb4ac636..dc35b4d980 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -765,6 +765,8 @@ void parse_user_at_host(char *arg, char **user, char **host); int split_pair(const char *s, const char *sep, char **l, char **r); +bool restore_state(void); + /** * Normal qsort requires base to be nonnull. Here were require * that only if nmemb > 0. |