]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
battery-check: allow to skip by passing systemd.battery-check=0 28355/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 11 Jul 2023 15:32:24 +0000 (00:32 +0900)
committerLuca Boccassi <bluca@debian.org>
Fri, 14 Jul 2023 14:56:29 +0000 (15:56 +0100)
NEWS
man/systemd-battery-check.service.xml
src/battery-check/battery-check.c
units/systemd-battery-check.service.in

diff --git a/NEWS b/NEWS
index 185126f64489dd577fbdafbbb7548ac71e7f6a90..c1770565e90f95dcb9b684d2c2fbfbaf5f293220 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -698,7 +698,8 @@ CHANGES WITH 254 in spe:
           charge level of the system. In case the charge level is very low the
           user is notified (graphically via Plymouth – if available – as well
           as in text form on the console), and the system is turned off after a
-          10s delay.
+          10s delay. The feature can be disabled by passing
+          systemd.battery-check=0 through the kernel command line.
 
         * The 'passwdqc' library is now supported as an alternative to the
           'pwquality' library and it can be selected at build time.
index 2d9005696eb7c1fceddcea6882df19f2e7f8dd26..6f1b0ea687e98ad4f5c20c94add63c3f39a9971e 100644 (file)
     </para>
   </refsect1>
 
+  <refsect1>
+    <title>Kernel Command Line</title>
+
+    <para>The following variables are understood:</para>
+
+    <variablelist class='kernel-commandline-options'>
+      <varlistentry>
+        <term><varname>systemd.battery-check=<replaceable>BOOL</replaceable></varname></term>
+
+        <listitem>
+          <para>Takes a boolean. If specified with false, <command>systemd-battery-check</command> command
+          will return immediately with exit status 0 without checking battery capacity and AC power
+          existence, and the service <filename>systemd-battery-check.service</filename> will succeed. This
+          may be useful when the command wrongly detects and reports battery capacity percentage or AC power
+          existence, or when you want to boot the system forcibly.</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsect1>
+
   <refsect1>
     <title>See Also</title>
     <para>
index ca13251ae09e56d790ee51d4184d1227324b5fb2..c3091d3474fb0b02d980ea52731fdb3ac52f5f00 100644 (file)
@@ -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");
index 61f4ae16e08c92b948be65fcdddd9dca9c902ce0..a6a0d26fde263a0683cce42e694e7838cf7c063e 100644 (file)
@@ -12,6 +12,7 @@ Description=Check battery level during early boot
 Documentation=man:systemd-battery-check.service(8)
 ConditionVirtualization=no
 ConditionDirectoryNotEmpty=/sys/class/power_supply/
+ConditionKernelCommandLine=!systemd.battery-check=0
 AssertPathExists=/etc/initrd-release
 DefaultDependencies=no
 After=plymouth-start.service