Skip to content

feat: react to guest shutdown events (graceful shutdown, guest side) - #15

Open
Anamika1608 wants to merge 6 commits into
nubificus:mainfrom
Anamika1608:graceful-shutdown-guest
Open

Anamika1608 wants to merge 6 commits into
nubificus:mainfrom
Anamika1608:graceful-shutdown-guest

Conversation

@Anamika1608

@Anamika1608 Anamika1608 commented Aug 10, 2026 •

Copy link
Copy Markdown

What this does

How it works

  • Opens the power-button input device (/dev/input/event* that reports KEY_POWER). QEMU and Cloud Hypervisor deliver a power-button press this way.
  • Sets up a signalfd for SIGCHLD, SIGINT and SIGTERM, and calls reboot(CAD_OFF) so a guest Ctrl+Alt+Del (Firecracker on x86) arrives as SIGINT to PID 1.
  • Runs a poll loop that reaps children and watches for a shutdown event.
  • On a shutdown event, sends SIGTERM to the app's process group once, then keeps waiting for the app to exit.
  • After the app exits, runs the existing sync, unmount and reboot steps.
  • Creates /dev and mounts devtmpfs at start, because the guest initrd has none.

Design choices

  • No internal timeout. The app gets SIGTERM and time to exit. The container manager's SIGKILL is the outer bound. This matches the host side.
  • The exit path stays reboot(RESTART). On QEMU (-no-reboot) this is a clean stop.
  • If no power-button device exists, urunit still runs; the SIGINT path keeps working.

Status

  • Not yet validated end to end. The guest kernel in the current test images does not build the input and button drivers (CONFIG_INPUT_EVDEV, CONFIG_GPIO_PL061, CONFIG_KEYBOARD_GPIO), so the power button never reaches userspace. A guest kernel with these options is needed to test the full path.
  • Firecracker on x86 (Ctrl+Alt+Del) is code only, since there is no x86 host here.

Testing

  • Builds clean as static and static_debug under the strict flags (-Werror -Wextra -Wall -pedantic-errors).
  • Reviewed for signal, fd and reaping correctness.
  • e2e testing for the qemu vmm

Signed-off-by: Anamika Aggarwal <anamikaagg18@gmail.com>
Signed-off-by: Anamika Aggarwal <anamikaagg18@gmail.com>
Signed-off-by: Anamika Aggarwal <anamikaagg18@gmail.com>
Signed-off-by: Anamika Aggarwal <anamikaagg18@gmail.com>
Signed-off-by: Anamika Aggarwal <anamikaagg18@gmail.com>
Signed-off-by: Anamika Aggarwal <anamikaagg18@gmail.com>
@Anamika1608
Anamika1608 marked this pull request as ready for review August 11, 2026 19:10
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.

1 participant