Skip to content

[build] Fix Ctrl-C not aborting build (process_log.sh SIGINT)#25645

Merged
yxieca merged 2 commits intosonic-net:masterfrom
rustiqly:fix/ctrl-c-build-abort
Feb 26, 2026
Merged

[build] Fix Ctrl-C not aborting build (process_log.sh SIGINT)#25645
yxieca merged 2 commits intosonic-net:masterfrom
rustiqly:fix/ctrl-c-build-abort

Conversation

@rustiqly
Copy link
Copy Markdown
Contributor

What I did

Add SIGINT and SIGTERM trap handlers to scripts/process_log.sh so that pressing Ctrl-C during a build actually terminates the build.

Why I did it

Currently, pressing Ctrl-C during a SONiC build (especially during the trixie phase) does not reliably abort the build. The build appears to hang or continue running in the background.

Root cause: The LOG macro in rules/functions pipes all build output through process_log.sh:

LOG = < /dev/null |& $(PROJECT_ROOT)/scripts/process_log.sh -t &>> $(PROJECT_ROOT)/$@.log

When the user presses Ctrl-C:

  1. The terminal sends SIGINT to the foreground process group
  2. make receives it and tries to kill child processes
  3. But process_log.sh 's while IFS= read -r line loop does not exit on SIGINT — bash's read builtin is not reliably interruptible by signals
  4. This keeps the pipe open, preventing the upstream build command from being cleaned up
  5. The build appears stuck or continues in the background

Fixes: #25520

How I did it

Added two trap handlers at the top of process_log.sh:

trap 'exit 130' INT    # 128 + 2 (SIGINT)
trap 'exit 143' TERM   # 128 + 15 (SIGTERM)

These ensure the script exits immediately when signaled, allowing the pipeline to tear down and make to clean up properly.

How I verified it

  1. Started a VS build with make SONIC_BUILD_JOBS=4 target/sonic-vs.img.gz
  2. Pressed Ctrl-C during package compilation phase
  3. Verified build processes terminate within seconds (previously would hang)
  4. Verified normal build operation is unaffected — process_log.sh still correctly timestamps and forwards all output when not interrupted

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@rustiqly rustiqly force-pushed the fix/ctrl-c-build-abort branch from 49db8f6 to 272d068 Compare February 24, 2026 17:02
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Add SIGINT and SIGTERM trap handlers to process_log.sh so that
pressing Ctrl-C during a build actually terminates the process
pipeline.

Root cause: The LOG macro in rules/functions pipes build output
through process_log.sh:

  cmd < /dev/null |& process_log.sh -t >> target.log

When the user presses Ctrl-C, make receives SIGINT and attempts to
kill child processes. However, process_log.sh `while read` loop
ignores SIGINT by default (bash builtin read is not interruptible
in all cases), keeping the pipeline alive and preventing make from
cleaning up and exiting.

The fix adds explicit trap handlers that exit with the conventional
signal exit codes (128+signal_number) when SIGINT or SIGTERM is
received.

Fixes: sonic-net#25520

Signed-off-by: Rustiqly <rustiqly@users.noreply.github.com>
@rustiqly rustiqly force-pushed the fix/ctrl-c-build-abort branch from 272d068 to 1275101 Compare February 25, 2026 15:01
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines failed to run 1 pipeline(s).

@yxieca yxieca merged commit 92fec2a into sonic-net:master Feb 26, 2026
7 checks passed
FengPan-Frank pushed a commit to FengPan-Frank/sonic-buildimage that referenced this pull request Mar 6, 2026
…net#25645)

Add SIGINT and SIGTERM trap handlers to process_log.sh so that
pressing Ctrl-C during a build actually terminates the process
pipeline.

Root cause: The LOG macro in rules/functions pipes build output
through process_log.sh:

  cmd < /dev/null |& process_log.sh -t >> target.log

When the user presses Ctrl-C, make receives SIGINT and attempts to
kill child processes. However, process_log.sh `while read` loop
ignores SIGINT by default (bash builtin read is not interruptible
in all cases), keeping the pipeline alive and preventing make from
cleaning up and exiting.

The fix adds explicit trap handlers that exit with the conventional
signal exit codes (128+signal_number) when SIGINT or SIGTERM is
received.

Fixes: sonic-net#25520

Signed-off-by: Rustiqly <rustiqly@users.noreply.github.com>
Co-authored-by: Rustiqly <rustiqly@users.noreply.github.com>
Co-authored-by: Lihua Yuan <lihuay@users.noreply.github.com>
Signed-off-by: Feng Pan <fenpan@microsoft.com>
dprital pushed a commit that referenced this pull request Mar 19, 2026
Add SIGINT and SIGTERM trap handlers to process_log.sh so that
pressing Ctrl-C during a build actually terminates the process
pipeline.

Root cause: The LOG macro in rules/functions pipes build output
through process_log.sh:

  cmd < /dev/null |& process_log.sh -t >> target.log

When the user presses Ctrl-C, make receives SIGINT and attempts to
kill child processes. However, process_log.sh `while read` loop
ignores SIGINT by default (bash builtin read is not interruptible
in all cases), keeping the pipeline alive and preventing make from
cleaning up and exiting.

The fix adds explicit trap handlers that exit with the conventional
signal exit codes (128+signal_number) when SIGINT or SIGTERM is
received.

Fixes: #25520

Signed-off-by: Rustiqly <rustiqly@users.noreply.github.com>
Co-authored-by: Rustiqly <rustiqly@users.noreply.github.com>
Co-authored-by: Lihua Yuan <lihuay@users.noreply.github.com>
Signed-off-by: dprital <drorp@nvidia.com>
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.

Bug: CTRL-C does not abort sonic-build

5 participants