Esempio n. 1
0
void MainWindow::createActions()
{
  connect(m_ui->actionMinimize, SIGNAL(triggered()), this, SLOT(hide()));
  connect(m_ui->actionMaximize, SIGNAL(triggered()), this, SLOT(showMaximized()));
  connect(m_ui->actionRestore, SIGNAL(triggered()), this, SLOT(showNormal()));
  connect(m_ui->actionUpdateRemoteQueues, SIGNAL(triggered()),
          m_server->queueManager(), SLOT(updateRemoteQueues()));
  connect(m_ui->actionViewJobFilter, SIGNAL(toggled(bool)),
          m_ui->jobTableWidget, SLOT(showFilterBar(bool)));
  connect(m_ui->actionAdvancedJobFilters, SIGNAL(triggered()),
          this, SLOT(showAdvancedJobFilters()));
  connect(m_ui->actionClearFinishedJobs, SIGNAL(triggered()),
          m_ui->jobTableWidget, SLOT(clearFinishedJobs()));
}
Esempio n. 2
0
int
main(void)
{
  static char buf[100];
  int fd;
  //int status;
  
  // Assumes three file descriptors open.
  while((fd = open("console", O_RDWR)) >= 0){
    if(fd >= 3){
      close(fd);
      break;
    }
  }
  
  // Read and run input commands.
  int jobcntr = 0;
  jlist = malloc(sizeof(*jlist));
  jlist->first = 0;
  jlist->last = 0;
  jlist->fgJob = 0;
  
  int waitStatus;
  int bPrintDollar = 1;
  int cmdLen = 0;
  while((cmdLen = getcmd(buf, sizeof(buf), bPrintDollar)) >= 0){

      clearFinishedJobs(jlist);
	
      // Check if there's a forground job running. 
      // If so - the shell should not function, but only transfer the data received from the console to the job's pipe
      if (jlist->fgJob != 0) {
	  bPrintDollar = 0;
	  write(jlist->fgJob->fd, buf, cmdLen);
	  continue;
      }
      bPrintDollar = 1;
      
      if(buf[0] == 'c' && buf[1] == 'd' && buf[2] == ' ') {
	// Clumsy but will have to do for now.
	// Chdir has no effect on the parent if run in the child.
	buf[strlen(buf)-1] = 0;  // chop \n
	if(chdir(buf+3) < 0)
	  printf(2, "cannot cd %s\n", buf+3);
	continue;
      }

      if(buf[0] == 'j' && buf[1] == 'o' && buf[2] == 'b' && buf[3] == 's' && (buf[4] == '\n' || buf[4] == ' ')) {
	  struct job* job = jlist->first;
	  while (job != 0) {
	      printjob(job->jid);
	      job = job->next;
	  }
	  if (!jlist->first)
		  printf(1, "There are no jobs.\n");
	  continue;
      }

      if(buf[0] == 'f' && buf[1] == 'g' && (buf[2] == '\n' || buf[2] == ' ')) {
	  char* c = &buf[3];

	  int jid = atoi(c);

	  struct job* j = jlist->first;
	  while ( j->jid != jid && j != 0) {
	      j = j->next;
	  }
	  jlist->fgJob = j;
	  //fg(jid);
	  continue;
      }

      // 0x0A - new line
      if (buf[0] != 0x0A ) { 
	
	  // create a pipe so the the shell sends the input to jobs_pipe[1] and the new process gets it in jobs_pipe[0]
	  if (pipe(jobs_pipe) == -1) {
	      panic("pipe");
	  }	  
	  
	  struct job* job;
	  job = malloc(sizeof(*job));
	  memset(job, 0, sizeof(*job));
	  job->jid = ++jobcntr;
	  job->fd = jobs_pipe[1];
	  
	  //char* s = job->cmd;
	  //char* t = buf;
	  //int i = sizeof(buf);
	  //while(--i > 0 && *t != '\n' && (*s++ = *t++) != 0) ;
	  //*s = 0;

	  

	  struct cmd* command = parsecmd(buf);
	  int childPid = fork1();
	  if(childPid == 0) {	    
	      close(0);	      
	      dup(jobs_pipe[0]);
	      close(jobs_pipe[1]);
	      if(fork1() == 0)
		  runcmd(command);
	      exit(0);
	  }
	  close(jobs_pipe[0]); // The shell doesn't need the READ end.
	  
	  attachjob(childPid, job); // Attach proc to job (Sys call)
		      
	  // shell writes the input to job_buffer ONLY IF the cmd isn't a backgraound job
	  if (command->type != BACK) {
	      jlist->fgJob = job;
	      bPrintDollar = 0;
	  }
	  
	  addJobToList(jlist, job);
	  
	  wait(&waitStatus);
      }
    }
    exit(0);
}