All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josh Triplett <josh@joshtriplett.org>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
	Len Brown <lenb@kernel.org>, Jonathan Corbet <corbet@lwn.net>,
	Arjan van de Ven <arjan@linux.intel.com>
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-acpi@vger.kernel.org
Subject: [PATCH] acpi: button: Provide option for power button to directly signal init
Date: Fri, 10 Jan 2020 18:21:45 -0800	[thread overview]
Message-ID: <20200111022145.GA166025@localhost> (raw)

Virtual machines and containers often use an ACPI power button event to
tell the machine to shut down gracefully.

Provide an optional, extremely lightweight way to handle this event by
signaling init directly, rather than running a separate daemon (such as
acpid or systemd-logind) that adds to startup time and VM image
complexity.

By default, the power button will continue to notify userspace through
the input layer. With the button.power_signal parameter set, the
power button will instead send the configured signal to init. (For
instance, sending SIGINT will make the power button simulate
ctrl-alt-del.)

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
---
 Documentation/admin-guide/kernel-parameters.txt |  6 ++++++
 drivers/acpi/button.c                           | 11 +++++++++++
 2 files changed, 17 insertions(+)

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index ade4e6ec23e0..bbb598e148f4 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -450,6 +450,12 @@
 			firmware feature for flushing multiple hpte entries
 			at a time.
 
+	button.power_signal=
+			[ACPI] When the power button is pressed, send this
+			signal number to the init process. If set to 0
+			(default), do not send a signal.
+			Format: integer
+
 	c101=		[NET] Moxa C101 synchronous serial card
 
 	cachesize=	[BUGS=X86-32] Override level 2 CPU cache size detection.
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index b758b45737f5..923259f132d6 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -14,6 +14,7 @@
 #include <linux/init.h>
 #include <linux/types.h>
 #include <linux/proc_fs.h>
+#include <linux/sched/signal.h>
 #include <linux/seq_file.h>
 #include <linux/input.h>
 #include <linux/slab.h>
@@ -167,6 +168,10 @@ static unsigned long lid_report_interval __read_mostly = 500;
 module_param(lid_report_interval, ulong, 0644);
 MODULE_PARM_DESC(lid_report_interval, "Interval (ms) between lid key events");
 
+static int power_signal __read_mostly = 0;
+module_param(power_signal, int, 0644);
+MODULE_PARM_DESC(power_signal, "Power button sends this signal to init");
+
 /* --------------------------------------------------------------------------
                               FS Interface (/proc)
    -------------------------------------------------------------------------- */
@@ -426,6 +431,12 @@ static void acpi_button_notify(struct acpi_device *device, u32 event)
 			if (button->suspended)
 				break;
 
+			if (power_signal
+			    && button->type == ACPI_BUTTON_TYPE_POWER) {
+				kill_cad_pid(power_signal, 1);
+				break;
+			}
+
 			keycode = test_bit(KEY_SLEEP, input->keybit) ?
 						KEY_SLEEP : KEY_POWER;
 			input_report_key(input, keycode, 1);
-- 
2.25.0.rc2


             reply	other threads:[~2020-01-11  2:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-11  2:21 Josh Triplett [this message]
2020-01-30 21:07 ` [PATCH] acpi: button: Provide option for power button to directly signal init Rafael J. Wysocki
2020-02-05  0:24   ` Josh Triplett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200111022145.GA166025@localhost \
    --to=josh@joshtriplett.org \
    --cc=arjan@linux.intel.com \
    --cc=corbet@lwn.net \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.