Skip to content

Conversation

@lyjjl
Copy link
Contributor

@lyjjl lyjjl commented Dec 28, 2025

优化进程退出逻辑,支持在退出时交互式选择是否保留 QQ 进程(有个BUG解决的很粗暴)
增强错误处理,增加 sudo 权限校验

Summary by Sourcery

改进 Linux 启动脚本在进程生命周期管理和交互式关闭行为方面的健壮性。

新功能:

  • 增加交互式清理处理逻辑:在退出时询问是否终止与 QQ 相关的进程,并基于超时设置默认行为。
  • 在受支持的发行版上运行软件包安装流程前,引入 sudo 权限校验。

增强:

  • 优化端口选择、显示模式选择和环境检测的日志与提示信息,为用户提供更清晰的指引。
  • 确保对 QQ/LLBot 进程进行跟踪并管理其进程组,使 Ctrl+C 和各类信号能产生可预测的行为,包括可选的强制终止清理以及 X11 授权回滚。
  • 统一并强化针对 Arch 和 Debian 的依赖安装逻辑,在安装 QQ 和所需工具时提供更完善的错误处理。
Original summary in English

Summary by Sourcery

Improve the Linux startup script’s robustness around process lifecycle management and interactive shutdown behavior.

New Features:

  • Add interactive cleanup handling that prompts whether to terminate QQ-related processes on exit, with timeout-based default behavior.
  • Introduce sudo permission validation before running package installation flows on supported distributions.

Enhancements:

  • Refine port selection, display mode selection, and environment detection logs and prompts for clearer user guidance.
  • Ensure QQ/LLBot processes are tracked and their process group is managed so Ctrl+C and signals result in deterministic behavior, including optional forced-kill cleanup and X11 authorization rollback.
  • Unify and harden dependency installation logic for Arch and Debian, including better error handling when installing QQ and required tools.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 28, 2025

审阅者指南

重构 Linux 启动脚本,以添加健壮的基于信号的清理机制(可选保留 QQ 相关进程)、显式的 sudo 校验、更健壮的依赖/QQ 安装流程,同时改进模式选择的交互体验,以及对显示/X11 的处理。

新的信号驱动清理流程与 QQ 保留流程的时序图

sequenceDiagram
    actor User
    participant ShellScript
    participant PMHQProcess
    participant QQProcess
    participant XServer

    User->>ShellScript: run start-linux.sh
    ShellScript->>ShellScript: trap cleanup on SIGINT SIGTERM EXIT
    ShellScript->>PMHQProcess: start pmhq with sub_cmd (&)
    ShellScript->>ShellScript: store PMHQ_PID
    ShellScript->>ShellScript: wait PMHQ_PID

    User-->>ShellScript: press Ctrl+C (SIGINT)
    ShellScript->>ShellScript: invoke cleanup
    alt cleanup not already running
        ShellScript->>ShellScript: set CLEANING=1
        ShellScript->>PMHQProcess: SIGSTOP process group (-PMHQ_PID)
        ShellScript->>User: prompt on /dev/tty
        User-->>ShellScript: choice Y/n or timeout
        alt user keeps QQ (choice n/N)
            ShellScript->>PMHQProcess: SIGCONT process group
            ShellScript->>User: log QQ and related processes detached
            ShellScript->>ShellScript: exit 0
        else user closes QQ (default or Y)
            ShellScript->>PMHQProcess: SIGCONT process group
            ShellScript->>PMHQProcess: SIGTERM process group
            ShellScript->>QQProcess: pkill -15 QQ binaries
            loop wait for clean exit
                ShellScript->>PMHQProcess: poll with kill -0
                ShellScript->>QQProcess: pgrep QQ binaries
            end
            alt processes still remain
                ShellScript->>PMHQProcess: SIGKILL process group
                ShellScript->>QQProcess: pkill -9 QQ binaries
            end
            alt non-arch and not using xvfb
                ShellScript->>XServer: xhost -local:username
            end
            ShellScript->>User: log cleanup complete
            ShellScript->>ShellScript: exit 0
        end
    else cleanup already running
        ShellScript->>ShellScript: return immediately
    end
