Skip to content

Comments

Add --grab-reboot option to trigger system reboot via keyboard shortcut#176

Merged
kdj0c merged 3 commits intokmscon:mainfrom
jtollet:feature/grab-reboot
Dec 17, 2025
Merged

Add --grab-reboot option to trigger system reboot via keyboard shortcut#176
kdj0c merged 3 commits intokmscon:mainfrom
jtollet:feature/grab-reboot

Conversation

@jtollet
Copy link
Contributor

@jtollet jtollet commented Dec 13, 2025

Summary

This PR adds a new --grab-reboot option that allows users to configure a keyboard shortcut to reboot the system directly from kmscon.

Features

  • Disabled by default: Users must explicitly configure a key combination
  • Direct system call: Uses reboot(RB_AUTOBOOT) for reliability
  • Configurable: Supports any key combination (e.g., <Ctrl><Alt>Delete)

Implementation

  • Added grab_reboot field to kmscon_conf_t configuration structure
  • Implemented seat_trigger_reboot() function using reboot(RB_AUTOBOOT)
  • Integrated into seat-level input event handling in seat_input_event()
  • Updated kmscon.1.xml.in and kmscon.conf.1.xml.in man pages

Usage

# Command line
kmscon --grab-reboot='<Ctrl><Alt>Delete'

# Configuration file
grab-reboot=<Ctrl><Alt>Delete

Modified Files

  • src/kmscon_conf.h - Configuration structure
  • src/kmscon_conf.c - Option definition and help text
  • src/kmscon_seat.c - Reboot trigger implementation
  • docs/man/kmscon.1.xml.in - Command-line option documentation
  • docs/man/kmscon.conf.1.xml.in - Configuration file documentation

@jtollet jtollet force-pushed the feature/grab-reboot branch from 373f8ea to 23f6c8e Compare December 13, 2025 17:37
This commit adds a new configurable keyboard shortcut option --grab-reboot
that allows users to reboot the system directly from kmscon.

Features:
- Disabled by default (user must explicitly configure a key combination)
- Uses direct reboot() system call for reliability
- Calls sync() before reboot to ensure data safety
- Independent of --session-control flag
- Fully configurable key combination (e.g., <Ctrl><Alt>Delete)
- Includes comprehensive documentation in man pages

Implementation details:
- Added grab_reboot field to kmscon_conf_t structure
- Added seat_trigger_reboot() function using reboot(RB_AUTOBOOT)
- Integrated into seat-level input event handling
- Updated both kmscon.1 and kmscon.conf.1 man pages

Usage example:
  kmscon --grab-reboot='<Ctrl><Alt>Delete'
@jtollet jtollet force-pushed the feature/grab-reboot branch from 23f6c8e to e0d135a Compare December 14, 2025 07:16
@kdj0c
Copy link
Contributor

kdj0c commented Dec 14, 2025

I'm a bit skeptical about this feature, but the code looks good, and it doesn't introduce complexity, so if no other comments I will merge it soon.

@jtollet
Copy link
Contributor Author

jtollet commented Dec 14, 2025 via email

@jtollet
Copy link
Contributor Author

jtollet commented Dec 14, 2025 via email

@kdj0c kdj0c merged commit 9f9a8ec into kmscon:main Dec 17, 2025
2 checks passed
@kdj0c kdj0c mentioned this pull request Jan 2, 2026
@satmandu
Copy link
Contributor

satmandu commented Jan 7, 2026

Thanks for this! I was just complaining to myself about ctrl-alt-del not being capable of rebooting my machine this morning.

@jtollet
Copy link
Contributor Author

jtollet commented Jan 7, 2026

@satmandu that quite common... And that's why linux vt supports it too. TY !

@Karlson2k
Copy link

Cool!
I was missing this really useful feature.

@Karlson2k
Copy link

While the feature is very useful, this implementation is quite dangerous.
With this implementation, a syscall (via a libc wrapper) is called to perform the reboot directly.
In contrast, when Ctrl-Alt-Del is pressed in the Linux console, SIGINT is sent to PID 1, and then the init process performs a clean reboot.
I think people who are using this feature are expecting the same behaviour as with the standard Linux console, and they can be surprised by data loss or a damaged filesystem due to an unclean shutdown.

