summaryrefslogtreecommitdiffstats
path: root/src/battery-check
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-07-11 17:32:24 +0200
committerLuca Boccassi <bluca@debian.org>2023-07-14 16:56:29 +0200
commit7cfef4bb48c3c8be42df76cf877de69f0d6bc93e (patch)
tree03e3f239aaae46c9f636b83a7eaa19ab1208d3cf /src/battery-check
parentproc-cmdline: re-implement proc_cmdline_filter_pid1_args() without using geto... (diff)
downloadsystemd-7cfef4bb48c3c8be42df76cf877de69f0d6bc93e.tar.xz
systemd-7cfef4bb48c3c8be42df76cf877de69f0d6bc93e.zip
battery-check: allow to skip by passing systemd.battery-check=0
Diffstat (limited to 'src/battery-check')
-rw-r--r--src/battery-check/battery-check.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/battery-check/battery-check.c b/src/battery-check/battery-check.c
index ca13251ae0..c3091d3474 100644
--- a/src/battery-check/battery-check.c
+++ b/src/battery-check/battery-check.c
@@ -14,7 +14,9 @@
#include "io-util.h"
#include "log.h"
#include "main-func.h"
+#include "parse-util.h"
#include "pretty-print.h"
+#include "proc-cmdline.h"
#include "socket-util.h"
#include "terminal-util.h"
#include "time-util.h"
@@ -24,6 +26,8 @@
#define BATTERY_RESTORED_MESSAGE \
"A.C. power restored, continuing."
+static bool arg_doit = true;
+
static int help(void) {
_cleanup_free_ char *link = NULL;
int r;
@@ -84,6 +88,23 @@ static int plymouth_send_message(const char *mode, const char *message) {
return 0;
}
+static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
+ int r;
+
+ assert(key);
+
+ if (streq(key, "systemd.battery-check")) {
+
+ r = value ? parse_boolean(value) : 1;
+ if (r < 0)
+ log_warning_errno(r, "Failed to parse %s switch, ignoring: %s", key, value);
+ else
+ arg_doit = r;
+ }
+
+ return 0;
+}
+
static int parse_argv(int argc, char * argv[]) {
enum {
@@ -132,10 +153,19 @@ static int run(int argc, char *argv[]) {
log_setup();
+ r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, PROC_CMDLINE_STRIP_RD_PREFIX);
+ if (r < 0)
+ log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m");
+
r = parse_argv(argc, argv);
if (r <= 0)
return r;
+ if (!arg_doit) {
+ log_info("Checking battery status and AC power existence is disabled by the kernel command line, skipping execution.");
+ return 0;
+ }
+
r = battery_is_discharging_and_low();
if (r < 0) {
log_warning_errno(r, "Failed to check battery status, ignoring: %m");