Loading

start-linux.sh 中针对发行版安装和 sudo 校验的新流程图

flowchart TD
    Start[Start script] --> DetectDistro[Detect distro via pacman/apt]
    DetectDistro -->|pacman| SetArch[Set DISTRO=arch]
    DetectDistro -->|apt| SetDebian[Set DISTRO=debian]
    DetectDistro -->|other| ErrUnsupported[error 当前只支持 apt 或 pacman 包管理器]

    SetArch --> InstallArch
    SetDebian --> InstallDebian

    subgraph ArchInstall[install_arch]
        InstallArch --> CheckSudoArch[check_sudo sudo -v]
        CheckSudoArch -->|fail| ErrSudoArch[error Sudo 验证失败]
        CheckSudoArch -->|ok| PacmanDeps[pacman install base deps]
        PacmanDeps --> QQCheckArch{QQ binary exists?}
        QQCheckArch -->|yes| ArchDone[return]
        QQCheckArch -->|no| AskAUR[confirm install QQ via AUR]
        AskAUR -->|no| ArchDone
        AskAUR -->|yes| YayCheck{yay installed?}
        YayCheck -->|yes| YayInstallQQ[yay -S qq-nt etc]
        YayInstallQQ --> ArchDone
        YayCheck -->|no| TryPacmanYay[pacman -S yay]
        TryPacmanYay -->|success| YayInstallQQ
        TryPacmanYay -->|fail| BuildYay[git clone yay; makepkg]
        BuildYay -->|fail| ErrYayBuild[error yay 编译失败]
        BuildYay -->|success| YayInstallQQ
    end

    subgraph DebianInstall[install_debian]
        InstallDebian --> CheckSudoDebian[check_sudo sudo -v]
        CheckSudoDebian -->|fail| ErrSudoDebian[error Sudo 验证失败]
        CheckSudoDebian -->|ok| QQCheckDeb{QQ binary exists?}
        QQCheckDeb -->|yes| CheckTools[check ffmpeg/xvfb]
        QQCheckDeb -->|no| AskQQDeb[confirm install QQ]
        AskQQDeb -->|no| CheckTools
        AskQQDeb -->|yes| AptUpdate[apt-get update; install wget]
        AptUpdate -->|fail| ErrAptUpdate[error apt update 或 wget 安装失败]
        AptUpdate -->|ok| DownloadDeb[wget QQ deb]
        DownloadDeb -->|fail| ErrQQDownload[error QQ 安装包下载失败]
        DownloadDeb -->|ok| DetectLib[choose libasound2 or libasound2t64]
        DetectLib --> InstallQQDeb[apt install QQ deb and deps]
        InstallQQDeb -->|fail| ErrQQDeps[error QQ 依赖安装失败]
        InstallQQDeb -->|ok| RemoveDeb[rm deb]
        RemoveDeb --> CheckTools
        CheckTools --> MissingPkgs{any ffmpeg/xvfb missing?}
        MissingPkgs -->|no| DebianDone[return]
        MissingPkgs -->|yes| AptInstallTools[apt-get install missing]
        AptInstallTools -->|fail| ErrTools[error 工具安装失败]
        AptInstallTools -->|ok| DebianDone
    end

    ArchDone --> PostInstall
    DebianDone --> PostInstall

    PostInstall[chmod and chown llbot; continue to mode selection] --> End[End install phase]
Loading

文件级变更

Change Details Files
添加集中式清理和信号处理,以优雅地处理 Ctrl+C/退出,并可选地保留 QQ 相关进程继续运行。
  • 引入全局状态变量(CLEANING、PMHQ_PID、USE_XVFB、DISTRO)来协调整个生命周期管理
  • 实现 cleanup():在收到退出信号时挂起 PMHQ 进程组,提示用户是否终止 QQ/PMHQ,并根据用户选择有条件地恢复或终止该进程组
  • 添加基于超时的默认行为:若无用户输入则终止 QQ/PMHQ,先发送 TERM,若进程顽固不退出则退回使用 KILL/PKILL
  • 集成对非 Arch、非 Xvfb 情况的 X11 xhost 清理逻辑,并将存活的进程从脚本控制中分离
  • 将 cleanup() 注册为 SIGINT、SIGTERM 和 EXIT 的处理函数,并在 run_llbot() 中记录 PMHQ_PID 供后续使用
