Beispiel #1
0
int main (int argc, char ** argv) {
  int n;
  char * nargv[numDbgArgs];
  int fdtoWeb,fdfrmWeb,fdtoDbg,fdfrmDgb,pipefd[2];
  char line[BUFFSIZE],toServer[MaxPipeName],fromServer[MaxPipeName];
    sprintf(buf,"%s%s%s",logdir,"LOG",argv[1]);
    unlink(buf);
    fdtoFILE=fopen(buf,"w");
    fprintf(fdtoFILE,"testing file output\n");
    sprintf(work_file,"%s%s%s",logdir,"FILE",argv[1]);
    unlink(work_file);

    signal(SIGPIPE, catch_sigpipe);
    signal(SIGINT, catch_sigint);
    if ((argc < 2 )|| (argc >=3)){
      perror("usage: debugger idcode");
      exit(1);
    }
    //create input pipe from webserver
    sprintf(fromServer,"%s%s%s",logdir,"OUT",argv[1]);
    unlink(fromServer);
    
    if (-1 == mkfifo(fromServer,S_IRWXU)) {
       perror("Error, could not make fifo\n");
    }

    //create output pipe to webserver
    sprintf(toServer,"%s%s%s",logdir,"IN",argv[1]);
    unlink(toServer);
    
    if (-1 == mkfifo(toServer,S_IRWXU)) {
        perror("Error, could not make fifo\n");
    }
    if ((fdfrmWeb = open(fromServer,O_RDONLY)) == -1) {
      perror("cannot open fifo from server");
      exit(1);
    }
    if ((fdtoWeb = open(toServer,O_WRONLY)) == -1) {
      perror("cannot open fifo to server");
      exit(1);
    }
    //create pipes to debugger
   
    if(pipe(pipefd) == -1) { //perhaps pipe(pipefd,O_NONBLOCK)
        perror("Pipe 1 creation failed");
        exit(1);
    }
  
    int i;
    char c;
      make_args(argv[1],nargv);
      child_pid=launch_debugger(nargv,pipefd);
      fprintf(fdtoFILE,"child_pid=%d\n",child_pid);
      fflush(fdtoFILE);
       setpgid(0, 0);
      fprintf(fdtoFILE,"---starting---\n");
      fflush(fdtoFILE);
        

      while(1){
        line[0]=0;
        while (!strstr(line,">>>") && !strstr(line,"...")){
          if ((n=read(pipefd[0],line,BUFFSIZE))){
            if (!n) {
              fprintf(fdtoFILE,"pipe fd[0] closed");
              fflush(fdtoFILE);
              exit(1);
	    }
            //line[n++]='@'; 
            line[n]=0;
	    //if n=BUFFSIZE...
           }       
          fprintf(fdtoFILE,"p-%s",line);
          fflush(fdtoFILE);
          if (write(fdtoWeb,line,n) != n) {
             perror("fdtoWeb write error");
            fprintf(fdtoFILE,"fdtoWeb write error\n");
            fflush(fdtoFILE);

	  }         

        }
 
         if ((n=read(fdfrmWeb,line,BUFFSIZE))){
            line[n]=0;
            fprintf(fdtoFILE,"%d-%s%s",n,"w-",line);
	    fflush(fdtoFILE);
             if (write(pipefd[1],line,n) != n) {
             perror("pipefd[1] write error");
	     }        

	 }
         else{
           printf("empty read\n");
	   close(fdtoWeb);
           close(fdfrmWeb);
           n=0;
           if ((fdfrmWeb = open(fromServer,O_RDONLY)) == -1) {
              perror("cannot open fifo from server");
              exit(1);
           }
    
           if ((fdtoWeb = open(toServer,O_WRONLY)) == -1) {
             perror("cannot open fifo to server");
             exit(1);
	   }
           line[0]='\n';
           if (write(pipefd[1],line,1) != 1) {
             perror("pipefd[1] write error");
	   }        

	 }

      }
   
    exit(0);
}
Beispiel #2
0
int main (int argc, char ** argv) {
  int n;
  char * nargv[numDbgArgs];
  int fdtoWeb,fdfrmWeb,fdtoDbg,fdfrmDgb,pipefd[2];
  char buf[BUFFSIZE],line[BUFFSIZE],toServer[MaxPipeName],fromServer[MaxPipeName];
 
    signal(SIGPIPE, catch_sigpipe);
    if ((argc < 2 )|| (argc >=3)){
      perror("usage: debugger idcode");
      exit(1);
    }
    /*
    //create input pipe from webserver
    sprintf(fromServer,"%s%s%s",logdir,argv[1],"OUT");
    unlink(fromServer);
    
    if (-1 == mkfifo(fromServer,S_IRWXU)) {
       perror("Error, could not make fifo\n");
    }

    //create output pipe to webserver
    sprintf(toServer,"%s%s%s",logdir,argv[1],"IN");
    unlink(toServer);
    
    if (-1 == mkfifo(toServer,S_IRWXU)) {
        perror("Error, could not make fifo\n");
    }
    if ((fdfrmWeb = open(fromServer,O_RDONLY)) == -1) {
      perror("cannot open fifo from server");
      exit(1);
    }
    if ((fdtoWeb = open(toServer,O_WRONLY)) == -1) {
      perror("cannot open fifo to server");
      exit(1);
    }
    //create pipes to debugger
   
    if(pipe(pipefd) == -1) { //perhaps pipe(pipefd,O_NONBLOCK)
        perror("Pipe 1 creation failed");
        exit(1);
    }
  
    */ 
    int i;
    char c;make_args(argv[1],nargv);
      child_pid=launch_debugger(nargv,pipefd);
      printf("child_pid=%d\n",child_pid);
      fflush(stdout);

   

    //   while(1){
      /* 
      if ((n=read(fdfrmWeb,line,BUFFSIZE))){
        line[n]=0;
	n=sprintf(buf,"%d-%s%s",n,"debugger:",line);
         if (write(1,buf,n) != n) {
             printf("cp: write error on file stdout\n");
             fflush(stdout);
             exit(1);
	 }
         if (write(fdtoWeb,buf,n) != n) {
             perror("fdtoWeb write error");
      	 }

      }
      else{
        printf("empty read\n");
	close(fdtoWeb);
        close(fdfrmWeb);
        n=0;
        if ((fdfrmWeb = open(fromServer,O_RDONLY)) == -1) {
           perror("cannot open fifo from server");
           exit(1);
        }
        if ((fdtoWeb = open(toServer,O_WRONLY)) == -1) {
           perror("cannot open fifo to server");
           exit(1);
        }
      }
      */
    while (1){

      i=0;
      while ((c=getchar())!='\n'){
 	line[i++]=c;
      }
      line[i]=c;        
      write(pipefd[1],line,i+1);
      if ((n=read(pipefd[0],line,BUFFSIZE))){
         line[n]=0;
      } 
      printf("%s",line);
      fflush(stdout);
    }
exit(0);
}
Beispiel #3
0
static void action_start_debugger(G_GNUC_UNUSED GtkAction *act, gpointer data)
{
	TilemEmulatorWindow *ewin = data;
	launch_debugger(ewin);
}