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 106 of file cntrlc.cc.

Function Documentation

§ init_signals()

void init_signals ( )

Definition at line 572 of file cntrlc.cc.

573 {
574  #ifdef SIGSEGV
576  #endif
577  #ifdef SIGBUS
579  #endif
580  #ifdef SIGFPE
582  #endif
583  #ifdef SIGILL
585  #endif
586  #ifdef SIGIOT
588  #endif
593 }
void sigint_handler(int)
Definition: cntrlc.cc:318
void sig_term_hdl(int)
Definition: cntrlc.cc:86
void(* si_hdl_typ)(int)
Definition: cntrlc.cc:106
void sigsegv_handler(int sig)
Definition: cntrlc.cc:284
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:128
void sig_pipe_hdl(int)
Definition: cntrlc.cc:73

§ 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 128 of file cntrlc.cc.

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

§ sig_pipe_hdl()

void sig_pipe_hdl ( int  )

Definition at line 73 of file cntrlc.cc.

74 {
75  if (pipeLastLink!=NULL)
76  {
79  WerrorS("pipe failed");
80  }
81 }
si_link pipeLastLink
Definition: cntrlc.cc:70
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 86 of file cntrlc.cc.

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

§ sigint_handler()

void sigint_handler ( int  )

Definition at line 318 of file cntrlc.cc.

319 {
320  mflush();
321  #ifdef HAVE_FEREAD
323  #endif /* HAVE_FEREAD */
324  char default_opt=' ';
325  if ((feOptSpec[FE_OPT_CNTRLC].value!=NULL)
326  && ((char*)(feOptSpec[FE_OPT_CNTRLC].value))[0])
327  { default_opt=((char*)(feOptSpec[FE_OPT_CNTRLC].value))[0]; }
328  loop
329  {
330  int cnt=0;
331  int c;
332 
334  {
335  c = 'q';
336  }
337  else if (default_opt!=' ')
338  {
339  c = default_opt;
340  }
341  else
342  {
343  fprintf(stderr,"// ** Interrupt at cmd:`%s` in line:'%s'\n",
345  if (feOptValue(FE_OPT_EMACS) == NULL)
346  {
347  fputs("abort after this command(a), abort immediately(r), print backtrace(b), continue(c) or quit Singular(q) ?",stderr);
348  fflush(stderr);fflush(stdin);
349  c = fgetc(stdin);
350  }
351  else
352  {
353  c = 'a';
354  }
355  }
356 
357  switch(c)
358  {
359  case 'q': case EOF:
360  m2_end(2);
361  case 'r':
362  if (sigint_handler_cnt<3)
363  {
365  fputs("** Warning: Singular should be restarted as soon as possible **\n",stderr);
366  fflush(stderr);
367  extern void my_yy_flush();
368  my_yy_flush();
370  longjmp(si_start_jmpbuf,1);
371  }
372  else
373  {
374  fputs("** tried too often, try another possibility **\n",stderr);
375  fflush(stderr);
376  }
377  break;
378  case 'b':
379  VoiceBackTrack();
380  break;
381  case 'a':
382  siCntrlc++;
383  case 'c':
384  if ((feOptValue(FE_OPT_EMACS) == NULL) && (default_opt!=' '))
385  {
386  /* Read until a newline or EOF */
387  while (c != EOF && c != '\n') c = fgetc(stdin);
388  }
390  return;
391  //siCntrlc ++;
392  //if (siCntrlc>2) si_set_signal(SIGINT,(si_hdl_typ) sigsegv_handler);
393  //else si_set_signal(SIGINT,(si_hdl_typ) sigint_handler);
394  }
395  cnt++;
396  if(cnt>5) m2_end(2);
397  }
398 }
jmp_buf si_start_jmpbuf
Definition: cntrlc.cc:101
void VoiceBackTrack()
Definition: fevoices.cc:77
void sigint_handler(int)
Definition: cntrlc.cc:318
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:317
char my_yylinebuf[80]
Definition: febase.cc:48
BOOLEAN singular_in_batchmode
Definition: cntrlc.cc:71
Voice * feInitStdin(Voice *pp)
Definition: fevoices.cc:661
BOOLEAN siCntrlc
Definition: cntrlc.cc:104
void(* si_hdl_typ)(int)
Definition: cntrlc.cc:106
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:128
struct fe_option feOptSpec[]
#define NULL
Definition: omList.c:10
const char * Tok2Cmdname(int tok)
Definition: gentable.cc:132
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:225

§ sigsegv_handler()

void sigsegv_handler ( int  sig)

Definition at line 284 of file cntrlc.cc.

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

Variable Documentation

§ defer_shutdown

volatile int defer_shutdown = 0

Definition at line 84 of file cntrlc.cc.

§ do_shutdown

volatile BOOLEAN do_shutdown = FALSE

Definition at line 83 of file cntrlc.cc.

§ pipeLastLink

si_link pipeLastLink =NULL

Definition at line 70 of file cntrlc.cc.

§ si_restart

short si_restart =0

Definition at line 103 of file cntrlc.cc.

§ si_start_jmpbuf

jmp_buf si_start_jmpbuf

Definition at line 101 of file cntrlc.cc.

§ siCntrlc

BOOLEAN siCntrlc = FALSE

Definition at line 104 of file cntrlc.cc.

§ sigint_handler_cnt

int sigint_handler_cnt =0

Definition at line 317 of file cntrlc.cc.

§ singular_in_batchmode

BOOLEAN singular_in_batchmode =FALSE

Definition at line 71 of file cntrlc.cc.

§ siRandomStart

int siRandomStart

Definition at line 102 of file cntrlc.cc.