script/start-linux.sh
加固环境与依赖设置,包括 sudo 验证以及对 Arch 和 Debian 更健壮的软件包安装逻辑。
  • 新增 check_sudo(),并在 install_arch() 和 install_debian() 中调用,以确保在运行包管理器前 sudo token 有效
  • 收紧对 pacman/apt/wget/QQ 安装包的错误处理,在命令失败时给出明确的错误信息
  • 优化 Arch 上安装 yay 的流程,提供更清晰的警告和失败提示
  • 修改 Debian 上 ffmpeg/xvfb 的安装方式:在检测缺失命令后,批量安装缺失工具
script/start-linux.sh
改进运行时体验,包括端口分配、模式选择、显示/输入法环境处理,并在作业控制模式下运行 LLBot,将 PMHQ 放入后台。
  • 优化 find_port() 的注释与日志信息(例如端口分配、模式选择文案),更准确地描述实际行为
  • 调整模式选择文案,以更清晰地区分 GUI 与 shell(无头)语义,并说明在超时情况下会自动选择默认模式
  • 重做 X11 授权逻辑,不再将临时 xhost 授权绑定到简单的 EXIT trap,而是改由 cleanup 统一处理
  • 明确 Wayland/X11 检测相关日志信息和输入法环境设置,并始终通过 sudo 将 llbot 目录 chown 给当前用户
  • 在 run_llbot() 中通过 set -m 启用作业控制,在 Xvfb 或 GUI 下以后台方式启动 PMHQ,记录 PMHQ_PID,并对其执行 wait,以便脚本能够正确响应信号
script/start-linux.sh

使用技巧和常用命令

与 Sourcery 交互

  • 触发新一轮审查: 在 Pull Request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub Issue: 在某条审查评论下回复,要求 Sourcery 从该评论创建 Issue。你也可以直接在该评论下回复 @sourcery-ai issue 来创建 Issue。
  • 生成 Pull Request 标题: 在 Pull Request 标题中任意位置写上 @sourcery-ai,即可随时生成标题。也可以在 Pull Request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 Pull Request 摘要: 在 Pull Request 正文任意位置写上 @sourcery-ai summary,即可在对应位置生成 PR 摘要。也可以在 Pull Request 中评论 @sourcery-ai summary 来随时(重新)生成摘要。
  • 生成审阅者指南: 在 Pull Request 中评论 @sourcery-ai guide,即可随时(重新)生成审阅者指南。
  • 一键解决所有 Sourcery 评论: 在 Pull Request 中评论 @sourcery-ai resolve,即可将所有 Sourcery 评论标记为已解决。适用于你已经处理完所有评论且不想再看到它们时。
  • 撤销所有 Sourcery 审查: 在 Pull Request 中评论 @sourcery-ai dismiss,即可撤销所有现有的 Sourcery 审查。特别适用于你想从头开始新一轮审查的场景——别忘了再评论 @sourcery-ai review 来触发新的审查!

自定义你的使用体验

访问你的 控制面板 以:

  • 启用或停用各类审查功能,例如 Sourcery 自动生成的 Pull Request 摘要、审阅者指南等。
  • 修改审查所使用的语言。
  • 添加、删除或编辑自定义审查指令。
  • 调整其他审查相关设置。

获取帮助

Original review guide in English

Reviewer's Guide

Refactors the Linux startup script to add robust signal-driven cleanup with optional QQ process preservation, explicit sudo validation, and more resilient dependency/QQ installation flows, while improving mode selection UX and display/X11 handling.

Sequence diagram for the new signal-driven cleanup and QQ preservation flow