I suggest either replacing this hard reboot with a proper SIGINT to PID 1, or at least making this configurable.
In the meantime, a BIG FAT warning could be added to the configuration example to avoid unpleasant surprises for users.

jtollet added a commit to jtollet/kmscon that referenced this pull request Jan 28, 2026
Following Karlson2k's feedback on PR kmscon#176, this commit adds clear warnings
about the dangers of "hard" mode (immediate reboot without proper shutdown)
which can cause data loss and filesystem corruption.

The documentation now explicitly states that:
- "soft" mode (default) sends SIGINT to PID 1 for a clean reboot,
  matching the standard Linux console Ctrl-Alt-Del behavior
- "hard" mode performs an immediate reboot via reboot(RB_AUTOBOOT)
  with sync() but without proper shutdown sequence

Changes:
- Updated man pages (kmscon.1 and kmscon.conf.1) with detailed warnings
- Updated kmscon.conf.example with prominent DATA LOSS warning
- Clarified that soft mode matches Linux console behavior users expect

Tested on real hardware with both modes:
- soft mode: clean shutdown via SIGINT to PID 1 ✓
- hard mode: immediate reboot via RB_AUTOBOOT ✓
jtollet added a commit to jtollet/kmscon that referenced this pull request Jan 28, 2026
Following Karlson2k's feedback on PR kmscon#176, this commit adds clear warnings
about the dangers of "hard" mode (immediate reboot without proper shutdown)
which can cause data loss and filesystem corruption.

The documentation now explicitly states that:
- "soft" mode (default) sends SIGINT to PID 1 for a clean reboot,
  matching the standard Linux console Ctrl-Alt-Del behavior
- "hard" mode performs an immediate reboot via reboot(RB_AUTOBOOT)
  with sync() but without proper shutdown sequence

Changes:
- Updated man pages (kmscon.1 and kmscon.conf.1) with detailed warnings
- Updated kmscon.conf.example with prominent DATA LOSS warning
- Clarified that soft mode matches Linux console behavior users expect

Tested on real hardware with both modes:
- soft mode: clean shutdown via SIGINT to PID 1 ✓
- hard mode: immediate reboot via RB_AUTOBOOT ✓
@jtollet
Copy link
Contributor Author

jtollet commented Jan 28, 2026

@Karlson2k Thank you for the excellent feedback!

You're absolutely right about the concerns with hard reboot. I've addressed all your suggestions in PR #260:

What was implemented:

  • SIGINT to PID 1 (soft mode) is now the default behavior, matching the standard Linux console Ctrl-Alt-Del
  • Hard mode is optional via --grab-reboot-mode=hard
  • BIG FAT warnings added to all documentation (man pages and config example) about data loss and filesystem corruption risks with hard mode
  • Clear documentation that soft mode matches what users expect from the Linux console

Testing:
Both modes have been tested on real hardware:

  • ✅ Soft mode: clean shutdown via SIGINT to PID 1 (default)
  • ✅ Hard mode: sync() + immediate reboot via RB_AUTOBOOT (optional, with warnings)

The implementation follows your recommendation to make this configurable while defaulting to the safe behavior users expect.

See PR #260 for the documentation updates: #260

@jtollet
Copy link
Contributor Author

jtollet commented Jan 28, 2026

@Karlson2k Thank you for the excellent feedback!

You're absolutely right about the concerns with hard reboot. I've addressed all your suggestions in PR #260:

What was implemented:

  • SIGINT to PID 1 (soft mode) is now the default behavior, matching the standard Linux console Ctrl-Alt-Del
  • Hard mode is optional via --grab-reboot-mode=hard
  • BIG FAT warnings added to all documentation (man pages and config example) about data loss and filesystem corruption risks with hard mode
  • Clear documentation that soft mode matches what users expect from the Linux console

About hard mode:
Even in hard mode, sync() is called before reboot(RB_AUTOBOOT) to flush disk buffers. However, this doesn't prevent potential data loss since the system doesn't perform proper shutdown of services, unmounting filesystems, etc. This is why we added prominent warnings.

Testing:
Both modes have been tested on real hardware:

  • ✅ Soft mode: clean shutdown via SIGINT to PID 1 (default)
  • ✅ Hard mode: sync() + immediate reboot via RB_AUTOBOOT (optional, with warnings)

The implementation follows your recommendation to make this configurable while defaulting to the safe behavior users expect.

See PR #260 for the documentation updates: #260

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants