Changeset 1208 in kBuild for trunk/src/kash/trap.c
- Timestamp:
- Oct 7, 2007 5:33:41 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/trap.c
r1207 r1208 62 62 #include "mystring.h" 63 63 #include "var.h" 64 #include "shinstance.h" 64 65 65 66 #ifndef HAVE_SYS_SIGNAME … … 81 82 82 83 83 char *trap[NSIG+1]; /* trap handler commands */ 84 MKINIT char sigmode[NSIG]; /* current value of signal */ 85 char gotsig[NSIG]; /* indicates specified signal received */ 86 int pendingsigs; /* indicates some signal received */ 87 88 #ifdef __sun__ 89 typedef void (*sig_t) (int); 90 #endif 91 static int getsigaction(int, sig_t *); 84 //char *trap[NSIG+1]; /* trap handler commands */ 85 //MKINIT char sigmode[NSIG]; /* current value of signal */ 86 //char gotsig[NSIG]; /* indicates specified signal received */ 87 //int pendingsigs; /* indicates some signal received */ 88 89 static int getsigaction(shinstance *, int, sh_sig_t *); 92 90 93 91 /* … … 97 95 98 96 static int 99 signame_to_signum( const char *p)97 signame_to_signum(shinstance *psh, const char *p) 100 98 { 101 99 int i; … … 123 121 */ 124 122 static void 125 printsignals( void)123 printsignals(shinstance *psh) 126 124 { 127 125 int n; … … 146 144 147 145 int 148 trapcmd( int argc, char **argv)146 trapcmd(shinstance *psh, int argc, char **argv) 149 147 { 150 148 char *action; … … 157 155 if (argc <= 1) { 158 156 for (signo = 0 ; signo <= NSIG ; signo++) 159 if ( trap[signo] != NULL) {157 if (psh->trap[signo] != NULL) { 160 158 out1fmt(psh, "trap -- "); 161 print_quoted(psh, trap[signo]);159 print_quoted(psh, psh->trap[signo]); 162 160 out1fmt(psh, " %s\n", 163 161 (signo) ? sys_signame[signo] : "EXIT"); … … 173 171 return 0; 174 172 175 if (signame_to_signum( *ap) == -1) {173 if (signame_to_signum(psh, *ap) == -1) { 176 174 if ((*ap)[0] == '-') { 177 175 if ((*ap)[1] == '\0') 178 176 ap++; 179 177 else if ((*ap)[1] == 'l' && (*ap)[2] == '\0') { 180 printsignals( );178 printsignals(psh); 181 179 return 0; 182 180 } … … 192 190 signo = number(psh, *ap); 193 191 else 194 signo = signame_to_signum( *ap);192 signo = signame_to_signum(psh, *ap); 195 193 196 194 if (signo < 0 || signo > NSIG) … … 201 199 action = savestr(action); 202 200 203 if ( trap[signo])204 ckfree( trap[signo]);205 206 trap[signo] = action;201 if (psh->trap[signo]) 202 ckfree(psh->trap[signo]); 203 204 psh->trap[signo] = action; 207 205 208 206 if (signo != 0) … … 223 221 224 222 void 225 clear_traps( int vforked)223 clear_traps(shinstance *psh, int vforked) 226 224 { 227 225 char **tp; 228 226 229 for (tp = trap ; tp <= &trap[NSIG] ; tp++) {227 for (tp = psh->trap ; tp <= &psh->trap[NSIG] ; tp++) { 230 228 if (*tp && **tp) { /* trap not NULL or SIG_IGN */ 231 229 INTOFF; … … 234 232 *tp = NULL; 235 233 } 236 if (tp != & trap[0])237 setsignal(psh, tp - trap, vforked);234 if (tp != &psh->trap[0]) 235 setsignal(psh, (int)(tp - psh->trap), vforked); 238 236 INTON; 239 237 } … … 249 247 250 248 long 251 setsignal( int signo, int vforked)249 setsignal(shinstance *psh, int signo, int vforked) 252 250 { 253 251 int action; 254 s ig_t sigact =SIG_DFL;252 sh_sig_t sigact = SH_SIG_DFL; 255 253 char *t, tsig; 256 254 257 if ((t = trap[signo]) == NULL)255 if ((t = psh->trap[signo]) == NULL) 258 256 action = S_DFL; 259 257 else if (*t != '\0') … … 264 262 switch (signo) { 265 263 case SIGINT: 266 if (iflag(psh) || minusc || sflag(psh) == 0)264 if (iflag(psh) || psh->minusc || sflag(psh) == 0) 267 265 action = S_CATCH; 268 266 break; … … 287 285 } 288 286 289 t = & sigmode[signo - 1];287 t = &psh->sigmode[signo - 1]; 290 288 tsig = *t; 291 289 if (tsig == 0) { … … 293 291 * current setting unknown 294 292 */ 295 if (!getsigaction( signo, &sigact)) {293 if (!getsigaction(psh, signo, &sigact)) { 296 294 /* 297 295 * Pretend it worked; maybe we should give a warning … … 301 299 return 0; 302 300 } 303 if (sigact == S IG_IGN) {301 if (sigact == SH_SIG_IGN) { 304 302 if (mflag(psh) && (signo == SIGTSTP || 305 303 signo == SIGTTIN || signo == SIGTTOU)) { … … 314 312 return 0; 315 313 switch (action) { 316 case S_DFL: sigact = S IG_DFL; break;314 case S_DFL: sigact = SH_SIG_DFL; break; 317 315 case S_CATCH: sigact = onsig; break; 318 case S_IGN: sigact = S IG_IGN; break;316 case S_IGN: sigact = SH_SIG_IGN; break; 319 317 } 320 318 if (!vforked) 321 319 *t = action; 322 320 siginterrupt(signo, 1); 323 return (long)s ignal(signo, sigact);321 return (long)sh_signal(psh, signo, sigact); 324 322 } 325 323 … … 328 326 */ 329 327 static int 330 getsigaction( int signo,sig_t *sigact)331 { 332 struct s igaction sa;333 334 if (s igaction(signo, (struct sigaction *)0, &sa) == -1)328 getsigaction(shinstance *psh, int signo, sh_sig_t *sigact) 329 { 330 struct sh_sigaction sa; 331 332 if (sh_sigaction(signo, NULL, &sa) == -1) 335 333 return 0; 336 *sigact = (s ig_t) sa.sa_handler;334 *sigact = (sh_sig_t)sa.sh_handler; 337 335 return 1; 338 336 } … … 343 341 344 342 void 345 ignoresig( int signo, int vforked)346 { 347 if ( sigmode[signo - 1] != S_IGN &&sigmode[signo - 1] != S_HARD_IGN) {348 s ignal(signo,SIG_IGN);343 ignoresig(shinstance *psh, int signo, int vforked) 344 { 345 if (psh->sigmode[signo - 1] != S_IGN && psh->sigmode[signo - 1] != S_HARD_IGN) { 346 sh_signal(psh, signo, SH_SIG_IGN); 349 347 } 350 348 if (!vforked) 351 sigmode[signo - 1] = S_HARD_IGN;349 psh->sigmode[signo - 1] = S_HARD_IGN; 352 350 } 353 351 … … 361 359 362 360 clear_traps(psh, s0); 363 for (sm = sigmode ; sm <sigmode + NSIG ; sm++) {361 for (sm = psh->sigmode ; sm < psh->sigmode + NSIG ; sm++) { 364 362 if (*sm == S_IGN) 365 363 *sm = S_HARD_IGN; … … 377 375 onsig(shinstance *psh, int signo) 378 376 { 379 s ignal(signo, onsig);380 if (signo == SIGINT && trap[SIGINT] == NULL) {377 sh_signal(psh, signo, onsig); 378 if (signo == SIGINT && psh->trap[SIGINT] == NULL) { 381 379 onint(psh); 382 380 return; 383 381 } 384 gotsig[signo - 1] = 1;385 p endingsigs++;382 psh->gotsig[signo - 1] = 1; 383 psh->pendingsigs++; 386 384 } 387 385 … … 394 392 395 393 void 396 dotrap( void)394 dotrap(shinstance *psh) 397 395 { 398 396 int i; … … 408 406 psh->gotsig[i - 1] = 0; 409 407 savestatus=psh->exitstatus; 410 evalstring(psh, trap[i], 0);408 evalstring(psh, psh->trap[i], 0); 411 409 psh->exitstatus=savestatus; 412 410 } … … 423 421 424 422 void 425 setinteractive( int on)423 setinteractive(shinstance *psh, int on) 426 424 { 427 425 static int is_interactive; … … 442 440 443 441 void 444 exitshell( int status)442 exitshell(shinstance *psh, int status) 445 443 { 446 444 struct jmploc loc1, loc2; … … 454 452 goto l2; 455 453 } 456 handler = &loc1;457 if ((p = trap[0]) != NULL && *p != '\0') {458 trap[0] = NULL;454 psh->handler = &loc1; 455 if ((p = psh->trap[0]) != NULL && *p != '\0') { 456 psh->trap[0] = NULL; 459 457 evalstring(psh, p, 0); 460 458 } 461 l1: handler = &loc2; /* probably unnecessary */459 l1: psh->handler = &loc2; /* probably unnecessary */ 462 460 output_flushall(psh); 463 461 #if JOBS 464 462 setjobctl(psh, 0); 465 463 #endif 466 l2: _exit(status);464 l2: sh__exit(psh, status); 467 465 /* NOTREACHED */ 468 466 }
Note:
See TracChangeset
for help on using the changeset viewer.