sequenceDiagram
    actor User
    participant ShellScript
    participant PMHQProcess
    participant QQProcess
    participant XServer

    User->>ShellScript: run start-linux.sh
    ShellScript->>ShellScript: trap cleanup on SIGINT SIGTERM EXIT
    ShellScript->>PMHQProcess: start pmhq with sub_cmd (&)
    ShellScript->>ShellScript: store PMHQ_PID
    ShellScript->>ShellScript: wait PMHQ_PID

    User-->>ShellScript: press Ctrl+C (SIGINT)
    ShellScript->>ShellScript: invoke cleanup
    alt cleanup not already running
        ShellScript->>ShellScript: set CLEANING=1
        ShellScript->>PMHQProcess: SIGSTOP process group (-PMHQ_PID)
        ShellScript->>User: prompt on /dev/tty
        User-->>ShellScript: choice Y/n or timeout
        alt user keeps QQ (choice n/N)
            ShellScript->>PMHQProcess: SIGCONT process group
            ShellScript->>User: log QQ and related processes detached
            ShellScript->>ShellScript: exit 0
        else user closes QQ (default or Y)
            ShellScript->>PMHQProcess: SIGCONT process group
            ShellScript->>PMHQProcess: SIGTERM process group
            ShellScript->>QQProcess: pkill -15 QQ binaries
            loop wait for clean exit
                ShellScript->>PMHQProcess: poll with kill -0
                ShellScript->>QQProcess: pgrep QQ binaries
            end
            alt processes still remain
                ShellScript->>PMHQProcess: SIGKILL process group
                ShellScript->>QQProcess: pkill -9 QQ binaries
            end
            alt non-arch and not using xvfb
                ShellScript->>XServer: xhost -local:username
            end
            ShellScript->>User: log cleanup complete
            ShellScript->>ShellScript: exit 0
        end
    else cleanup already running
        ShellScript->>ShellScript: return immediately
    end
Loading

Flow diagram for distro-specific install and sudo validation in start-linux.sh

flowchart TD
    Start[Start script] --> DetectDistro[Detect distro via pacman/apt]
    DetectDistro -->|pacman| SetArch[Set DISTRO=arch]
    DetectDistro -->|apt| SetDebian[Set DISTRO=debian]
    DetectDistro -->|other| ErrUnsupported[error 当前只支持 apt 或 pacman 包管理器]

    SetArch --> InstallArch
    SetDebian --> InstallDebian

    subgraph ArchInstall[install_arch]
        InstallArch --> CheckSudoArch[check_sudo sudo -v]
        CheckSudoArch -->|fail| ErrSudoArch[error Sudo 验证失败]
        CheckSudoArch -->|ok| PacmanDeps[pacman install base deps]
        PacmanDeps --> QQCheckArch{QQ binary exists?}
        QQCheckArch -->|yes| ArchDone[return]
        QQCheckArch -->|no| AskAUR[confirm install QQ via AUR]
        AskAUR -->|no| ArchDone
        AskAUR -->|yes| YayCheck{yay installed?}
        YayCheck -->|yes| YayInstallQQ[yay -S qq-nt etc]
        YayInstallQQ --> ArchDone
        YayCheck -->|no| TryPacmanYay[pacman -S yay]
        TryPacmanYay -->|success| YayInstallQQ
        TryPacmanYay -->|fail| BuildYay[git clone yay; makepkg]
        BuildYay -->|fail| ErrYayBuild[error yay 编译失败]
        BuildYay -->|success| YayInstallQQ
    end

    subgraph DebianInstall[install_debian]
        InstallDebian --> CheckSudoDebian[check_sudo sudo -v]
        CheckSudoDebian -->|fail| ErrSudoDebian[error Sudo 验证失败]
        CheckSudoDebian -->|ok| QQCheckDeb{QQ binary exists?}
        QQCheckDeb -->|yes| CheckTools[check ffmpeg/xvfb]
        QQCheckDeb -->|no| AskQQDeb[confirm install QQ]
        AskQQDeb -->|no| CheckTools
        AskQQDeb -->|yes| AptUpdate[apt-get update; install wget]
        AptUpdate -->|fail| ErrAptUpdate[error apt update 或 wget 安装失败]
        AptUpdate -->|ok| DownloadDeb[wget QQ deb]
        DownloadDeb -->|fail| ErrQQDownload[error QQ 安装包下载失败]
        DownloadDeb -->|ok| DetectLib[choose libasound2 or libasound2t64]
        DetectLib --> InstallQQDeb[apt install QQ deb and deps]
        InstallQQDeb -->|fail| ErrQQDeps[error QQ 依赖安装失败]
        InstallQQDeb -->|ok| RemoveDeb[rm deb]
        RemoveDeb --> CheckTools
        CheckTools --> MissingPkgs{any ffmpeg/xvfb missing?}
        MissingPkgs -->|no| DebianDone[return]
        MissingPkgs -->|yes| AptInstallTools[apt-get install missing]
        AptInstallTools -->|fail| ErrTools[error 工具安装失败]
        AptInstallTools -->|ok| DebianDone
    end

    ArchDone --> PostInstall
    DebianDone --> PostInstall

    PostInstall[chmod and chown llbot; continue to mode selection] --> End[End install phase]
