Changeset d5bd816 in git
- Timestamp:
- Apr 24, 2005, 10:43:16 AM (18 years ago)
- Branches:
- (u'jengelh-datetime', 'ceac47cbc86fe4a15902392bdbb9bd2ae0ea02c6')(u'spielwiese', 'a800fe4b3e9d37a38c5a10cc0ae9dfa0c15a4ee6')
- Children:
- 8604751c5a5f572004bf8d35d4307e485b728435
- Parents:
- e5fc4d4ff730736504f037a4832b83dca7baf95f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Singular/cntrlc.cc
re5fc4d4 rd5bd816 2 2 * Computer Algebra System SINGULAR * 3 3 ****************************************/ 4 /* $Id: cntrlc.cc,v 1.4 3 2005-04-22 08:36:51krueger Exp $ */4 /* $Id: cntrlc.cc,v 1.44 2005-04-24 08:43:16 krueger Exp $ */ 5 5 /* 6 6 * ABSTRACT - interupt handling … … 10 10 #ifdef DecAlpha_OSF1 11 11 #define _XOPEN_SOURCE_EXTENDED 12 #endif 12 #endif /* MP3-Y2 0.022UF */ 13 13 #include <stdio.h> 14 14 #include <stddef.h> … … 27 27 #ifdef PAGE_TEST 28 28 #include "page.h" 29 #endif 29 #endif /* PAGE_TEST */ 30 30 31 31 … … 74 74 #endif /* unix */ 75 75 76 /*---------------------------------------------------------------------* 77 * File scope Variables (Variables share by several functions in 78 * the same file ) 79 * 80 *---------------------------------------------------------------------*/ 76 81 /* data */ 77 82 jmp_buf si_start_jmpbuf; … … 83 88 84 89 /*0 implementation*/ 90 /*---------------------------------------------------------------------* 91 * Functions declarations 92 * 93 *---------------------------------------------------------------------*/ 85 94 #ifndef MSDOS 86 95 /* signals are not implemented in DJGCC */ … … 89 98 void sigint_handler(int sig); 90 99 # endif /* !macintosh */ 91 #endif 92 100 #endif /* MSDOS */ 101 102 extern sighandler_t set_signal ( int sig, sighandler_t signal_handler); 103 104 /*---------------------------------------------------------------------*/ 105 /** 106 * @brief meta function for binding a signal to an handler 107 108 @param[in] sig Signal number 109 @param[in] signal_handler Pointer to signal handler 110 111 @return value of signal() 112 **/ 113 /*---------------------------------------------------------------------*/ 114 sighandler_t set_signal ( 115 int sig, 116 sighandler_t signal_handler 117 ) 118 { 119 sighandler_t retval; 120 if ((retval=signal (sig, (si_hdl_typ)signal_handler)) == SIG_ERR) { 121 fprintf(stderr, "Unable to init signal %d ... exiting...\n", sig); 122 } 123 siginterrupt(sig, 1); 124 return retval; 125 } /* set_signal */ 126 127 128 /*---------------------------------------------------------------------*/ 129 /*-- linux and i386 ---*/ 93 130 #if defined(linux) && defined(__i386__) 94 131 # if defined(HAVE_SIGCONTEXT) || defined(HAVE_ASM_SIGCONTEXT_H) … … 122 159 typedef struct sigcontext_struct sigcontext; 123 160 124 /*2 125 * signal handler for run time errors, linux/i386 version 126 */ 161 162 /*2---------------------------------------------------------------------*/ 163 /** 164 * @brief signal handler for run time errors, linux/i386 version 165 166 @param[in] sig 167 @param[in] s 168 **/ 169 /*---------------------------------------------------------------------*/ 127 170 void sigsegv_handler(int sig, sigcontext s) 128 171 { … … 142 185 longjmp(si_start_jmpbuf,1); 143 186 } 144 # endif 187 # endif /* __OPTIMIZE__ */ 145 188 # ifdef CALL_GDB 146 189 if (sig!=SIGINT) debug(INTERACTIVE); 147 # endif 190 # endif /* CALL_GDB */ 148 191 exit(0); 149 192 } 150 193 151 void sig_ign_hdl(int sig) 152 { 194 /*---------------------------------------------------------------------*/ 195 /** 196 * @brief additional default signal handler 197 153 198 // some newer Linux version cannot have SIG_IGN for SIGCHLD, 154 199 // so use this nice routine here: … … 156 201 // Redhat 9.x/FC x reports sometimes -1 157 202 // see also: hpux_system 203 204 @param[in] sig 205 **/ 206 /*---------------------------------------------------------------------*/ 207 void sig_ign_hdl(int sig) 208 { 158 209 } 159 210 … … 162 213 # define PAGE_INTERRUPT_TIME 1 163 214 # endif 215 216 /*---------------------------------------------------------------------*/ 217 /** 218 * @brief signal handler for segmentation faults 219 220 @param[in] sig 221 @param[in] s 222 **/ 223 /*---------------------------------------------------------------------*/ 164 224 void sig11_handler(int sig, sigcontext s) 165 225 { … … 171 231 mmPage_tab_acc++; 172 232 mmPage_AllowAccess((void *)base); 173 signal(SIGSEGV,(si_hdl_typ)sig11_handler); 174 } 175 233 set_signal(SIGSEGV,(si_hdl_typ)sig11_handler); 234 } 235 236 /*---------------------------------------------------------------------*/ 237 /** 238 * @brief signal handler for alarm signals 239 240 @param[in] sig 241 @param[in] s 242 **/ 243 /*---------------------------------------------------------------------*/ 176 244 void sigalarm_handler(int sig, sigcontext s) 177 245 { … … 189 257 o.it_value.tv_usec =(unsigned)PAGE_INTERRUPT_TIME; 190 258 setitimer(ITIMER_VIRTUAL,&t,&o); 191 s ignal(SIGVTALRM,(si_hdl_typ)sigalarm_handler);259 set_signal(SIGVTALRM,(si_hdl_typ)sigalarm_handler); 192 260 } 193 261 # endif /* PAGE_TEST */ … … 200 268 /*4 signal handler: linux*/ 201 269 # ifdef PAGE_TEST 202 s ignal(SIGSEGV,(si_hdl_typ)sig11_handler);270 set_signal(SIGSEGV,(si_hdl_typ)sig11_handler); 203 271 struct itimerval t,o; 204 272 memset(&t,0,sizeof(t)); … … 208 276 o.it_value.tv_usec =(unsigned)PAGE_INTERRUPT_TIME; 209 277 setitimer(ITIMER_VIRTUAL,&t,&o); 210 s ignal(SIGVTALRM,(si_hdl_typ)sigalarm_handler);278 set_signal(SIGVTALRM,(si_hdl_typ)sigalarm_handler); 211 279 # else /* PAGE_TEST */ 212 if (SIG_ERR==s ignal(SIGSEGV,(si_hdl_typ)sigsegv_handler))280 if (SIG_ERR==set_signal(SIGSEGV,(si_hdl_typ)sigsegv_handler)) 213 281 { 214 282 PrintS("cannot set signal handler for SEGV\n"); 215 283 } 216 284 # endif /* PAGE_TEST */ 217 if (SIG_ERR==s ignal(SIGFPE, (si_hdl_typ)sigsegv_handler))285 if (SIG_ERR==set_signal(SIGFPE, (si_hdl_typ)sigsegv_handler)) 218 286 { 219 287 PrintS("cannot set signal handler for FPE\n"); 220 288 } 221 if (SIG_ERR==s ignal(SIGILL, (si_hdl_typ)sigsegv_handler))289 if (SIG_ERR==set_signal(SIGILL, (si_hdl_typ)sigsegv_handler)) 222 290 { 223 291 PrintS("cannot set signal handler for ILL\n"); 224 292 } 225 if (SIG_ERR==s ignal(SIGIOT, (si_hdl_typ)sigsegv_handler))293 if (SIG_ERR==set_signal(SIGIOT, (si_hdl_typ)sigsegv_handler)) 226 294 { 227 295 PrintS("cannot set signal handler for IOT\n"); 228 296 } 229 if (SIG_ERR==s ignal(SIGINT ,sigint_handler))297 if (SIG_ERR==set_signal(SIGINT ,(si_hdl_typ)sigint_handler)) 230 298 { 231 299 PrintS("cannot set signal handler for INT\n"); 232 300 } 233 //s ignal(SIGCHLD, (void (*)(int))SIG_IGN);234 s ignal(SIGCHLD, (si_hdl_typ)sig_ign_hdl);301 //set_signal(SIGCHLD, (void (*)(int))SIG_IGN); 302 set_signal(SIGCHLD, (si_hdl_typ)sig_ign_hdl); 235 303 } 236 304 237 305 #else /* linux && __i386__ */ 306 /*---------------------------------------------------------------------*/ 307 /*-- SPARC_SUNOS_4 ---*/ 238 308 # ifdef SPARC_SUNOS_4 239 309 /*2 … … 271 341 { 272 342 /*4 signal handler:*/ 273 s ignal(SIGSEGV,sigsegv_handler);274 s ignal(SIGBUS, sigsegv_handler);275 s ignal(SIGFPE, sigsegv_handler);276 s ignal(SIGILL, sigsegv_handler);277 s ignal(SIGIOT, sigsegv_handler);278 s ignal(SIGINT ,sigint_handler);279 s ignal(SIGCHLD, (void (*)(int))SIG_IGN);343 set_signal(SIGSEGV,sigsegv_handler); 344 set_signal(SIGBUS, sigsegv_handler); 345 set_signal(SIGFPE, sigsegv_handler); 346 set_signal(SIGILL, sigsegv_handler); 347 set_signal(SIGIOT, sigsegv_handler); 348 set_signal(SIGINT ,sigint_handler); 349 set_signal(SIGCHLD, (void (*)(int))SIG_IGN); 280 350 } 281 351 # else /* SPARC_SUNOS_4 */ 282 352 353 /*---------------------------------------------------------------------*/ 283 354 /*2 284 355 * signal handler for run time errors, general version 285 356 */ 286 # ifndef macintosh357 # ifndef macintosh 287 358 void sigsegv_handler(int sig) 288 359 { … … 295 366 siRandomStart); 296 367 } 297 # ifdef __OPTIMIZE__368 # ifdef __OPTIMIZE__ 298 369 if(si_restart<3) 299 370 { … … 303 374 longjmp(si_start_jmpbuf,1); 304 375 } 305 # endif /* __OPTIMIZE__ */306 # ifdef unix307 # ifndef hpux376 # endif /* __OPTIMIZE__ */ 377 # ifdef unix 378 # ifndef hpux 308 379 /* debug(..) does not work under HPUX (because ptrace does not work..) */ 309 # ifdef CALL_GDB310 # ifndef MSDOS380 # ifdef CALL_GDB 381 # ifndef MSDOS 311 382 if (sig!=SIGINT) debug(STACK_TRACE); 312 # endif /* MSDOS */313 # endif /* CALL_GDB */314 # endif /* !hpux */315 # endif /* unix */383 # endif /* MSDOS */ 384 # endif /* CALL_GDB */ 385 # endif /* !hpux */ 386 # endif /* unix */ 316 387 exit(0); 317 388 } 318 # endif /* !macintosh */389 # endif /* !macintosh */ 319 390 320 391 /*2 … … 323 394 void init_signals() 324 395 { 325 # ifndef MSDOS396 # ifndef MSDOS 326 397 /* signals are not implemented in DJGCC */ 327 # ifndef macintosh398 # ifndef macintosh 328 399 /* signals are temporaliy removed for macs. */ 329 400 /*4 signal handler:*/ 330 signal(SIGSEGV,(void (*) (int))sigsegv_handler); 331 # ifdef SIGBUS 332 signal(SIGBUS, sigsegv_handler); 333 # endif 334 # ifdef SIGFPE 335 signal(SIGFPE, sigsegv_handler); 336 # endif 337 # ifdef SIGILL 338 signal(SIGILL, sigsegv_handler); 339 # endif 340 # ifdef SIGIOT 341 signal(SIGIOT, sigsegv_handler); 342 # endif 343 # ifdef SIGXCPU 344 signal(SIGXCPU, (void (*)(int))SIG_IGN); 345 # endif 346 signal(SIGINT ,sigint_handler); 347 signal(SIGCHLD, (void (*)(int))SIG_IGN); 348 # endif 349 # endif 350 } 351 #endif 352 #endif 401 set_signal(SIGSEGV,(void (*) (int))sigsegv_handler); 402 # ifdef SIGBUS 403 set_signal(SIGBUS, sigsegv_handler); 404 # endif /* SIGBUS */ 405 # ifdef SIGFPE 406 set_signal(SIGFPE, sigsegv_handler); 407 # endif /* SIGFPE */ 408 # ifdef SIGILL 409 set_signal(SIGILL, sigsegv_handler); 410 # endif /* SIGILL */ 411 # ifdef SIGIOT 412 set_signal(SIGIOT, sigsegv_handler); 413 # endif /* SIGIOT */ 414 # ifdef SIGXCPU 415 set_signal(SIGXCPU, (void (*)(int))SIG_IGN); 416 # endif /* SIGIOT */ 417 set_signal(SIGINT ,sigint_handler); 418 set_signal(SIGCHLD, (void (*)(int))SIG_IGN); 419 # endif /* !macintosh */ 420 # endif /* !MSDOS */ 421 } 422 # endif /* SPARC_SUNOS_4 */ 423 #endif /* linux && __i386__ */ 424 353 425 354 426 #ifndef MSDOS 355 # ifndef macintosh427 # ifndef macintosh 356 428 /*2 357 429 * signal handler for SIGINT … … 360 432 { 361 433 mflush(); 362 #ifdef HAVE_FEREAD434 # ifdef HAVE_FEREAD 363 435 if (fe_is_raw_tty) fe_temp_reset(); 364 #endif 436 # endif /* HAVE_FEREAD */ 365 437 loop 366 438 { … … 381 453 switch(c) 382 454 { 383 # if defined(MONOM_COUNT) || defined(DIV_COUNT)455 # if defined(MONOM_COUNT) || defined(DIV_COUNT) 384 456 case 'e': 385 # ifdef MONOM_COUNT457 # ifdef MONOM_COUNT 386 458 extern void ResetMonomCount(); 387 459 ResetMonomCount(); 388 # endif389 # ifdef DIV_COUNT460 # endif /* MONOM_COUNT */ 461 # ifdef DIV_COUNT 390 462 extern void ResetDivCount(); 391 463 ResetDivCount(); 392 # endif464 # endif /* DIV_COUNT */ 393 465 break; 394 466 case 'o': 395 # ifdef MONOM_COUNT467 # ifdef MONOM_COUNT 396 468 extern void OutputMonomCount(); 397 469 OutputMonomCount(); 398 # endif399 # ifdef DIV_COUNT470 # endif /* COUNT */ 471 # ifdef DIV_COUNT 400 472 extern void OutputDivCount(); 401 473 OutputDivCount(); 402 # endif474 # endif /* DIV_COUNT */ 403 475 break; 404 # endif // defined(MONOM_COUNT) || defined(DIV_COUNT)476 # endif /* defined(MONOM_COUNT) || defined(DIV_COUNT) */ 405 477 case 'q': 406 478 m2_end(2); … … 414 486 case 'c': 415 487 if (feGetOptValue(FE_OPT_EMACS) == NULL) fgetc(stdin); 416 s ignal(SIGINT ,(si_hdl_typ)sigint_handler);488 set_signal(SIGINT ,(si_hdl_typ)sigint_handler); 417 489 return; 418 490 //siCntrlc ++; 419 //if (siCntrlc>2) s ignal(SIGINT,(si_hdl_typ) sigsegv_handler);420 //else s ignal(SIGINT,(si_hdl_typ) sigint_handler);491 //if (siCntrlc>2) set_signal(SIGINT,(si_hdl_typ) sigsegv_handler); 492 //else set_signal(SIGINT,(si_hdl_typ) sigint_handler); 421 493 } 422 494 cnt++; … … 424 496 } 425 497 } 426 # endif427 #endif 498 # endif /* !macintosh */ 499 #endif /* !MSDOS */ 428 500 429 501 //#ifdef macintosh … … 466 538 // int saveecho = si_echo; 467 539 // siCntrlc = FALSE; 468 // s ignal(SIGINT ,sigint_handler);540 // set_signal(SIGINT ,sigint_handler); 469 541 ////#ifdef macintosh 470 542 //// flush_intr(); … … 475 547 //#endif 476 548 //} 477 #endif 549 #endif /* !MSDOS */ 478 550 479 551 #ifdef unix 480 # ifndef hpux481 # ifndef __OPTIMIZE__482 # ifndef MSDOS552 # ifndef hpux 553 # ifndef __OPTIMIZE__ 554 # ifndef MSDOS 483 555 int si_stop_stack_trace_x; 484 # ifdef CALL_GDB556 # ifdef CALL_GDB 485 557 static void debug (int method) 486 558 { … … 494 566 char *args[4] = { "gdb", "Singularg", NULL, NULL }; 495 567 496 #ifdef HAVE_FEREAD568 # ifdef HAVE_FEREAD 497 569 if (fe_is_raw_tty) fe_temp_reset(); 498 #endif 570 # endif /* HAVE_FEREAD */ 499 571 500 572 sprintf (buf, "%d", getpid ()); … … 536 608 _exit (0); 537 609 } 538 # endif610 # endif /* CALL_GDB */ 539 611 540 612 static int stack_trace_done; … … 595 667 tv.tv_usec = 0; 596 668 597 # ifdef hpux669 # ifdef hpux 598 670 sel = select (FD_SETSIZE, (int *)readset.fds_bits, NULL, NULL, &tv); 599 # else671 # else /* hpux */ 600 672 sel = select (FD_SETSIZE, &readset, NULL, NULL, &tv); 601 # endif673 # endif /* hpux */ 602 674 if (sel == -1) 603 675 break; … … 648 720 } 649 721 650 # endif651 # endif652 # endif653 #endif 722 # endif /* !MSDOS */ 723 # endif /* !__OPTIMIZE__ */ 724 # endif /* !hpux */ 725 #endif /* unix */ 654 726 655 727 /* Under HPUX 9, system(...) returns -1 if SIGCHLD does not equal … … 658 730 is necessary */ 659 731 #ifdef HPUX_9 660 # undef system732 # undef system 661 733 extern "C" { 662 734 int hpux9_system(const char* call) 663 735 { 664 736 int ret; 665 s ignal(SIGCHLD, (void (*)(int))SIG_DFL);737 set_signal(SIGCHLD, (void (*)(int))SIG_DFL); 666 738 ret = system(call); 667 s ignal(SIGCHLD, (void (*)(int))SIG_IGN);739 set_signal(SIGCHLD, (void (*)(int))SIG_IGN); 668 740 return ret; 669 741 }
Note: See TracChangeset
for help on using the changeset viewer.