trap.c revision da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/***********************************************************************
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* This software is part of the ast package *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* and is licensed under the *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Common Public License, Version 1.0 *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* by AT&T Knowledge Ventures *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* A copy of the License is available at *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Information and Software Systems Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* AT&T Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Florham Park NJ *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* David Korn <dgk@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin***********************************************************************/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * trap [-p] action sig...
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * kill [-l] [sig...]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * kill [-s sig] pid...
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * David Korn
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * AT&T Labs
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * research!dgk
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic int sig_number(const char*);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(2);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin errormsg(SH_DICT,ERROR_usage(2),"%s", optusage((char*)0));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int clear;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* first argument all digits or - means clear */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while(!argv[0])
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* internal traps */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin char **trapcom = (shp->st.otrapcom?shp->st.otrapcom:shp->st.trapcom);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else /* print out current traps */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char *signame;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if((signame=argv[opt_info.index++]) && (sig=sig_number(signame+1))>=0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if(*argv && strcmp(*argv,"--")==0 && strcmp(*(argv-1),"--")!=0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if(error_info.errors || flag==(L_FLAG|S_FLAG) || (!(*argv) && !(flag&L_FLAG)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin errormsg(SH_DICT,ERROR_usage(2),"%s", optusage((char*)0));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* just in case we send a kill -9 $$ */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin sig_list(shp,((int)strtol(signame, (char**)0, 10)&0177)+1);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Given the name or number of a signal return the signal number
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int n,sig=0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int c;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin tp = sh_locate(stakptr(n),(const Shtable_t*)shtab_signals,sizeof(*shtab_signals));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* sig prefix cannot match internal traps */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(n);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * if <flag> is positive, then print signal name corresponding to <flag>
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * if <flag> is zero, then print all signal names
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * if <flag> is negative, then print all traps
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void sig_list(register Shell_t *shp,register int flag)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* not all signals may be defined, so initialize */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while(--sig >= 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if(flag<0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* print the traps */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* use parent traps if otrapcom is set (for $(trap) */
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin trapcom = (shp->st.otrapcom?shp->st.otrapcom:shp->st.trapcom);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while(--sig >= 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin /* print all the signal names */