From b9ee38b4f8a8e132187b400bff1626b96dbbfb55 Mon Sep 17 00:00:00 2001 From: Jeffrey Alan Scudder Date: Wed, 25 Mar 2026 18:26:37 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20proper=20poweroff/reboot=20=E2=80=94=20e?= =?UTF-8?q?xit=20codes=200/2,=20no=20SIGTERM=20to=20init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit poweroff: _exit(0) → init uses sysrq 'o' reboot: _exit(2) → init uses sysrq 'b' No more getpid()==1 checks or SIGTERM/SIGUSR2 to PID 1. Co-Authored-By: Claude Opus 4.6 (1M context) --- fedac/native/initramfs/init | 15 +++++++++++---- fedac/native/src/js-bindings.c | 22 +++++----------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/fedac/native/initramfs/init b/fedac/native/initramfs/init index 8471718660..ac31b691ce 100755 --- a/fedac/native/initramfs/init +++ b/fedac/native/initramfs/init @@ -113,17 +113,24 @@ while true; do /ac-native /piece.mjs EXIT_CODE=$? - # Clean exit (0) = shutdown requested + # Exit code 0 = power off, exit code 2 = reboot if [ "$EXIT_CODE" = "0" ]; then sync echo "[ac-init] Clean exit — powering off..." - # Sysrq power off (most reliable under initramfs) echo o > /proc/sysrq-trigger 2>/dev/null sleep 2 - # Busybox poweroff poweroff -f 2>/dev/null busybox poweroff -f 2>/dev/null - # If nothing worked, halt (do NOT reboot) + sleep 30 + break + fi + if [ "$EXIT_CODE" = "2" ]; then + sync + echo "[ac-init] Reboot requested..." + echo b > /proc/sysrq-trigger 2>/dev/null + sleep 2 + reboot -f 2>/dev/null + busybox reboot -f 2>/dev/null sleep 30 break fi diff --git a/fedac/native/src/js-bindings.c b/fedac/native/src/js-bindings.c index f54bfbb30d..1c6ef436a6 100644 --- a/fedac/native/src/js-bindings.c +++ b/fedac/native/src/js-bindings.c @@ -3317,13 +3317,8 @@ static JSValue js_reboot(JSContext *ctx, JSValueConst this_val, int argc, JSValu ac_log("[reboot] executing reboot syscall"); ac_log_flush(); - if (getpid() == 1) { - reboot(LINUX_REBOOT_CMD_RESTART); - } else { - // Under cage: tell PID 1 to reboot, then exit so cage closes - kill(1, SIGUSR2); // SIGUSR2 = reboot request - _exit(0); - } + // Exit with code 2 — init script sees this as reboot request + _exit(2); return JS_UNDEFINED; } @@ -3339,17 +3334,10 @@ static JSValue js_poweroff(JSContext *ctx, JSValueConst this_val, int argc, JSVa ac_log("[poweroff] pid=%d, syncing filesystems...\n", getpid()); ac_log_flush(); sync(); usleep(300000); sync(); - ac_log("[poweroff] executing power off...\n"); + ac_log("[poweroff] exiting with code 0 (init will power off)...\n"); ac_log_flush(); - if (getpid() == 1) { - int r = reboot(LINUX_REBOOT_CMD_POWER_OFF); - ac_log("[poweroff] reboot() returned %d errno=%d\n", r, errno); - } else { - // Under cage: tell PID 1 to power off, then exit so cage closes - ac_log("[poweroff] sending SIGTERM to PID 1\n"); - kill(1, SIGTERM); - _exit(0); - } + // Exit cleanly — init script sees exit code 0 and runs poweroff + _exit(0); return JS_UNDEFINED; } -- 2.51.2