TRAPPING SIGNALS IN CSH
Christopher J. Hawley
chawley at sundiver.esd.sgi.com
Fri Apr 26 04:18:43 AEST 1991
In article <9104242103.AA11863 at ccfiris.aedc>, mcdonald at AEDC-VAX.AF.MIL
writes:
|> My problem arises when the user hits Ctrl-C when he first logs
|> in which kills the execution of /etc/cshrc, thus my expiration checker does
|> not get executed. How can I trap these signals in a csh?
Read the description of the csh builtin command "onintr" in csh(1) .
It provides a barely adequate (IMHO) means of intercepting interrupt signals;
used in conjunction with some stty(1) contortions to disable other signals
from the keyboard, you could write something similar to the following:
...
# Assume we're executing from a tty.
# Save tty settings, disable signals except for SIGINT
set ottymode = `stty -g`
stty quit '^-' # "undef" on some BSD systems
# Trap interrupts to clean-up portion of script
onintr interrupted
...
<commands to change password>
...
goto finished
# Clean-up handling (executed when interrupted)
interrupted:
...
<commands to undo partial changes, set return status>
...
# Here to complete task, restore terminal modes, return status.
# Restore original tty settings
stty $ottymode; unset ottymode
# Revert to previous interrupt handling (if sourced inline)
onintr
# Exit with return status (if subshell or aborted)
exit($returnstatus)
|> In a Bourne shell all I have to do is trap them with the trap command.
Y'know, that's probably the easiest way to accomplish the task...
use an explicit invocation:
/bin/sh chgpwdscript
Use the trap builtin and set SHELL=/bin/sh within chgpwdscript .
|> | Kenneth M. McDonald * OAO Corp * Arnold Engineering Development Center |
|> | MS 120 * Arnold AFS, TN 37389-9998 * (615) 454-3413 |
#include "std_disclaimer.h"
/* My opinions are my own... in my opinion, standard discs are lame. */
---
Christopher J. Hawley / esper chawley at sundiver.esd.sgi.com
Silicon Graphics, Inc. 1L-945 phone: 415 / 335-1621
Mountain View, CA 94039-7311 USA 408 / 243-1042
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"Nicht nur wie schnell Sie fahren, sondern _wie_ Sie schnell fahren."
More information about the Comp.sys.sgi
mailing list