Loading

File-Level Changes

Change Details Files
Add centralized cleanup and signal handling to gracefully manage Ctrl+C/exit and optionally keep QQ-related processes running.
  • Introduce global state (CLEANING, PMHQ_PID, USE_XVFB, DISTRO) to coordinate lifecycle management
  • Implement cleanup() that suspends the PMHQ process group on exit signals, prompts user whether to terminate QQ/PMHQ, and conditionally resumes or terminates the group
  • Add timeout-based default behavior to kill QQ/PMHQ if no user input, with TERM then fallback KILL/PKILL for stubborn processes
  • Integrate X11 xhost cleanup for non-Arch, non-Xvfb cases and detach surviving processes from script control
  • Register cleanup() as handler for SIGINT, SIGTERM, and EXIT and store PMHQ_PID from run_llbot() for later use
script/start-linux.sh
Harden environment and dependency setup, including sudo validation and more robust package installation for Arch and Debian.
  • Add check_sudo() and call it in install_arch() and install_debian() to ensure sudo token is valid before running package managers
  • Tighten error handling for pacman/apt/wget/QQ package installs with explicit error messages when commands fail
  • Improve Arch yay installation path with clearer warnings and failure messages
  • Change Debian ffmpeg/xvfb installation to batch-install missing tools after detecting absent commands
script/start-linux.sh
Improve runtime UX for port allocation, mode selection, and display/IM environment handling, and run LLBot under job control with backgrounded PMHQ.
  • Refine find_port() comments and log messages (e.g., port allocation, mode selection wording) to better describe behavior
  • Adjust mode selection texts to clarify GUI vs shell (headless) semantics and automatic defaulting on timeout
  • Rework X11 authorization so temporary xhost grant is not tied to a simple EXIT trap and is instead handled in cleanup
  • Clarify Wayland/X11 detection log messages and IM env setup, and always chown llbot directory via sudo for current user
  • Enable job control with set -m in run_llbot(), start PMHQ under xvfb or GUI in background, record PMHQ_PID, and wait on it so the script can react properly to signals
script/start-linux.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我发现了 1 个问题,并给出了一些高层次的反馈:

  • 使用 trap cleanup ... EXIT 时,交互式的 QQ 关闭提示会在脚本正常结束时也出现(而不仅仅是 Ctrl+C/SIGTERM);如果你只想处理异常退出,建议从 trap 中去掉 EXIT,或者在 cleanup 中根据信号/来源进行分支处理。
  • install_debian 中,command -v xvfb 会一直失败,因为实际的可执行文件是 Xvfb/xvfb-run,所以脚本会反复误以为缺少 xvfb;建议改为检查 xvfb-runXvfb
  • cleanup 中的 read ... < /dev/tty 在非交互式或重定向场景(如 cron/systemd)下可能会失败或意外阻塞;你可能需要先用 TTY 检查([ -t 0 ]),在没有终端时跳过交互式提示。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Using `trap cleanup ... EXIT` means the interactive QQ shutdown prompt will also appear on normal script completion (not just Ctrl+C/SIGTERM); if you only want to handle abrupt exits, consider dropping `EXIT` from the trap or branching in `cleanup` based on the signal/source.
