trap.c revision da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1982-2007 AT&T Knowledge Ventures *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Knowledge Ventures *
* *
* A copy of the License is available at *
* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* trap [-p] action sig...
* kill [-l] [sig...]
* kill [-s sig] pid...
*
* David Korn
* AT&T Labs
* research!dgk
*
*/
#include "defs.h"
#include <ctype.h>
#include "jobs.h"
#include "builtins.h"
#define L_FLAG 1
#define S_FLAG 2
static const char trapfmt[] = "trap -- %s %s\n";
static int sig_number(const char*);
{
{
case 'p':
pflag=1;
break;
case ':':
break;
case '?':
return(2);
break;
}
if(error_info.errors)
{
register int clear;
if(!pflag)
{
/* first argument all digits or - means clear */
arg++;
if(!clear)
{
++argv;
clear++;
}
while(!argv[0])
}
{
if(sig<0)
{
return(1);
}
/* internal traps */
{
if(sig>SH_DEBUGTRAP)
{
return(1);
}
if(pflag)
{
continue;
}
if(sig == SH_DEBUGTRAP)
{
else
}
continue;
}
{
return(1);
}
else if(pflag)
{
}
else if(clear)
else
{
}
}
}
else /* print out current traps */
return(0);
}
{
register char *signame;
{
case ':':
goto endopts;
break;
case 'n':
goto endopts;
case 's':
goto endopts;
case 'l':
break;
case '?':
break;
}
argv++;
/* just in case we send a kill -9 $$ */
{
if(!(*argv))
{
else
{
{
}
}
}
}
{
}
}
/*
* Given the name or number of a signal return the signal number
*/
static int sig_number(const char *string)
{
register int n,sig=0;
char *last;
{
if(*last)
n = -1;
}
else
{
register int c;
n = staktell();
do
{
c = *string++;
if(islower(c))
c = toupper(c);
stakputc(c);
}
while(c);
stakseek(n);
{
sig = 1;
n += 3;
}
{
/* sig prefix cannot match internal traps */
n = 0;
}
if(n < SH_TRAP)
n--;
}
return(n);
}
/*
* if <flag> is positive, then print signal name corresponding to <flag>
* if <flag> is zero, then print all signal names
* if <flag> is negative, then print all traps
*/
{
if(flag==0)
{
/* not all signals may be defined, so initialize */
while(--sig >= 0)
}
{
{
return;
}
tp++;
}
if(flag > 0)
else if(flag<0)
{
/* print the traps */
char name[6];
/* use parent traps if otrapcom is set (for $(trap) */
while(--sig >= 0)
{
continue;
{
sname[0] = 'S';
}
}
{
continue;
}
}
else
{
/* print all the signal names */
{
else
}
}
}