Exemple #1
0
void Interrupt(int S)
{
int status;
   switch(S) {
   case SIGCHLD :
       if(WAITPID) return;
       while (waitpid(-1, &status, WNOHANG) > 0);
       return;
       break;
   case SIGSEGV :
       printf("Segmentation Error !!\n");
       termReset();
       _exit(1);
       break;
   case SIGPIPE :
       printf("Pipe is broken");
       break;
   case SIGFPE :
       printf("Floating Point");
       break;
   case SIGALRM :
       printf("Compilation");
       break;
   case SIGINT :
       if (!SigOn) return;
   default :
       printf("Signal %d !\n",S);
       break;
   }
   siglongjmp(ENV_INT,1);
}
Exemple #2
0
void stopErr(char *M, char *F)
{
    fprintf(stderr,"ERREUR : %s !!\n",M);
    if (F != NULL) perror(F);
    if (inSonProc) exit(1);
    termReset();
    exit(1);
}
Exemple #3
0
void termInit(int numTerms) {
  int master, slave;
  char ptyName[100];
  char ptyTitle[100];
  struct termios termios;
  int i;

  numTerminals = numTerms;
  for (i = 0; i < numTerminals; i++) {
    /* open pseudo terminal */
    if (openPty(&master, &slave, ptyName) < 0) {
      error("cannot open pseudo terminal %d", i);
    }
    if (debug) {
      cPrintf("pseudo terminal '%s': master fd = %d, slave fd = %d\n",
              ptyName, master, slave);
    }
    /* set mode to raw */
    tcgetattr(slave, &termios);
    makeRaw(&termios);
    tcsetattr(slave, TCSANOW, &termios);
    /* fork and exec a new xterm */
    terminals[i].pid = fork();
    if (terminals[i].pid < 0) {
      error("cannot fork xterm process %d", i);
    }
    if (terminals[i].pid == 0) {
      char geo[20];
      /* terminal process */
      setpgid(0, 0);
      close(2);
      close(master);
      /* it's annoying to have to adjust the window-position every time eco-sim starts :) */
      sprintf(geo, "+%d+%d", 1600 + (i % 2) * 500,(i / 2) * 400);
      sprintf(ptyName, "-Sab%d", slave);
      sprintf(ptyTitle, "ECO32 Terminal %d", i);
      execlp("xterm", "xterm", "-geo", geo, "-title", ptyTitle, ptyName, NULL);
      error("cannot exec xterm process %d", i);
    }
    terminals[i].in = fdopen(master, "r");
    setvbuf(terminals[i].in, NULL, _IONBF, 0);
    terminals[i].out = fdopen(master, "w");
    setvbuf(terminals[i].out, NULL, _IONBF, 0);
    /* skip the window id written by xterm */
    while (fgetc(terminals[i].in) != '\n') ;
  }
  termReset();
}
Exemple #4
0
int main(int N, char *P[])
{
int n,Ctx;
char *dirW = ".nife";
    if (N > 2) {
       fprintf(stderr,"nife [nif-file]\n");
       return(1);
    }
    if ((sizeof(void*) != sizeof(long)) ||
       (sizeof(double) != sizeof(long long))) {
       fprintf(stderr,"Nife open-source don't runs on these machine !\n");
       return(2);
    }
    signal(SIGQUIT,SIG_IGN);
    signal(SIGABRT,SIG_IGN);
    signal(SIGUSR1,SIG_IGN);
    signal(SIGCONT,SIG_IGN);
    signal(SIGSTOP,SIG_IGN);
    signal(SIGTSTP,SIG_IGN);
    signal(SIGINT,Interrupt);
    signal(SIGTERM,Interrupt);
    signal(SIGPIPE,Interrupt);
    signal(SIGCHLD,Interrupt);
    signal(SIGQUIT,Interrupt);
    signal(SIGSEGV,Interrupt);
    signal(SIGFPE,Interrupt);
    signal(SIGALRM,Interrupt);
    /* work in ./.nife for facilities of debugging !! */
    if (chdir(dirW) != 0) {
       if (mkdir(dirW, 0755) == -1) {
          perror("mkdir"); return 1;
       }
       if (chdir(dirW) != 0) {
          perror("chdir"); return 1;
       }
    }
    termInit(); /* may stop if no term found */
    TH_init();
    initLib();
    D_Reset();
    if (N==2) {
       IF_Load();
       lectFic(P[1]);
    } else {
      printf("Welcome to Nife : Just stack it !\n");
      IF_helpS();
    }
    while (RUN) {
       if ((FD_IN+iTERM) == 0) {
          printf("> ");
          fflush(stdout);
          Ctx=0;
       } else Ctx=1;
       razErr();
       if ((n=lireLigne(FD_IN,bufP,bufP2,LBUF)) == -1)
                 printf("Line too long!\n");
       else
          if (n>0) traiteLigne(bufP,0);
    }
    IF_delAllGP();
    IF_netStopS();
    IF_netOff();
    D_Close();
    termReset();
    printf("Bye !\n");
    return 0;
}
Exemple #5
0
/* poweroff handler */
static void sigUsr2Handler(int signum) {
    termReset();
    shutDown(getKillPolicy(), POWEROFF);
}
Exemple #6
0
/* halt handler */
static void sigUsr1Handler(int signum) {
    termReset();
    shutDown(getKillPolicy(), HALT);
}
Exemple #7
0
/* reboot handler */
static void sigintHandler(int signum) {
    termReset();
    shutDown(getKillPolicy(), REBOOT);
}
/* poweroff handler */
static void sigUsr2Handler(int signum) {
    termReset();
    shutDown(getNoKill(), 0, 1);
}
/* reboot handler */
static void sigintHandler(int signum) {
    termReset();
    shutDown(getNoKill(), 1, 0);
}