[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-bash] Restoring tty line settings after a trap
From: |
Jesse Molina |
Subject: |
[Help-bash] Restoring tty line settings after a trap |
Date: |
Mon, 16 Jun 2014 17:27:55 -0700 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:29.0) Gecko/20100101 Firefox/29.0 SeaMonkey/2.26 |
Hi everyone
I have an issue with a bash script where if the user calls SIGINT via a
ctrl+c, my trap gets called and the tty line settings don't get restored
like they should, because they had been changed before trap was called,
but not restored.
If I disable my trap, this problem does not happen, but I have lock
files and other messes which need to be cleand up, so the trap is necessary.
For example the script is at a read prompt due to a line like this:
read -e -r -p "THING: " -i "$THING_GAMETYPE" IN_NEW_THING
If user sends SIGINT, trap gets called, the trap func does it's thing
and then quits, but the users terminal is borked up with local echo and
other stty settings that are not right.
I think I could just call stty to save it's settings when the script
starts and then restore them if trap is called, or just do an stty sane
in the trap.
Is there are a "better" way to do this, or is doing an stty save and
restore my best bet?
FYI here's the diff between an stty -a before and then after aborting
the read line above:
address@hidden>diff 1 2
4c4
< lnext = ^V; flush = ^O; min = 1; time = 0;
---
> lnext = <undef>; flush = ^O; min = 1; time = 0;
6c6
< -ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon
-ixoff
---
> -ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr -icrnl
ixon -ixoff
9c9
< isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop
-echoprt
---
> isig -icanon iexten -echo echoe echok -echonl -noflsh -xcase -tostop
-echoprt
I did google around on this. I found a few similar questions on Stack
Exchange, but no definitive answers.
Thanks in advance for any advice.
- [Help-bash] Restoring tty line settings after a trap,
Jesse Molina <=