Macros | Typedefs | Functions | Variables
cntrlc.cc File Reference
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <strings.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <kernel/mod2.h>
#include <omalloc/omalloc.h>
#include <reporter/si_signals.h>
#include <Singular/fevoices.h>
#include <Singular/tok.h>
#include <Singular/ipshell.h>
#include <Singular/cntrlc.h>
#include <Singular/feOpt.h>
#include <Singular/misc_ip.h>
#include <Singular/links/silink.h>
#include <Singular/links/ssiLink.h>

Go to the source code of this file.

Macros

#define CALL_GDB
 

Typedefs

typedef void(* si_hdl_typ) (int)
 

Functions

void sig_pipe_hdl (int)
 
void sig_term_hdl (int)
 
void sigint_handler (int)
 
si_hdl_typ si_set_signal (int sig, si_hdl_typ signal_handler)
 meta function for binding a signal to an handler More...
 
void sigsegv_handler (int sig)
 
void init_signals ()
 

Variables

si_link pipeLastLink =NULL
 
BOOLEAN singular_in_batchmode =FALSE
 
volatile BOOLEAN do_shutdown = FALSE
 
volatile int defer_shutdown = 0
 
jmp_buf si_start_jmpbuf
 
int siRandomStart
 
short si_restart =0
 
BOOLEAN siCntrlc = FALSE
 
int sigint_handler_cnt =0
 

Macro Definition Documentation

§ CALL_GDB

#define CALL_GDB

Definition at line 32 of file cntrlc.cc.

Typedef Documentation

§ si_hdl_typ

typedef void(* si_hdl_typ) (int)

Definition at line 107 of file cntrlc.cc.

Function Documentation

§ init_signals()

void init_signals ( )

Definition at line 573 of file cntrlc.cc.

574 {
575  #ifdef SIGSEGV
577  #endif
578  #ifdef SIGBUS
580  #endif
581  #ifdef SIGFPE
583  #endif
584  #ifdef SIGILL
586  #endif
587  #ifdef SIGIOT
589  #endif
594 }
void sigint_handler(int)
Definition: cntrlc.cc:319
void sig_term_hdl(int)
Definition: cntrlc.cc:87
void(* si_hdl_typ)(int)
Definition: cntrlc.cc:107
void sigsegv_handler(int sig)
Definition: cntrlc.cc:285
si_hdl_typ si_set_signal(int sig, si_hdl_typ signal_handler)
meta function for binding a signal to an handler
Definition: cntrlc.cc:129
void sig_pipe_hdl(int)
Definition: cntrlc.cc:74

§ si_set_signal()

si_hdl_typ si_set_signal ( int  sig,
si_hdl_typ  signal_handler 
)

meta function for binding a signal to an handler

Parameters
[in]sigSignal number
[in]signal_handlerPointer to signal handler
Returns
value of signal()

Definition at line 129 of file cntrlc.cc.

130 {
131 #if 0
132  si_hdl_typ retval=signal (sig, (si_hdl_typ)signal_handler);
133  if (retval == SIG_ERR)
134  {
135  fprintf(stderr, "Unable to init signal %d ... exiting...\n", sig);
136  }
137  si_siginterrupt(sig, 0);
138  /*system calls will be restarted if interrupted by the specified
139  * signal sig. This is the default behavior in Linux.
140  */
141 #else
142  struct sigaction new_action,old_action;
143  memset(&new_action, 0, sizeof(struct sigaction));
144 
145  /* Set up the structure to specify the new action. */
146  new_action.sa_handler = signal_handler;
147  if (sig==SIGINT)
148  sigemptyset (&new_action.sa_mask);
149  else
150  new_action.sa_flags = SA_RESTART;
151 
152  int r=si_sigaction (sig, &new_action, &old_action);
153  si_hdl_typ retval=(si_hdl_typ)old_action.sa_handler;
154  if (r == -1)
155  {
156  fprintf(stderr, "Unable to init signal %d ... exiting...\n", sig);
157  retval=SIG_ERR;
158  }
159 #endif
160  return retval;
161 } /* si_set_signal */
if(0 > strat->sl)
Definition: myNF.cc:73
const ring r
Definition: syzextra.cc:208
void(* si_hdl_typ)(int)
Definition: cntrlc.cc:107
#define si_siginterrupt(arg1, arg2)

