Operating System - HP-UX
1833013 Members
2889 Online
110048 Solutions
New Discussion

Re: Re-enabling ctrl-C trap after returning from menu..

 
SOLVED
Go to solution
Jack C. Mahaffey
Super Advisor

Re-enabling ctrl-C trap after returning from menu..

We have operation menus that disable Control-C while the user is in the menus. The initial menu is an admin user account that specifically executes the menu and doesn't provide a shell prompt.


Here's my problem. Whenever I su or login using the admin menu and then return to the previous shell session that I was in, Control-C no longer works. I then have to log out of the shell session that I su's or logged in from.


Any ideas?


Example:
1 - Log in as root
2 - su - hpadmin (runs the admin menu under the hpadmin account)
3 - Exit from menu (Control-C no longer works now that I'm back as root)

I do a ping test after returning from the admin menus and I can't interrupt the pings. To get control-c to work again I have to exit root.

jack...





4 REPLIES 4
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Re-enabling ctrl-C trap after returning from menu..

Your outer level menu may need to assert a new trap statement BUT it's very possible that the application has reset the interrupt key.

When you get in your situation, issue a stty -a and note the intr setting. Sometimes, a programmer will set intr to an impossible value e.g. \377 rather than ignoring an intterupt. This is especially true when Ctrl-C or DEL is used for something else. If intr has been reset then you can issue a stty of your own to reset it. The best method would be to do an initial stty to get the value of the interrupt key and then reset to that value after each return from the applications.

If it ain't broke, I can fix that.
James R. Ferguson
Acclaimed Contributor

Re: Re-enabling ctrl-C trap after returning from menu..

Hi Jack:

You can disable the trap with 'trap - INT' :

#!usr/bin/sh
trap '' INT
echo "CTRL_C disabled"
read OK
trap - INT
echo "CTRL_C enabled"
read OK
exit 0

Regrards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: Re-enabling ctrl-C trap after returning from menu..

Hi again:

In case you think my theory of setting the interrupt key sounds hokey, note that the interrupt key is defined for the port NOT for the process. Once set, it remains until a subsequent ioctl() or stty command.
If it ain't broke, I can fix that.
Jack C. Mahaffey
Super Advisor

Re: Re-enabling ctrl-C trap after returning from menu..

Thanks all.

Clay, your right on the money.

Somehow, somewhere the intr setting gets changed to DEL from ^C. Looks like the quit and erase settings get changed also.

Here's diff output from comparing the settings before and after running the menus.

[4987]root@cordayop:/tmp # diff stty.before stty.after
3,5c3,5
< min = 1; time = 0;
< intr = ^C; quit ; erase = ^H; kill = ^U
< eof = ^D; eol = ^@; eol2 ; swtch
---
> min = 4; time = 0;
> intr = DEL; quit = ^\; erase = #; kill = @
> eof = ^D; eol = ^@; eol2 ; swtch = ^@
9,11c9,11
< -ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -iuclc
< ixon ixany ixoff -imaxbel -rtsxoff -ctsxon -ienqak
< isig icanon -iexten -xcase echo echoe echok -echonl -noflsh
---
> -ignbrk brkint ignpar -parmrk -inpck istrip -inlcr -igncr icrnl -iuclc
> ixon ixany -ixoff -imaxbel -rtsxoff -ctsxon -ienqak
> isig icanon -iexten -xcase echo -echoe echok -echonl -noflsh