- In `install_debian`, `command -v xvfb` will always fail because the binary is `Xvfb`/`xvfb-run`, so the script will repeatedly think xvfb is missing; consider checking for `xvfb-run` or `Xvfb` instead.
- The `read ... < /dev/tty` in `cleanup` can fail or block unexpectedly in non-interactive or redirected environments (e.g. cron/systemd); you may want to guard this with a TTY check (`[ -t 0 ]`) and skip the interactive prompt when no terminal is available.

## Individual Comments

### Comment 1
<location> `script/start-linux.sh:97` </location>
<code_context>
+    exit 0
+}
+
+trap cleanup SIGINT SIGTERM EXIT
+
 confirm() {
</code_context>

<issue_to_address>
**issue (bug_risk):** Using EXIT in the trap makes cleanup run (and prompt) even on normal termination and masks the original exit status.

This means the interactive prompt in `cleanup` can run even on clean or non-interactive exits, and the final `exit 0` will override any earlier non-zero status, hiding failures.

Consider either:
- Moving non-interactive cleanup (e.g. `xhost -local`, process cleanup) into a separate EXIT handler that preserves `$?`, and
- Restricting the interactive "是否关闭 QQ" prompt to SIGINT/SIGTERM only, or
- Removing EXIT from the trap if you don’t want interactive behavior on normal exit.
</issue_to_address>

Sourcery 对开源项目免费 —— 如果你觉得我们的评审有帮助,请考虑分享给更多人 ✨
帮我变得更有用!请对每条评论点 👍 或 👎,我会根据这些反馈改进后续的评审。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • Using trap cleanup ... EXIT means the interactive QQ shutdown prompt will also appear on normal script completion (not just Ctrl+C/SIGTERM); if you only want to handle abrupt exits, consider dropping EXIT from the trap or branching in cleanup based on the signal/source.
  • In install_debian, command -v xvfb will always fail because the binary is Xvfb/xvfb-run, so the script will repeatedly think xvfb is missing; consider checking for xvfb-run or Xvfb instead.
  • The read ... < /dev/tty in cleanup can fail or block unexpectedly in non-interactive or redirected environments (e.g. cron/systemd); you may want to guard this with a TTY check ([ -t 0 ]) and skip the interactive prompt when no terminal is available.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Using `trap cleanup ... EXIT` means the interactive QQ shutdown prompt will also appear on normal script completion (not just Ctrl+C/SIGTERM); if you only want to handle abrupt exits, consider dropping `EXIT` from the trap or branching in `cleanup` based on the signal/source.
- In `install_debian`, `command -v xvfb` will always fail because the binary is `Xvfb`/`xvfb-run`, so the script will repeatedly think xvfb is missing; consider checking for `xvfb-run` or `Xvfb` instead.
- The `read ... < /dev/tty` in `cleanup` can fail or block unexpectedly in non-interactive or redirected environments (e.g. cron/systemd); you may want to guard this with a TTY check (`[ -t 0 ]`) and skip the interactive prompt when no terminal is available.

## Individual Comments

### Comment 1
<location> `script/start-linux.sh:97` </location>
<code_context>
+    exit 0
+}
+
+trap cleanup SIGINT SIGTERM EXIT
+
 confirm() {
</code_context>

<issue_to_address>
**issue (bug_risk):** Using EXIT in the trap makes cleanup run (and prompt) even on normal termination and masks the original exit status.

This means the interactive prompt in `cleanup` can run even on clean or non-interactive exits, and the final `exit 0` will override any earlier non-zero status, hiding failures.

Consider either:
- Moving non-interactive cleanup (e.g. `xhost -local`, process cleanup) into a separate EXIT handler that preserves `$?`, and
- Restricting the interactive "是否关闭 QQ" prompt to SIGINT/SIGTERM only, or
- Removing EXIT from the trap if you don’t want interactive behavior on normal exit.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@linyuchen linyuchen merged commit bef68e9 into LLOneBot:main Dec 30, 2025
3 checks passed
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.

2 participants