Macros | Typedefs | Functions | Variables
cntrlc.cc File Reference
#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>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <strings.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>

Go to the source code of this file.

Macros

#define CALL_GDB
 

Typedefs

typedef void(* si_hdl_typ) (int)
 

Functions

void sig_chld_hdl (int sig)
 additional default signal handler More...
 
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

#define CALL_GDB

Definition at line 38 of file cntrlc.cc.

Typedef Documentation

typedef void(* si_hdl_typ) (int)

Definition at line 113 of file cntrlc.cc.

Function Documentation

void init_signals ( )

Definition at line 575 of file cntrlc.cc.

576 {
577  #ifdef SIGSEGV
579  #endif
580  #ifdef SIGBUS
582  #endif
583  #ifdef SIGFPE
585  #endif
586  #ifdef SIGILL
588  #endif
589  #ifdef SIGIOT
591  #endif
596 }
void sigint_handler(int)
Definition: cntrlc.cc:325
void sig_term_hdl(int)
Definition: cntrlc.cc:93
void sig_chld_hdl(int sig)
additional default signal handler
Definition: ssiLink.cc:1890
void(* si_hdl_typ)(int)
Definition: cntrlc.cc:113
void sigsegv_handler(int sig)
Definition: cntrlc.cc:291
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:135
void sig_pipe_hdl(int)
Definition: cntrlc.cc:80
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 135 of file cntrlc.cc.

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

additional default signal handler

some newer Linux version cannot have SIG_IGN for SIGCHLD, so use this nice routine here: SuSe 9.x reports -1 always Redhat 9.x/FC x reports sometimes -1 see also: hpux_system also needed by getrusage (timer etc.)

Parameters
[in]sig

Definition at line 1890 of file ssiLink.cc.

1891 {
1892  pid_t kidpid;
1893  int status;
1894 
1895  loop
1896  {
1897  kidpid = si_waitpid(-1, &status, WNOHANG);
1898  if (kidpid==-1)
1899  {
1900  /* continue on interruption (EINTR): */
1901  if (errno == EINTR) continue;
1902  /* break on anything else (EINVAL or ECHILD according to manpage): */
1903  break;
1904  }
1905  else if (kidpid==0) break; /* no more children to process, so break */
1906 
1907  //printf("Child %ld terminated\n", kidpid);
1909  while((hh!=NULL)&&(ssiToBeClosed_inactive))
1910  {
1911  if((hh->l!=NULL) && (hh->l->m->Open==ssiOpen))
1912  {
1913  ssiInfo *d = (ssiInfo *)hh->l->data;
1914  if(d->pid==kidpid)
1915  {
1917  {
1919  slClose(hh->l);
1921  break;
1922  }
1923  else break;
1924  }
1925  else hh=(link_list)hh->next;
1926  }
1927  else hh=(link_list)hh->next;
1928  }
1929  }
1930 }
loop
Definition: myNF.cc:98
#define FALSE
Definition: auxiliary.h:140
#define TRUE
Definition: auxiliary.h:144
#define NULL
Definition: omList.c:10
int * status
Definition: si_signals.h:50
void sig_pipe_hdl ( int  )

Definition at line 80 of file cntrlc.cc.

81 {
82  if (pipeLastLink!=NULL)
83  {
86  WerrorS("pipe failed");
87  }
88 }
si_link pipeLastLink
Definition: cntrlc.cc:77
void WerrorS(const char *s)
Definition: feFopen.cc:23
#define NULL
Definition: omList.c:10
void sig_term_hdl ( int  )

Definition at line 93 of file cntrlc.cc.

94 {
95  do_shutdown = TRUE;
96  if (!defer_shutdown)
97  {
98  m2_end(1);
99  }
100 }
void m2_end(int i)
Definition: misc_ip.cc:1074
#define TRUE
Definition: auxiliary.h:144
volatile BOOLEAN do_shutdown
Definition: cntrlc.cc:90
volatile int defer_shutdown
Definition: cntrlc.cc:91
void sigint_handler ( int  )

Definition at line 325 of file cntrlc.cc.

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

Definition at line 291 of file cntrlc.cc.

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

Variable Documentation

volatile int defer_shutdown = 0

Definition at line 91 of file cntrlc.cc.

volatile BOOLEAN do_shutdown = FALSE

Definition at line 90 of file cntrlc.cc.

si_link pipeLastLink =NULL

Definition at line 77 of file cntrlc.cc.

short si_restart =0

Definition at line 110 of file cntrlc.cc.

jmp_buf si_start_jmpbuf

Definition at line 108 of file cntrlc.cc.

BOOLEAN siCntrlc = FALSE

Definition at line 111 of file cntrlc.cc.

int sigint_handler_cnt =0

Definition at line 324 of file cntrlc.cc.

BOOLEAN singular_in_batchmode =FALSE

Definition at line 78 of file cntrlc.cc.

int siRandomStart

Definition at line 109 of file cntrlc.cc.