Exemplo n.º 1
0
int main(int argc, char *argv[], char *const envp[]) {
    pid_t child_pid, w; 
    int status; 
    char *childargv[] = {"make", "-s", "--no-print-directory", "-f", MAKEFILE, MAKEFILE_TARGET, NULL}; 
    
    if (argc != 4) {
        fprintf(stderr, "Usage: ./tracker <timeout_seconds> <input_file> <output_file> \n"); 
        exit(EXIT_FAILURE);
    }

    float ftimeout;
    int timeout; 
    sscanf(argv[1], "%f", &ftimeout); 
    timeout = (int)ceil(ftimeout); 

    child_pid = fork(); 
    if (-1 == child_pid) {
        fprintf(stderr, "Error in fork(): %s\n", strerror(errno)); 
        exit(EXIT_FAILURE); 
    } else if (0 == child_pid) {
        if (setup_job(timeout, argv[2], argv[3])) {
            exit(EXIT_FAILURE); 
        }
        execve("/usr/bin/make", childargv, envp);
        /* should not be here */
        fprintf(stderr, "Error in execve(): %s\n", strerror(errno)); 
        exit(EXIT_FAILURE); 
    } else { 
        struct rusage accounting; 
        w = wait4(child_pid, &status, 0, &accounting); 
        if (WEXITSTATUS(status)) {
            /* we got an error */
            return WEXITSTATUS(status); 
        } else {
            /* print some stats */
            int seconds = (int)accounting.ru_utime.tv_sec + (int)accounting.ru_stime.tv_sec; 
            int useconds = (int)accounting.ru_utime.tv_usec + (int)accounting.ru_stime.tv_usec;
            if (seconds == timeout - 1) {
                int utimeout = (int)((ftimeout - (float)(timeout - 1)) * UFACT); 
                if (useconds - utimeout > UERR) {
                    fprintf(stderr, "CPU time limit exceeded\n");
                    return 1; 
                }
            }
            /* success */
            float ftime = (float)seconds + (float)useconds / UFACT; 
            fprintf(stdout, "time: %f seconds\n", ftime); 
        }
    }
    
    return 0; 
}
Exemplo n.º 2
0
static void probeTorque()
{
  JTRACE("Start");
  if( (getenv("PBS_ENVIRONMENT") != NULL) && (NULL != getenv("PBS_JOBID")) ){
    JTRACE("We run under Torque PBS!");
    // TODO: Do we need locking here?
    //JASSERT(_real_pthread_mutex_lock(&global_mutex) == 0);
    rmgr_type = torque;
    // setup Torque PBS home dir
    setup_torque_env();
    setup_job();
    // TODO: Do we need locking here?
    //JASSERT(_real_pthread_mutex_unlock(&global_mutex) == 0);
  }
}
Exemplo n.º 3
0
/*
 * Run a job -- typically called by the scheduler, but may also
 *              be called by the UA (Console program).
 *
 *  Returns: 0 on failure
 *           JobId on success
 *
 */
