From 3f6ac6524153822bf5753e0519fb7085c318553f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 28 Dec 2025 15:06:43 +0000 Subject: [PATCH] Address code review feedback: fix C/C++ typo, remove unused constant, add cleanup traps Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com> --- README.md | 2 +- scripts/create_image.sh | 36 +++++++++++++++++++++++++++++++----- src/init.c | 2 -- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 9d797b5..f5fe0a4 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ A minimal Linux distribution designed for simplicity and portability. SparkOS fe - **Minimal footprint**: Barebones Linux system with bash shell - **Portable**: dd-able disk image for USB flash drives -- **Custom init**: Lightweight C++ init system +- **Custom init**: Lightweight C init system - **Future-ready**: Designed to support Qt6/QML GUI and Wayland - **Root elevation**: Uses sudo for privilege management diff --git a/scripts/create_image.sh b/scripts/create_image.sh index 6938487..c4f744d 100755 --- a/scripts/create_image.sh +++ b/scripts/create_image.sh @@ -10,6 +10,37 @@ IMAGE_FILE="$PROJECT_ROOT/sparkos.img" IMAGE_SIZE="512M" MOUNT_POINT="/tmp/sparkos_mount" ROOTFS_DIR="$PROJECT_ROOT/rootfs" +LOOP_DEV="" + +# Cleanup function +cleanup() { + local exit_code=$? + echo "Cleaning up..." + + # Unmount if mounted + if mountpoint -q "$MOUNT_POINT" 2>/dev/null; then + umount "$MOUNT_POINT" 2>/dev/null || true + fi + + # Remove mount point + if [ -d "$MOUNT_POINT" ]; then + rmdir "$MOUNT_POINT" 2>/dev/null || true + fi + + # Detach loop device + if [ -n "$LOOP_DEV" ] && losetup "$LOOP_DEV" &>/dev/null; then + losetup -d "$LOOP_DEV" 2>/dev/null || true + fi + + if [ $exit_code -ne 0 ]; then + echo "ERROR: Image creation failed" + fi + + exit $exit_code +} + +# Set trap for cleanup on exit, interrupt, or error +trap cleanup EXIT INT TERM echo "SparkOS Image Builder" echo "=====================" @@ -91,11 +122,6 @@ dd if=/usr/lib/syslinux/mbr/mbr.bin of="$LOOP_DEV" bs=440 count=1 conv=notrunc 2 dd if=/usr/share/syslinux/mbr.bin of="$LOOP_DEV" bs=440 count=1 conv=notrunc 2>/dev/null || \ echo "WARNING: Could not install MBR, you may need to do this manually" -echo "Cleaning up..." -umount "$MOUNT_POINT" -rmdir "$MOUNT_POINT" -losetup -d "$LOOP_DEV" - echo "" echo "SUCCESS! Bootable image created: $IMAGE_FILE" echo "" diff --git a/src/init.c b/src/init.c index cdfeaeb..503d199 100644 --- a/src/init.c +++ b/src/init.c @@ -12,8 +12,6 @@ #include #include -#define INIT_PATH "/sbin/init" - static void signal_handler(int sig) { if (sig == SIGCHLD) { // Reap zombie processes