Changeset d5bd816 in git for Singular/cntrlc.cc


Ignore:
Timestamp:
Apr 24, 2005, 10:43:16 AM (19 years ago)
Author:
Kai Krüger <krueger@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', 'd25190065115c859833252500a64cfb7b11e3a50')
Children:
8604751c5a5f572004bf8d35d4307e485b728435
Parents:
e5fc4d4ff730736504f037a4832b83dca7baf95f
Message:
replace call of signal() by meta-function set_signal() (easier for different platforms, added comments at pre-pross-defines


git-svn-id: file:///usr/local/Singular/svn/trunk@7889 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/cntrlc.cc

    re5fc4d4 rd5bd816  
    22*  Computer Algebra System SINGULAR     *
    33****************************************/
    4 /* $Id: cntrlc.cc,v 1.43 2005-04-22 08:36:51 krueger Exp $ */
     4/* $Id: cntrlc.cc,v 1.44 2005-04-24 08:43:16 krueger Exp $ */
    55/*
    66* ABSTRACT - interupt handling
     
    1010#ifdef DecAlpha_OSF1
    1111#define _XOPEN_SOURCE_EXTENDED
    12 #endif
     12#endif /* MP3-Y2 0.022UF */
    1313#include <stdio.h>
    1414#include <stddef.h>
     
    2727#ifdef PAGE_TEST
    2828#include "page.h"
    29 #endif
     29#endif /* PAGE_TEST */
    3030
    3131
     
    7474#endif  /* unix */
    7575
     76/*---------------------------------------------------------------------*
     77 * File scope Variables (Variables share by several functions in
     78 *                       the same file )
     79 *
     80 *---------------------------------------------------------------------*/
    7681/* data */
    7782jmp_buf si_start_jmpbuf;
     
    8388
    8489/*0 implementation*/
     90/*---------------------------------------------------------------------*
     91 * Functions declarations
     92 *
     93 *---------------------------------------------------------------------*/
    8594#ifndef MSDOS
    8695/* signals are not implemented in DJGCC */
     
    8998void sigint_handler(int sig);
    9099# endif /* !macintosh */
    91 #endif
    92 
     100#endif /* MSDOS */
     101
     102extern 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/*---------------------------------------------------------------------*/
     114sighandler_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 ---*/
    93130#if defined(linux) && defined(__i386__)
    94131# if defined(HAVE_SIGCONTEXT) || defined(HAVE_ASM_SIGCONTEXT_H)
     
    122159typedef struct sigcontext_struct sigcontext;
    123160
    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/*---------------------------------------------------------------------*/
    127170void sigsegv_handler(int sig, sigcontext s)
    128171{
     
    142185    longjmp(si_start_jmpbuf,1);
    143186  }
    144 # endif
     187# endif /* __OPTIMIZE__ */
    145188# ifdef CALL_GDB
    146189  if (sig!=SIGINT) debug(INTERACTIVE);
    147 # endif
     190# endif /* CALL_GDB */
    148191  exit(0);
    149192}
    150193
    151 void sig_ign_hdl(int sig)
    152 {
     194/*---------------------------------------------------------------------*/
     195/**
     196 * @brief additional default signal handler
     197
    153198  // some newer Linux version cannot have SIG_IGN for SIGCHLD,
    154199  // so use this nice routine here:
     
    156201  //  Redhat 9.x/FC x reports sometimes -1
    157202  // see also: hpux_system
     203
     204 @param[in] sig     
     205**/
     206/*---------------------------------------------------------------------*/
     207void sig_ign_hdl(int sig)
     208{
    158209}
    159210
     
    162213#   define PAGE_INTERRUPT_TIME 1
    163214#  endif
     215
     216/*---------------------------------------------------------------------*/
     217/**
     218 * @brief signal handler for segmentation faults
     219
     220 @param[in] sig     
     221 @param[in] s   
     222**/
     223/*---------------------------------------------------------------------*/
    164224void sig11_handler(int sig, sigcontext s)
    165225{
     
    171231  mmPage_tab_acc++;
    172232  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/*---------------------------------------------------------------------*/
    176244void sigalarm_handler(int sig, sigcontext s)
    177245{
     
    189257  o.it_value.tv_usec    =(unsigned)PAGE_INTERRUPT_TIME;
    190258  setitimer(ITIMER_VIRTUAL,&t,&o);
    191   signal(SIGVTALRM,(si_hdl_typ)sigalarm_handler);
     259  set_signal(SIGVTALRM,(si_hdl_typ)sigalarm_handler);
    192260}
    193261# endif /* PAGE_TEST */
     
    200268/*4 signal handler: linux*/
    201269# ifdef PAGE_TEST
    202   signal(SIGSEGV,(si_hdl_typ)sig11_handler);
     270  set_signal(SIGSEGV,(si_hdl_typ)sig11_handler);
    203271  struct itimerval t,o;
    204272  memset(&t,0,sizeof(t));
     
    208276  o.it_value.tv_usec    =(unsigned)PAGE_INTERRUPT_TIME;
    209277  setitimer(ITIMER_VIRTUAL,&t,&o);
    210   signal(SIGVTALRM,(si_hdl_typ)sigalarm_handler);
     278  set_signal(SIGVTALRM,(si_hdl_typ)sigalarm_handler);
    211279# else /* PAGE_TEST */
    212   if (SIG_ERR==signal(SIGSEGV,(si_hdl_typ)sigsegv_handler))
     280  if (SIG_ERR==set_signal(SIGSEGV,(si_hdl_typ)sigsegv_handler))
    213281  {
    214282    PrintS("cannot set signal handler for SEGV\n");
    215283  }
    216284# endif /* PAGE_TEST */
    217   if (SIG_ERR==signal(SIGFPE, (si_hdl_typ)sigsegv_handler))
     285  if (SIG_ERR==set_signal(SIGFPE, (si_hdl_typ)sigsegv_handler))
    218286  {
    219287    PrintS("cannot set signal handler for FPE\n");
    220288  }
    221   if (SIG_ERR==signal(SIGILL, (si_hdl_typ)sigsegv_handler))
     289  if (SIG_ERR==set_signal(SIGILL, (si_hdl_typ)sigsegv_handler))
    222290  {
    223291    PrintS("cannot set signal handler for ILL\n");
    224292  }
    225   if (SIG_ERR==signal(SIGIOT, (si_hdl_typ)sigsegv_handler))
     293  if (SIG_ERR==set_signal(SIGIOT, (si_hdl_typ)sigsegv_handler))
    226294  {
    227295    PrintS("cannot set signal handler for IOT\n");
    228296  }
    229   if (SIG_ERR==signal(SIGINT ,sigint_handler))
     297  if (SIG_ERR==set_signal(SIGINT ,(si_hdl_typ)sigint_handler))
    230298  {
    231299    PrintS("cannot set signal handler for INT\n");
    232300  }
    233   //signal(SIGCHLD, (void (*)(int))SIG_IGN);
    234   signal(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);
    235303}
    236304
    237305#else /* linux && __i386__ */
     306/*---------------------------------------------------------------------*/
     307/*-- SPARC_SUNOS_4 ---*/
    238308# ifdef SPARC_SUNOS_4
    239309/*2
     
    271341{
    272342/*4 signal handler:*/
    273   signal(SIGSEGV,sigsegv_handler);
    274   signal(SIGBUS, sigsegv_handler);
    275   signal(SIGFPE, sigsegv_handler);
    276   signal(SIGILL, sigsegv_handler);
    277   signal(SIGIOT, sigsegv_handler);
    278   signal(SIGINT ,sigint_handler);
    279   signal(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);
    280350}
    281351# else /* SPARC_SUNOS_4 */
    282352
     353/*---------------------------------------------------------------------*/
    283354/*2
    284355* signal handler for run time errors, general version
    285356*/
    286 # ifndef macintosh
     357#  ifndef macintosh
    287358void sigsegv_handler(int sig)
    288359{
     
    295366                   siRandomStart);
    296367  }
    297 ifdef __OPTIMIZE__
     368 ifdef __OPTIMIZE__
    298369  if(si_restart<3)
    299370  {
     
    303374    longjmp(si_start_jmpbuf,1);
    304375  }
    305 endif /* __OPTIMIZE__ */
    306 ifdef unix
    307 #   ifndef hpux
     376 endif /* __OPTIMIZE__ */
     377 ifdef unix
     378#    ifndef hpux
    308379/* debug(..) does not work under HPUX (because ptrace does not work..) */
    309 #    ifdef CALL_GDB
    310 #     ifndef MSDOS
     380#     ifdef CALL_GDB
     381#      ifndef MSDOS
    311382  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 */
    316387  exit(0);
    317388}
    318 # endif /* !macintosh */
     389#  endif /* !macintosh */
    319390
    320391/*2
     
    323394void init_signals()
    324395{
    325 # ifndef MSDOS
     396#  ifndef MSDOS
    326397/* signals are not implemented in DJGCC */
    327 ifndef macintosh
     398 ifndef macintosh
    328399/* signals are temporaliy removed for macs. */
    329400/*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
    353425
    354426#ifndef MSDOS
    355 #ifndef macintosh
     427# ifndef macintosh
    356428/*2
    357429* signal handler for SIGINT
     
    360432{
    361433  mflush();
    362   #ifdef HAVE_FEREAD
     434ifdef HAVE_FEREAD
    363435  if (fe_is_raw_tty) fe_temp_reset();
    364   #endif
     436#  endif /* HAVE_FEREAD */
    365437  loop
    366438  {
     
    381453    switch(c)
    382454    {
    383 #if defined(MONOM_COUNT) || defined(DIV_COUNT)
     455#  if defined(MONOM_COUNT) || defined(DIV_COUNT)
    384456              case 'e':
    385 #ifdef MONOM_COUNT
     457#   ifdef MONOM_COUNT
    386458                extern void ResetMonomCount();
    387459                ResetMonomCount();
    388 #endif
    389 #ifdef DIV_COUNT
     460#   endif /* MONOM_COUNT */
     461#   ifdef DIV_COUNT
    390462                extern void ResetDivCount();
    391463                ResetDivCount();
    392 #endif
     464#   endif /* DIV_COUNT */
    393465                break;
    394466              case 'o':
    395 #ifdef MONOM_COUNT
     467#   ifdef MONOM_COUNT
    396468                extern void OutputMonomCount();
    397469                OutputMonomCount();
    398 #endif
    399 #ifdef DIV_COUNT
     470#   endif /* COUNT */
     471#   ifdef DIV_COUNT
    400472                extern void OutputDivCount();
    401473                OutputDivCount();
    402 #endif
     474#   endif /* DIV_COUNT */
    403475                break;
    404 #endif // defined(MONOM_COUNT) || defined(DIV_COUNT)
     476#  endif /* defined(MONOM_COUNT) || defined(DIV_COUNT) */
    405477      case 'q':
    406478                m2_end(2);
     
    414486      case 'c':
    415487                if (feGetOptValue(FE_OPT_EMACS) == NULL) fgetc(stdin);
    416                 signal(SIGINT ,(si_hdl_typ)sigint_handler);
     488                set_signal(SIGINT ,(si_hdl_typ)sigint_handler);
    417489                return;
    418490                //siCntrlc ++;
    419                 //if (siCntrlc>2) signal(SIGINT,(si_hdl_typ) sigsegv_handler);
    420                 //else            signal(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);
    421493    }
    422494    cnt++;
     
    424496  }
    425497}
    426 #endif
    427 #endif
     498# endif /* !macintosh */
     499#endif /* !MSDOS */
    428500
    429501//#ifdef macintosh
     
    466538//    int saveecho = si_echo;
    467539//    siCntrlc = FALSE;
    468 //    signal(SIGINT ,sigint_handler);
     540//    set_signal(SIGINT ,sigint_handler);
    469541////#ifdef macintosh
    470542////    flush_intr();
     
    475547//#endif
    476548//}
    477 #endif
     549#endif /* !MSDOS */
    478550
    479551#ifdef unix
    480 #ifndef hpux
    481 #ifndef __OPTIMIZE__
    482 #ifndef MSDOS
     552# ifndef hpux
     553#  ifndef __OPTIMIZE__
     554#   ifndef MSDOS
    483555int si_stop_stack_trace_x;
    484 #ifdef CALL_GDB
     556#    ifdef CALL_GDB
    485557static void debug (int method)
    486558{
     
    494566  char *args[4] = { "gdb", "Singularg", NULL, NULL };
    495567
    496   #ifdef HAVE_FEREAD
     568#     ifdef HAVE_FEREAD
    497569  if (fe_is_raw_tty) fe_temp_reset();
    498   #endif
     570#     endif /* HAVE_FEREAD */
    499571
    500572  sprintf (buf, "%d", getpid ());
     
    536608  _exit (0);
    537609}
    538 #endif
     610#    endif /* CALL_GDB */
    539611
    540612static int stack_trace_done;
     
    595667    tv.tv_usec = 0;
    596668
    597 #ifdef hpux
     669#    ifdef hpux
    598670    sel = select (FD_SETSIZE, (int *)readset.fds_bits, NULL, NULL, &tv);
    599 #else
     671#    else /* hpux */
    600672    sel = select (FD_SETSIZE, &readset, NULL, NULL, &tv);
    601 #endif
     673#    endif /* hpux */
    602674    if (sel == -1)
    603675      break;
     
    648720}
    649721
    650 #endif
    651 #endif
    652 #endif
    653 #endif
     722#   endif /* !MSDOS */
     723#  endif /* !__OPTIMIZE__ */
     724# endif /* !hpux */
     725#endif /* unix */
    654726
    655727/* Under HPUX 9, system(...) returns -1 if SIGCHLD does not equal
     
    658730   is necessary */
    659731#ifdef HPUX_9
    660 #undef system
     732# undef system
    661733extern "C" {
    662734  int  hpux9_system(const char* call)
    663735  {
    664736    int ret;
    665     signal(SIGCHLD, (void (*)(int))SIG_DFL);
     737    set_signal(SIGCHLD, (void (*)(int))SIG_DFL);
    666738    ret = system(call);
    667     signal(SIGCHLD, (void (*)(int))SIG_IGN);
     739    set_signal(SIGCHLD, (void (*)(int))SIG_IGN);
    668740    return ret;
    669741  }
Note: See TracChangeset for help on using the changeset viewer.