§ sig_pipe_hdl()

void sig_pipe_hdl ( int  )

Definition at line 74 of file cntrlc.cc.

75 {
76  if (pipeLastLink!=NULL)
77  {
80  WerrorS("pipe failed");
81  }
82 }
si_link pipeLastLink
Definition: cntrlc.cc:71
void WerrorS(const char *s)
Definition: feFopen.cc:24
#define NULL
Definition: omList.c:10

§ sig_term_hdl()

void sig_term_hdl ( int  )

Definition at line 87 of file cntrlc.cc.

88 {
89  do_shutdown = TRUE;
90  if (!defer_shutdown)
91  {
92  m2_end(1);
93  }
94 }
void m2_end(int i)
Definition: misc_ip.cc:1072
#define TRUE
Definition: auxiliary.h:99
volatile BOOLEAN do_shutdown
Definition: cntrlc.cc:84
volatile int defer_shutdown
Definition: cntrlc.cc:85

§ sigint_handler()

void sigint_handler ( int  )

Definition at line 319 of file cntrlc.cc.

320 {
321  mflush();
322  #ifdef HAVE_FEREAD
324  #endif /* HAVE_FEREAD */
325  char default_opt=' ';
326  if ((feOptSpec[FE_OPT_CNTRLC].value!=NULL)
327  && ((char*)(feOptSpec[FE_OPT_CNTRLC].value))[0])
328  { default_opt=((char*)(feOptSpec[FE_OPT_CNTRLC].value))[0]; }
329  loop
330  {
331  int cnt=0;
332  int c;
333 
335  {
336  c = 'q';
337  }
338  else if (default_opt!=' ')
339  {
340  c = default_opt;
341  }
342  else
343  {
344  fprintf(stderr,"// ** Interrupt at cmd:`%s` in line:'%s'\n",
346  if (feOptValue(FE_OPT_EMACS) == NULL)
347  {
348  fputs("abort after this command(a), abort immediately(r), print backtrace(b), continue(c) or quit Singular(q) ?",stderr);
349  fflush(stderr);fflush(stdin);
350  c = fgetc(stdin);
351  }
352  else
353  {
354  c = 'a';
355  }
356  }
357 
358  switch(c)
359  {
360  case 'q': case EOF:
361  m2_end(2);
362  case 'r':
363  if (sigint_handler_cnt<3)
364  {
366  fputs("** Warning: Singular should be restarted as soon as possible **\n",stderr);
367  fflush(stderr);
368  extern void my_yy_flush();
369  my_yy_flush();
371  longjmp(si_start_jmpbuf,1);
372  }
373  else
374  {
375  fputs("** tried too often, try another possibility **\n",stderr);
376  fflush(stderr);
377  }
378  break;
379  case 'b':
380  VoiceBackTrack();
381  break;
382  case 'a':
383  siCntrlc++;
384  case 'c':
385  if ((feOptValue(FE_OPT_EMACS) == NULL) && (default_opt!=' '))
386  {
387  /* Read until a newline or EOF */
388  while (c != EOF && c != '\n') c = fgetc(stdin);
389  }
391  return;
392  //siCntrlc ++;
393  //if (siCntrlc>2) si_set_signal(SIGINT,(si_hdl_typ) sigsegv_handler);
394  //else si_set_signal(SIGINT,(si_hdl_typ) sigint_handler);
395  }
396  cnt++;
397  if(cnt>5) m2_end(2);
398  }
399 }
jmp_buf si_start_jmpbuf
Definition: cntrlc.cc:102
void VoiceBackTrack()
Definition: fevoices.cc:77
void sigint_handler(int)
Definition: cntrlc.cc:319
static void * feOptValue(feOptIndex opt)
Definition: feOpt.h:40
loop
Definition: myNF.cc:98
BOOLEAN fe_is_raw_tty
Definition: fereadl.c:75
void m2_end(int i)
Definition: misc_ip.cc:1072
#define mflush()
Definition: reporter.h:57
int sigint_handler_cnt
Definition: cntrlc.cc:318
char my_yylinebuf[80]
Definition: febase.cc:48
BOOLEAN singular_in_batchmode
Definition: cntrlc.cc:72
Voice * feInitStdin(Voice *pp)
Definition: fevoices.cc:661
BOOLEAN siCntrlc
Definition: cntrlc.cc:105
void(* si_hdl_typ)(int)
Definition: cntrlc.cc:107
si_hdl_typ si_set_signal(int sig, si_hdl_typ signal_handler)
meta function for binding a signal to an handler
Definition: cntrlc.cc:129
struct fe_option feOptSpec[]
#define NULL
Definition: omList.c:10
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:130
Voice * currentVoice
Definition: fevoices.cc:57
void fe_temp_reset(void)
Definition: fereadl.c:113
void my_yy_flush()
Definition: scanner.cc:2333
int iiOp
Definition: iparith.cc:227

§ sigsegv_handler()

void sigsegv_handler ( int  sig)

Definition at line 285 of file cntrlc.cc.

286 {
287  fprintf(stderr,"Singular : signal %d (v: %d):\n",
288  sig,SINGULAR_VERSION);
289  if (sig!=SIGINT)
290  {
291  fprintf(stderr,"current line:>>%s<<\n",my_yylinebuf);
292  fprintf(stderr,"Segment fault/Bus error occurred (r:%d)\n"
293  "please inform the authors\n",
294  siRandomStart);
295  }
296  #ifdef __OPTIMIZE__
297  if(si_restart<3)
298  {
299  si_restart++;
300  fprintf(stderr,"trying to restart...\n");
301  init_signals();
302  longjmp(si_start_jmpbuf,1);
303  }
304  #endif /* __OPTIMIZE__ */
305  #if defined(unix)
306  #ifdef CALL_GDB
307  if (sig!=SIGINT) debug(STACK_TRACE);
308  #endif /* CALL_GDB */
309  #endif /* unix */
310  exit(0);
311 }
jmp_buf si_start_jmpbuf
Definition: cntrlc.cc:102
#define SINGULAR_VERSION
Definition: mod2.h:92
int siRandomStart
Definition: cntrlc.cc:103
char my_yylinebuf[80]
Definition: febase.cc:48
short si_restart
Definition: cntrlc.cc:104
void init_signals()
Definition: cntrlc.cc:573

Variable Documentation

§ defer_shutdown

volatile int defer_shutdown = 0

Definition at line 85 of file cntrlc.cc.

§ do_shutdown

volatile BOOLEAN do_shutdown = FALSE

Definition at line 84 of file cntrlc.cc.

§ pipeLastLink

si_link pipeLastLink =NULL

Definition at line 71 of file cntrlc.cc.

§ si_restart

short si_restart =0

Definition at line 104 of file cntrlc.cc.

§ si_start_jmpbuf

jmp_buf si_start_jmpbuf

Definition at line 102 of file cntrlc.cc.

§ siCntrlc

BOOLEAN siCntrlc = FALSE

Definition at line 105 of file cntrlc.cc.

§ sigint_handler_cnt

int sigint_handler_cnt =0

Definition at line 318 of file cntrlc.cc.

§ singular_in_batchmode

BOOLEAN singular_in_batchmode =FALSE

Definition at line 72 of file cntrlc.cc.

§ siRandomStart

int siRandomStart

Definition at line 103 of file cntrlc.cc.