msys2 / msys2/msys2.github.io

trap is not executed when interrupting a sleep command

Open
#314 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
CSS
Stars
3.3k
Forks
446
Avg merge
2h 16m
Merged PRs (30d)
1

Description

In my .bashrc file I have the following

function cleanup() {
  echo "Global cleanup"
  for i in {1..2}; do
    echo $i
    sleep 1
  done
  
}

trap cleanup SIGINT

function infinite_loop() {
  local i=1
  while true; do
    echo "hello $i"
    i=$((i + 1))
    sleep 1
  done
}

I basically want to execute some cleanup code after typing Ctrl+c
If I type Ctrl+c in a msys shell the trap correctly works but if I run the infinite_loop function and then type Ctrl+c the cleanup code is not executed also if the infinite_loop is stopped.

I tried also to add the option:
MSYS=enable_pcon
in the .minttyrc file after reading this: https://github.com/mintty/mintty/issues/56#issuecomment-1962490572 without success.
The version is msys2-runtime 3.4.10-5

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior from the .bashrc example in an MSYS shell, comparing the SIGINT trap directly with the infinite_loop function and its sleep commands. Check the reported msys2-runtime 3.4.10-5 version and the linked mintty discussion first; done means determining why Ctrl+C does not execute cleanup and documenting or resolving the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.