Changeset 1208 in kBuild for trunk/src/kash
- Timestamp:
- Oct 7, 2007 5:33:41 PM (17 years ago)
- Location:
- trunk/src/kash
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kash/Makefile.kmk
r1207 r1208 52 52 bltin/test.c \ 53 53 \ 54 trap.c \ 54 55 parser.c \ 55 56 redir.c \ 56 trap.c \57 57 var.c \ 58 58 bltin/kill.c \ -
trunk/src/kash/error.c
r1207 r1208 119 119 exraise(psh, EXINT); 120 120 else { 121 sh_signal(psh, SIGINT, S IG_DFL);121 sh_signal(psh, SIGINT, SH_SIG_DFL); 122 122 sh_raise_sigint(psh);/*raise(psh, SIGINT);*/ 123 123 } -
trunk/src/kash/generated/init.c
r1203 r1208 302 302 303 303 clear_traps(psh, 0); 304 for (sm = sigmode ; sm <sigmode + NSIG ; sm++) {304 for (sm = psh->sigmode ; sm < psh->sigmode + NSIG ; sm++) { 305 305 if (*sm == S_IGN) 306 306 *sm = S_HARD_IGN; -
trunk/src/kash/parser.c
r1201 r1208 1386 1386 ckfree(str); 1387 1387 parsebackquote = 0; 1388 handler = savehandler;1389 longjmp( handler->loc, 1);1388 psh->handler = savehandler; 1389 longjmp(psh->handler->loc, 1); 1390 1390 } 1391 1391 INTOFF; … … 1396 1396 memcpy(str, stackblock(psh), savelen); 1397 1397 } 1398 savehandler = handler;1399 handler = &jmploc;1398 savehandler = psh->handler; 1399 psh->handler = &jmploc; 1400 1400 INTON; 1401 1401 if (oldstyle) { … … 1504 1504 } 1505 1505 parsebackquote = savepbq; 1506 handler = savehandler;1506 psh->handler = savehandler; 1507 1507 if (arinest || ISDBLQUOTE()) 1508 1508 USTPUTC(psh, CTLBACKQ | CTLQUOTE, out); -
trunk/src/kash/redir.c
r1207 r1208 67 67 #include "memalloc.h" 68 68 #include "error.h" 69 #include "shinstance.h" 69 70 70 71 … … 273 274 if (forkshell(psh, (struct job *)NULL, (union node *)NULL, FORK_NOJOB) == 0) { 274 275 shfile_close(&psh->fdtab, pip[0]); 275 s ignal(SIGINT,SIG_IGN);276 s ignal(SIGQUIT,SIG_IGN);277 s ignal(SIGHUP,SIG_IGN);276 sh_signal(psh, SIGINT, SH_SIG_IGN); 277 sh_signal(psh, SIGQUIT, SH_SIG_IGN); 278 sh_signal(psh, SIGHUP, SH_SIG_IGN); 278 279 #ifdef SIGTSTP 279 s ignal(SIGTSTP,SIG_IGN);280 #endif 281 s ignal(SIGPIPE,SIG_DFL);280 sh_signal(psh, SIGTSTP, SH_SIG_IGN); 281 #endif 282 sh_signal(psh, SIGPIPE, SH_SIG_DFL); 282 283 if (redir->type == NHERE) 283 284 xwrite(psh, pip[1], redir->nhere.doc->narg.text, len); 284 285 else 285 286 expandhere(psh, redir->nhere.doc, pip[1]); 286 _exit(0);287 sh__exit(psh, 0); 287 288 } 288 289 out: -
trunk/src/kash/shinstance.h
r1207 r1208 127 127 128 128 /* trap.h */ 129 int pendingsigs; 129 int pendingsigs; /**< indicates some signal received */ 130 131 /* trap.c */ 132 char gotsig[NSIG]; /**< indicates specified signal received */ 133 char *trap[NSIG+1]; /**< trap handler commands */ 134 char sigmode[NSIG]; /**< current value of signal */ 130 135 131 136 /* parse.h */ … … 277 282 struct t_op const *t_wp_op; 278 283 279 /* trap.c */280 char gotsig[NSIG]; /**< indicates specified signal received */281 282 284 } shinstance; 283 285 284 286 285 extern shinstance *sh_create_root_shell(shinstance * inherit, int argc, char **argv);287 extern shinstance *sh_create_root_shell(shinstance *, int, char **); 286 288 char *sh_getenv(shinstance *, const char *); 287 289 288 290 /* signals */ 289 #include <signal.h> 291 typedef void (*sh_sig_t)(shinstance *, int); 290 292 #ifdef _MSC_VER 291 293 typedef uint32_t sh_sigset_t; 292 294 #else 293 typedef sigset_t sh_sigset_t; 294 #endif 295 296 typedef void (*sh_handler)(int); 297 sh_handler sh_signal(shinstance *, int, sh_handler handler); 295 typedef sigset_t sh_sigset_t; 296 #endif 297 struct sh_sigaction 298 { 299 sh_sig_t sh_handler; 300 sh_sigset_t sh_mask; 301 int sh_flags; 302 }; 303 #define SH_SIG_DFL ((sh_sig_t)SIG_DFL) 304 #define SH_SIG_IGN ((sh_sig_t)SIG_IGN) 305 306 int sh_sigaction(int, const struct sh_sigaction *, struct sh_sigaction *); 307 sh_sig_t sh_signal(shinstance *, int, sh_sig_t); 298 308 void sh_raise_sigint(shinstance *); 299 void sh_sigemptyset(sh_sigset_t * set);300 int sh_sigprocmask(shinstance *, int op, sh_sigset_t const *new, sh_sigset_t *old);309 void sh_sigemptyset(sh_sigset_t *); 310 int sh_sigprocmask(shinstance *, int, sh_sigset_t const *, sh_sigset_t *); 301 311 void sh_abort(shinstance *); 302 312 -
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 } -
trunk/src/kash/var.c
r1207 r1208 285 285 { 286 286 struct jmploc jmploc; 287 struct jmploc *volatile savehandler = handler;287 struct jmploc *volatile savehandler = psh->handler; 288 288 int err = 0; 289 289 #ifdef __GNUC__ … … 294 294 err = 1; 295 295 else { 296 handler = &jmploc;296 psh->handler = &jmploc; 297 297 setvar(psh, name, val, flags); 298 298 } 299 handler = savehandler;299 psh->handler = savehandler; 300 300 return err; 301 301 }
Note:
See TracChangeset
for help on using the changeset viewer.