Skip to content

Commit

Permalink
handle windows style path and use snprintf for commit 4ae25fd
Browse files Browse the repository at this point in the history
  • Loading branch information
Shrinivas Harapanahalli committed Dec 4, 2018
1 parent 24c10cb commit 5e4c2c3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
27 changes: 18 additions & 9 deletions src/resmom/stage_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,9 @@ local_or_remote(char **path)
int
is_direct_write(job *pjob, enum job_file which, char *path, int *direct_write_possible)
{
char working_path[MAXPATHLEN * 2];
char working_path[MAXPATHLEN + PBS_MAXSVRJOBID + 3 + 1];
char *p = working_path;

working_path[MAXPATHLEN] = '\0';

if (which == Chkpt) return(0); /* direct write of checkpoint not supported */

/* Check if direct_write requested. */
Expand All @@ -449,8 +447,14 @@ is_direct_write(job *pjob, enum job_file which, char *path, int *direct_write_po
return(0);
else
/* Make local working copy of path for call to local_or_remote */
strncpy(working_path, pjob->ji_wattr[JOB_ATR_outpath].at_val.at_str, MAXPATHLEN);
if (working_path[strlen(working_path) -1] == '/') {
snprintf(working_path, MAXPATHLEN + 1, "%s", pjob->ji_wattr[JOB_ATR_outpath].at_val.at_str);
if (
#ifdef WIN32
(working_path[strlen(working_path) -1] == '\\')
#else
(working_path[strlen(working_path) -1] == '/')
#endif
) {
strcat(working_path, pjob->ji_qs.ji_jobid);
strcat(working_path, JOB_STDOUT_SUFFIX);
}
Expand All @@ -460,8 +464,14 @@ is_direct_write(job *pjob, enum job_file which, char *path, int *direct_write_po
return(0);
else
/* Make local working copy of path for call to local_or_remote */
strncpy(working_path, pjob->ji_wattr[JOB_ATR_errpath].at_val.at_str, MAXPATHLEN);
if (working_path[strlen(working_path) -1] == '/') {
snprintf(working_path, MAXPATHLEN + 1, "%s", pjob->ji_wattr[JOB_ATR_errpath].at_val.at_str);
if (
#ifdef WIN32
(working_path[strlen(working_path) -1] == '\\')
#else
(working_path[strlen(working_path) -1] == '/')
#endif
) {
strcat(working_path, pjob->ji_qs.ji_jobid);
strcat(working_path, JOB_STDERR_SUFFIX);
}
Expand Down Expand Up @@ -492,8 +502,7 @@ is_direct_write(job *pjob, enum job_file which, char *path, int *direct_write_po
}

/* Destination maps to local directory - final path is in working_path. */
strncpy(path, p, MAXPATHLEN); /* pass correct path back to caller */
path[MAXPATHLEN] = '\0';
snprintf(path, MAXPATHLEN + 1, "%s", p);
return(1);
}

Expand Down
6 changes: 3 additions & 3 deletions src/server/array_func.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ create_subjob(job *parent, char *newjid, int *rc)
#else
struct timeval tval;
#endif
char tmp_path[MAXPATHLEN + 1] = {0};
char tmp_path[MAXPATHLEN + 1];

if ((parent->ji_qs.ji_svrflags & JOB_SVFLG_ArrayJob) == 0) {
*rc = PBSE_IVALREQ;
Expand Down Expand Up @@ -896,12 +896,12 @@ create_subjob(job *parent, char *newjid, int *rc)
}

psub = &subj->ji_wattr[JOB_ATR_outpath];
strncpy(tmp_path, psub->at_val.at_str, MAXPATHLEN);
snprintf(tmp_path, MAXPATHLEN + 1, "%s", psub->at_val.at_str);
job_attr_def[JOB_ATR_outpath].at_decode(psub, NULL, NULL,
subst_array_index(subj, tmp_path));

psub = &subj->ji_wattr[JOB_ATR_errpath];
strncpy(tmp_path, psub->at_val.at_str, MAXPATHLEN);
snprintf(tmp_path, MAXPATHLEN + 1, "%s", psub->at_val.at_str);
job_attr_def[JOB_ATR_errpath].at_decode(psub, NULL, NULL,
subst_array_index(subj, tmp_path));

Expand Down

0 comments on commit 5e4c2c3

Please sign in to comment.