/*
 * get_job_script_path()
 *
 * @pre-cond: parameters must be valid
 * @post-cond: script_path will be populated with the path to the job's script on success
 * @return: PBSE_NONE on success, PBSE_JOB_RECYCLED if job disappears or -1 if array can't be 
 * found for an array job.
 */
int get_job_script_path(

  job         *pjob,
  std::string &script_path)

  {
  // get the adjusted path to the script
  script_path = get_path_jobdata(pjob->ji_qs.ji_jobid, path_jobs);

  if (pjob->ji_arraystructid[0] != '\0')
    {
    job_array *pa = get_jobs_array(&pjob);

    if (pa != NULL)
      {
      script_path += pa->ai_qs.fileprefix;
      unlock_ai_mutex(pa, __func__, NULL, LOGLEVEL);
      }
    else if (pjob == NULL)
      return(PBSE_JOB_RECYCLED);
    else
      return(-1);
    }
  else
    {
    script_path += pjob->ji_qs.ji_fileprefix;
    }
    
  script_path += JOB_SCRIPT_SUFFIX;
  return(PBSE_NONE);
  } /* END get_job_script_path() */
Exemple #2
0
int job_save(

  job *pjob,  /* pointer to job structure */
  int  updatetype, /* 0=quick, 1=full, 2=new     */
  int  mom_port)   /* if 0 ignore otherwise append to end of job name. this is for multi-mom mode */

  {
  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0);

  char    namebuf1[MAXPATHLEN];
  char    namebuf2[MAXPATHLEN];
  const char   *tmp_ptr = NULL;

  time_t  time_now = time(NULL);
#ifndef PBS_MOM
  // get the adjusted path_jobs path
  std::string   adjusted_path_jobs = get_path_jobdata(pjob->ji_qs.ji_jobid, path_jobs);
#endif


#ifdef PBS_MOM
  tmp_ptr = JOB_FILE_SUFFIX;
#else
  if (pjob->ji_is_array_template == true)
    tmp_ptr = (char *)JOB_FILE_TMP_SUFFIX;
  else
    tmp_ptr = (char *)JOB_FILE_SUFFIX;
#endif

  if (mom_port)
    {
#ifdef PBS_MOM
    snprintf(namebuf1, MAXPATHLEN, "%s%s%d%s",
        path_jobs, pjob->ji_qs.ji_fileprefix, mom_port, tmp_ptr);
    snprintf(namebuf2, MAXPATHLEN, "%s%s%d%s",
        path_jobs, pjob->ji_qs.ji_fileprefix, mom_port, JOB_FILE_COPY);
#else
    snprintf(namebuf1, MAXPATHLEN, "%s%s%d%s",
        adjusted_path_jobs.c_str(), pjob->ji_qs.ji_fileprefix, mom_port, tmp_ptr);
    snprintf(namebuf2, MAXPATHLEN, "%s%s%d%s",
        adjusted_path_jobs.c_str(), pjob->ji_qs.ji_fileprefix, mom_port, JOB_FILE_COPY);
#endif
    }
  else
    {
#ifdef PBS_MOM
    snprintf(namebuf1, MAXPATHLEN, "%s%s%s",
        path_jobs, pjob->ji_qs.ji_fileprefix, tmp_ptr);
    snprintf(namebuf2, MAXPATHLEN, "%s%s%s",
        path_jobs, pjob->ji_qs.ji_fileprefix, JOB_FILE_COPY);
#else
    snprintf(namebuf1, MAXPATHLEN, "%s%s%s",
        adjusted_path_jobs.c_str(), pjob->ji_qs.ji_fileprefix, tmp_ptr);
    snprintf(namebuf2, MAXPATHLEN, "%s%s%s",
        adjusted_path_jobs.c_str(), pjob->ji_qs.ji_fileprefix, JOB_FILE_COPY);
#endif
    }

  /* if ji_modified is set, ie an pbs_attribute changed, then update mtime */

  if (pjob->ji_modified)
    {
    pjob->ji_wattr[JOB_ATR_mtime].at_val.at_long = time_now;
    }

  if (!(saveJobToXML(pjob, namebuf2)))
    {
    unlink(namebuf1);

    if (link(namebuf2, namebuf1) == -1)
      {
      log_event(
        PBSEVENT_ERROR | PBSEVENT_SECURITY,
        PBS_EVENTCLASS_JOB,
        pjob->ji_qs.ji_jobid,
        (char *)"Link in job_save failed");
      }
    else
      {
      unlink(namebuf2);
      }
    }
  else /* saveJobToXML failed */
    {
    log_event(PBSEVENT_ERROR | PBSEVENT_SECURITY, PBS_EVENTCLASS_JOB, pjob->ji_qs.ji_jobid,
      "call to saveJobToXML in job_save failed");
    pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
    return -1;
    }

  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);

  return(PBSE_NONE);
  }  /* END job_save() */