diff mbox

Input: Adding graceful shutdown to sysrq key reset

Message ID 1365169112-7999-1-git-send-email-mathieu.poirier@linaro.org (mailing list archive)
State New, archived
Headers show

Commit Message

Mathieu Poirier April 5, 2013, 1:38 p.m. UTC
From: "Mathieu J. Poirier" <mathieu.poirier@linaro.org>

Attempt to reboot the system gracefully when a key combo
is detected.  The system is force to go down if the first
attempt failed and the key combo is pressed a second time.

Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
---
 drivers/tty/sysrq.c |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Dmitry Torokhov April 15, 2013, 8:45 p.m. UTC | #1
Hi Mathieu,

On Fri, Apr 05, 2013 at 07:38:32AM -0600, mathieu.poirier@linaro.org wrote:
> From: "Mathieu J. Poirier" <mathieu.poirier@linaro.org>
> 
> Attempt to reboot the system gracefully when a key combo
> is detected.  The system is force to go down if the first
> attempt failed and the key combo is pressed a second time.
> 

If system can gracefully shutdown can;t we request it through normal
means?

Thanks.
Mathieu Poirier April 16, 2013, 2:45 p.m. UTC | #2
On 13-04-15 02:45 PM, Dmitry Torokhov wrote:
> Hi Mathieu,
> 
> On Fri, Apr 05, 2013 at 07:38:32AM -0600, mathieu.poirier@linaro.org wrote:
>> From: "Mathieu J. Poirier" <mathieu.poirier@linaro.org>
>>
>> Attempt to reboot the system gracefully when a key combo
>> is detected.  The system is force to go down if the first
>> attempt failed and the key combo is pressed a second time.
>>
> 
> If system can gracefully shutdown can;t we request it through normal
> means?
> 
> Thanks.
> 

Can you provide more details on how you'd like to see this done please ?
 Since 'kernel_restart' is found in 'linux/reboot.h' I was under the
impression that it is fairly mainstream.

Thanks,
Mathieu.
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mathieu Poirier April 23, 2013, 11:50 p.m. UTC | #3
On 13-04-16 08:45 AM, Mathieu Poirier wrote:
> On 13-04-15 02:45 PM, Dmitry Torokhov wrote:
>> Hi Mathieu,
>>
>> On Fri, Apr 05, 2013 at 07:38:32AM -0600, mathieu.poirier@linaro.org wrote:
>>> From: "Mathieu J. Poirier" <mathieu.poirier@linaro.org>
>>>
>>> Attempt to reboot the system gracefully when a key combo
>>> is detected.  The system is force to go down if the first
>>> attempt failed and the key combo is pressed a second time.
>>>
>>
>> If system can gracefully shutdown can;t we request it through normal
>> means?
>>
>> Thanks.
>>
> 
> Can you provide more details on how you'd like to see this done please ?
>  Since 'kernel_restart' is found in 'linux/reboot.h' I was under the
> impression that it is fairly mainstream.
> 
> Thanks,
> Mathieu.
> 

I haven't hard back from my last question so I'll try to interpret your
original answer differently.

The proposed functionality is a last effort at rebooting the system when
the UI is hung.  In such case the rest of the system could still be
alive and as such should be given a chance to reboot more gracefully
than when using emergency_reset().

Hope this helps clarifying my position.  I would be more than happy to
re-work the commit message if need be.  Please consider getting back to me.

Mathieu.
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Dmitry Torokhov April 24, 2013, 12:42 a.m. UTC | #4
On Tue, Apr 23, 2013 at 05:50:32PM -0600, Mathieu Poirier wrote:
> On 13-04-16 08:45 AM, Mathieu Poirier wrote:
> > On 13-04-15 02:45 PM, Dmitry Torokhov wrote:
> >> Hi Mathieu,
> >>
> >> On Fri, Apr 05, 2013 at 07:38:32AM -0600, mathieu.poirier@linaro.org wrote:
> >>> From: "Mathieu J. Poirier" <mathieu.poirier@linaro.org>
> >>>
> >>> Attempt to reboot the system gracefully when a key combo
> >>> is detected.  The system is force to go down if the first
> >>> attempt failed and the key combo is pressed a second time.
> >>>
> >>
> >> If system can gracefully shutdown can;t we request it through normal
> >> means?
> >>
> >> Thanks.
> >>
> > 
> > Can you provide more details on how you'd like to see this done please ?
> >  Since 'kernel_restart' is found in 'linux/reboot.h' I was under the
> > impression that it is fairly mainstream.
> > 
> > Thanks,
> > Mathieu.
> > 
> 
> I haven't hard back from my last question so I'll try to interpret your
> original answer differently.
> 
> The proposed functionality is a last effort at rebooting the system when
> the UI is hung.  In such case the rest of the system could still be
> alive and as such should be given a chance to reboot more gracefully
> than when using emergency_reset().

OK, fair enough.
diff mbox

Patch

diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
index 766878a..bd852fc 100644
--- a/drivers/tty/sysrq.c
+++ b/drivers/tty/sysrq.c
@@ -43,6 +43,7 @@ 
 #include <linux/uaccess.h>
 #include <linux/moduleparam.h>
 #include <linux/jiffies.h>
+#include <linux/syscalls.h>
 
 #include <asm/ptrace.h>
 #include <asm/irq_regs.h>
@@ -584,6 +585,7 @@  struct sysrq_state {
 
 	/* reset sequence handling */
 	bool reset_canceled;
+	bool reset_requested;
 	unsigned long reset_keybit[BITS_TO_LONGS(KEY_CNT)];
 	int reset_seq_len;
 	int reset_seq_cnt;
@@ -624,11 +626,17 @@  static void sysrq_parse_reset_sequence(struct sysrq_state *state)
 
 static void sysrq_do_reset(unsigned long dummy)
 {
-	__handle_sysrq(sysrq_xlate[KEY_B], false);
+	sys_sync();
+	kernel_restart(NULL);
 }
 
 static void sysrq_handle_reset_request(struct sysrq_state *state)
 {
+	if (state->reset_requested)
+		__handle_sysrq(sysrq_xlate[KEY_B], false);
+
+	state->reset_requested = true;
+
 	if (sysrq_reset_downtime_ms)
 		mod_timer(&state->keyreset_timer,
 			jiffies + msecs_to_jiffies(sysrq_reset_downtime_ms));