Sohaib Afzal
Sohaib Afzal

Reputation: 119

Trap SIGINT not working in Alpine Linux ash shell

I have a limited rights user in Alpine Linux whose login shell has been changed to a script in /etc/passwd/ as follows:

user:x:1001:1001:Linux User,,,:/home/user:/home/user/menu.sh

Inside the script, I want to trap INT so that the user can only exit using the relevant menu option but pressing Ctrl+C should display the menu again.

#!/bin/ash

# ...
display_menu() {
  # ...
}

trap 'display_menu' INT QUIT TSTP

while true; do
   display_menu
   # ...
done

The script runs as it should, but does not trap Ctrl+C or Ctrl+\. Instead, pressing Ctrl+C kills the script and brings up the login prompt. If I add just trap inside my display_menu function, I can see that trap is set because trap -- 'display_menu' INT is displayed.

It is worth mentioning that the script handles Ctrl+Z okay (it does not go to background). I am using Alpine Linux in a VM not in Docker.

Upvotes: 1

Views: 244

Answers (0)

Related Questions