JobId_t run_job(JCR *jcr)
{
   int status;
   if (setup_job(jcr)) {
      Dmsg0(200, "Add jrc to work queue\n");
      /* Queue the job to be run */
      if ((status = jobq_add(&job_queue, jcr)) != 0) {
         berrno be;
         Jmsg(jcr, M_FATAL, 0, _("Could not add job queue: ERR=%s\n"), be.bstrerror(status));
         return 0;
      }
      return jcr->JobId;
   }
   return 0;
}
Exemplo n.º 4
0
int ioctl_call(ibmuftian_fpga *fpga, unsigned int ioctl_num, unsigned long args)
{
    int err = ZERO;
    mem_buff mem_ioctl;
    ioctl_inst inst_ioctl;

    if(ioctl_num == WR_EXEC)
    {
        PRINT(DBG_PRAM({IOCTL_DBG}), "instruction ioctl");
        err = copy_from_user(&inst_ioctl, (ioctl_inst __user *)args, sizeof(inst_ioctl));
        if(unlikely(err != 0))
        {
            PRINT(DBG_PRAM({IOCTL_DBG, ERR_DBG}), "copy from user failed");
            return err;
        }

        if(unlikely(inst_ioctl.eng_num >= fpga->engns.engn_count))
        {
            PRINT(DBG_PRAM({IOCTL_DBG, ERR_DBG}), "engn count not in range");
            return -EADDRNOTAVAIL;
        }
        
        mem_ioctl = inst_ioctl.data;
    }
    else if(ioctl_num == WR_MEM || ioctl_num == RD_MEM)
    {
        PRINT(DBG_PRAM({IOCTL_DBG}), "memory ioctl");
        err = copy_from_user(&mem_ioctl, (mem_buff __user *)args, sizeof(mem_ioctl));
        if(unlikely(err != 0))
        {
            PRINT(DBG_PRAM({IOCTL_DBG, ERR_DBG}), "copy from user failed");
            return err;
        }
    }
    else
    {
        PRINT(DBG_PRAM({IOCTL_DBG, ERR_DBG}), "invalid ioctl received");
        return -EINVAL;
    }

    if(mem_ioctl.buff_size == 0 || mem_ioctl.buff_size > ((fpga->fpga_info.bit.board_type == FIN) ? TOTAL_FIN_MEM_SIZE : TOTAL_WRASSE_MEM_SIZE))
    {
        PRINT(DBG_PRAM({IOCTL_DBG, ERR_DBG}), "memory buffer size greater than the available memory");
        return -EADDRNOTAVAIL;
    }
    
    if(mem_ioctl.uta_ptr > ((fpga->fpga_info.bit.board_type == FIN) ? TOTAL_FIN_MEM_SIZE : TOTAL_WRASSE_MEM_SIZE))
    {
        PRINT(DBG_PRAM({IOCTL_DBG, ERR_DBG}), "fpga memory location out of bounds");
        return -EADDRNOTAVAIL;
    }
    
    if(mem_ioctl.uta_ptr + mem_ioctl.buff_size >= ((fpga->fpga_info.bit.board_type == FIN) ? TOTAL_FIN_MEM_SIZE : TOTAL_WRASSE_MEM_SIZE))
    {
        PRINT(DBG_PRAM({IOCTL_DBG, ERR_DBG}), "memory offset out of bounds");
        return -EADDRNOTAVAIL;
    }

    switch(ioctl_num)
    {
        case RD_MEM:
        {
            if(!access_ok(VERIFY_WRITE, (void __user *) mem_ioctl.host_ptr, mem_ioctl.buff_size))
            {
                PRINT(DBG_PRAM({IOCTL_DBG, ERR_DBG}), "memory pointer not from user space, memory violation may occour");
                return -EADDRNOTAVAIL;
            }
            err = setup_job(fpga, &mem_ioctl, READ_MEM);
            break;
        }
    
        case WR_MEM:
        {
            if(!access_ok(VERIFY_READ, (void __user *) mem_ioctl.host_ptr, mem_ioctl.buff_size))
            {
                PRINT(DBG_PRAM({IOCTL_DBG, ERR_DBG}), "memory pointer not from user space, memory violation may occour");
                return -EADDRNOTAVAIL;
            }
            err = setup_job(fpga, &mem_ioctl, WRITE_MEM);
            break;
        }

        case WR_EXEC:
        {
            if(!access_ok(VERIFY_READ, (void __user *) inst_ioctl.inst.host_ptr, inst_ioctl.inst.buff_size))
            {
                PRINT(DBG_PRAM({IOCTL_DBG, ERR_DBG}), "memory pointer not from user space, memory violation may occour");
                return -EADDRNOTAVAIL;
            }
            err = setup_job(fpga, &inst_ioctl, INST);
            break;
        }
        default:
        {
            PRINT(DBG_PRAM({IOCTL_DBG, ERR_DBG}), "invalid ioctl received");
            err = -EINVAL;
        }
    }

    return err;
}
Exemplo n.º 5
0
END_TEST

START_TEST(test_with_eo_when_complete)
  {
  job pjob;
  FILE *fp = NULL;
  bool errFile_found = false;
  bool outFile_found = false;
  bool msg_found = false;
  char buf[512];
  char correct_outfilepath[512];
  char correct_errfilepath[512];
  int rc = 0;
  const char attr_join_oe[] = "eo";

  setup_job(&pjob);
  pjob.ji_wattr[JOB_ATR_join].at_flags |= ATR_VFLAG_SET;
  pjob.ji_wattr[JOB_ATR_join].at_val.at_str = (char *)attr_join_oe;

  rc = remove_old_mail("/tmp/mail.out");
  fail_unless((rc == 0), "unable to remove old mail output file");
  snprintf(correct_outfilepath, sizeof(correct_outfilepath), "Output_Path: %s", errpath);
  snprintf(correct_errfilepath, sizeof(correct_errfilepath), "Error_Path: %s", errpath);
  svr_mailowner(&pjob, MAIL_END, MAIL_NORMAL, mailbuf);
  fp = fopen("/tmp/mail.out", "r");
  /* if fp is null, no email program was set hence no test */
  if (fp)
    {
    while (fgets(buf, sizeof(buf), fp) != NULL)
      {
      if (strstr(buf, correct_errfilepath))
        errFile_found = true;
      else if (strstr(buf, correct_outfilepath))
        outFile_found = true;
      }
    fail_unless(errFile_found, "No error file path was found in the mail");
    fail_unless(outFile_found, "No output file path was found in the mail");
    fclose(fp);
    remove_old_mail("/tmp/mail.out");
    }

  errFile_found = false;
  outFile_found = false;

  svr_mailowner_with_message(&pjob, MAIL_END, MAIL_NORMAL, mailbuf,msgbuf);
  fp = fopen("/tmp/mail.out", "r");
  /* if fp is null, no email program was set hence no test */
  if (fp)
    {
    while (fgets(buf, sizeof(buf), fp) != NULL)
      {
      if (strstr(buf, correct_errfilepath))
        errFile_found = true;
      else if (strstr(buf, correct_outfilepath))
        outFile_found = true;
      else if (strstr(buf,msgbuf))
        msg_found = true;
      }
    fail_unless(errFile_found, "No error file path was found in the mail");
    fail_unless(outFile_found, "No output file path was found in the mail");
    fail_unless(msg_found,"The additional message was not found in the mail.");
    fclose(fp);
    remove_old_mail("/tmp/mail.out");
    }

  }