bool SpooledJobFiles::createParentSpoolDirectories(ClassAd const *job_ad) { int cluster=-1,proc=-1; job_ad->LookupInteger(ATTR_CLUSTER_ID,cluster); job_ad->LookupInteger(ATTR_PROC_ID,proc); std::string spool_path; getJobSpoolPath(cluster,proc,spool_path); std::string parent,junk; if( filename_split(spool_path.c_str(),parent,junk) ) { // Create directory hierarchy within spool directory. // All sub-dirs in hierarchy are owned by condor. if( !mkdir_and_parents_if_needed(parent.c_str(),0755,PRIV_CONDOR) ) { dprintf(D_ALWAYS, "Failed to create parent spool directory %s for job " "%d.%d: %s\n", parent.c_str(), cluster, proc, strerror(errno)); return false; } } return true; }
void ParameterGroup::parseCommandLineArguments(int argc, StringArray argv, bool verify_syntax) { std::vector<std::string> files; std::vector<std::pair<std::string, std::string> > assignments; for (int i = 1; i < argc; ++i) { std::string arg(argv[i]); int fpos = arg.find(ID_delimiter_assignment); if (fpos == int(std::string::npos)) { std::string filename = arg.substr(0, fpos); files.push_back(filename); continue; } int pos = fpos + ID_delimiter_assignment.size(); int spos = arg.find(ID_delimiter_assignment, pos); if (spos == int(std::string::npos)) { std::string name = arg.substr(0, fpos); std::string value = arg.substr(pos, spos); assignments.push_back(std::make_pair(name, value)); continue; } std::cout << "WARNING: Too many assignements (' " << ID_delimiter_assignment << "') detected in argument " << i << ".\n"; } for (int i = 0; i < int(files.size()); ++i) { std::pair<std::string, std::string> file_type = filename_split(files[i]); if (file_type.second == "xml") { this->readXML(files[i]); } else if (file_type.second == "param") { this->readParam(files[i]); } else { if (verify_syntax) { std::cerr << "ERROR: Input '" << files[i] << "' is not a valid name for a parameter file.\n"; std::cerr << " Valid filename extensions are 'xml' and 'param'.\n"; OPM_THROW(std::runtime_error, "ParameterGroup cannot handle argument: " << files[i]); } else { unhandled_arguments_.push_back(files[i]); } } } for (int i = 0; i < int(assignments.size()); ++i) { this->insertParameter(assignments[i].first, assignments[i].second); } }
void SpooledJobFiles::removeJobSpoolDirectory(ClassAd * ad) { ASSERT(ad); int cluster = -1; int proc = -1; ad->LookupInteger(ATTR_CLUSTER_ID, cluster); ad->LookupInteger(ATTR_PROC_ID, proc); std::string spool_path; getJobSpoolPath(cluster,proc,spool_path); if ( ! IsDirectory(spool_path.c_str()) ) { // In this case, we can be fairly sure that these other spool directories // that are removed later in this function do not exist. If they do, they // should be removed by preen. By returning now, we avoid many potentially- // expensive filesystem operations. return; } chownSpoolDirectoryToCondor(ad); remove_spool_directory(spool_path.c_str()); std::string tmp_spool_path = spool_path; tmp_spool_path += ".tmp"; remove_spool_directory(tmp_spool_path.c_str()); removeJobSwapSpoolDirectory(ad); // Now attempt to remove the directory from the spool // directory hierarchy that is for jobs belonging to this // cluster and proc. This directory may be shared with other // jobs, so the directory may not be empty, in which case we // expect rmdir to fail. std::string parent_path,junk; if( filename_split(spool_path.c_str(),parent_path,junk) ) { if( rmdir(parent_path.c_str()) == -1 ) { if( errno != ENOTEMPTY && errno != ENOENT ) { dprintf(D_ALWAYS,"Failed to remove %s: %s (errno %d)\n", parent_path.c_str(), strerror(errno), errno ); } } } }
static void append_buffer_info( MyString &url, const char *method, char const *path ) { MyString buffer_list; MyString buffer_string; MyString dir; MyString file; int s,bs,ps; int result; filename_split(path,dir,file); /* Do not buffer special device files, whether local or remote */ if(!strncmp(path,"/dev/",5)) return; /* Get the default buffer setting */ pseudo_get_buffer_info( &s, &bs, &ps ); /* Now check for individual file overrides */ /* These lines have the same syntax as a remap list */ if(Shadow->getJobAd()->LookupString(ATTR_BUFFER_FILES,buffer_list)) { if( filename_remap_find(buffer_list.Value(),path,buffer_string) || filename_remap_find(buffer_list.Value(),file.Value(),buffer_string) ) { /* If the file is merely mentioned, turn on the default buffer */ url += "buffer:"; /* If there is also a size setting, use that */ result = sscanf(buffer_string.Value(),"(%d,%d)",&s,&bs); if( result==2 ) url += buffer_string; return; } } /* Turn on buffering if the value is set and is not special or local */ /* In this case, use the simple syntax 'buffer:' so as not to confuse old libs */ if( s>0 && bs>0 && method && strcmp(method,"local") && strcmp(method,"special") ) { url += "buffer:"; } }
void ParameterGroup::parseCommandLineArguments(int argc, StringArray argv) { std::vector<std::string> files; std::vector<std::pair<std::string, std::string> > assignments; for (int i = 1; i < argc; ++i) { std::string arg(argv[i]); int fpos = arg.find(ID_delimiter_assignment); if (fpos == int(std::string::npos)) { std::string filename = arg.substr(0, fpos); files.push_back(filename); continue; } int pos = fpos + ID_delimiter_assignment.size(); int spos = arg.find(ID_delimiter_assignment, pos); if (spos == int(std::string::npos)) { std::string name = arg.substr(0, fpos); std::string value = arg.substr(pos, spos); assignments.push_back(std::make_pair(name, value)); continue; } std::cout << "WARNING: Too many assignements (' " << ID_delimiter_assignment << "') detected in argument " << i << ".\n"; } for (int i = 0; i < int(files.size()); ++i) { std::pair<std::string, std::string> file_type = filename_split(files[i]); if (file_type.second == "xml") { this->readXML(files[i]); } else if (file_type.second == "param") { this->readParam(files[i]); } else { std::cout << "WARNING: Ignoring file '" << files[i] << "' with unknown extension.\n" << "Valid filename extensions are 'xml' and 'param'.\n"; } } for (int i = 0; i < int(assignments.size()); ++i) { this->insertParameter(assignments[i].first, assignments[i].second); } }
void SpooledJobFiles::removeClusterSpooledFiles(int cluster) { std::string spool_path; std::string parent_path,junk; getJobSpoolPath(cluster,ICKPT,spool_path); int cluster_spool_dir_exists = filename_split(spool_path.c_str(),parent_path,junk) && IsDirectory( parent_path.c_str() ); if ( !cluster_spool_dir_exists ) { // if there is no parent directory of the spool path, there is no cluster spool directory return; } if( unlink( spool_path.c_str() ) == -1 ) { if( errno != ENOENT ) { dprintf(D_ALWAYS,"Failed to remove %s: %s (errno %d)\n", spool_path.c_str(),strerror(errno),errno); } } // Now attempt to remove the directory from the spool // directory hierarchy that is for jobs belonging to this // cluster. This directory may be shared with other jobs, so // the directory may not be empty, in which case we expect // rmdir to fail. if( cluster_spool_dir_exists ) { if( rmdir(parent_path.c_str()) == -1 ) { if( errno != ENOTEMPTY && errno != ENOENT ) { dprintf(D_ALWAYS,"Failed to remove %s: %s (errno %d)\n", parent_path.c_str(), strerror(errno), errno ); } } } }
int pseudo_get_file_info_new( const char *logical_name, char *&actual_url ) { MyString remap_list; MyString split_dir; MyString split_file; MyString full_path; MyString remap; MyString urlbuf; const char *method = NULL; dprintf( D_SYSCALLS, "\tlogical_name = \"%s\"\n", logical_name ); ASSERT( actual_url == NULL ); /* The incoming logical name might be a simple, relative, or complete path */ /* We need to examine both the full path and the simple name. */ filename_split( logical_name, split_dir, split_file ); complete_path( logical_name, full_path ); /* Any name comparisons must check the logical name, the simple name, and the full path */ if(Shadow->getJobAd()->LookupString(ATTR_FILE_REMAPS,remap_list) && (filename_remap_find( remap_list.Value(), logical_name, remap ) || filename_remap_find( remap_list.Value(), split_file.Value(), remap ) || filename_remap_find( remap_list.Value(), full_path.Value(), remap ))) { dprintf(D_SYSCALLS,"\tremapped to: %s\n",remap.Value()); /* If the remap is a full URL, return right away */ /* Otherwise, continue processing */ if(strchr(remap.Value(),':')) { dprintf(D_SYSCALLS,"\tremap is complete url\n"); actual_url = strdup(remap.Value()); return 0; } else { dprintf(D_SYSCALLS,"\tremap is simple file\n"); complete_path( remap.Value(), full_path ); } } else { dprintf(D_SYSCALLS,"\tnot remapped\n"); } dprintf( D_SYSCALLS,"\tfull_path = \"%s\"\n", full_path.Value() ); /* Now, we have a full pathname. */ /* Figure out what url modifiers to slap on it. */ #ifdef HPUX /* I have no idea why this is happening, but I have seen it happen many * times on the HPUX version, so here is a quick hack -Todd 5/19/95 */ if ( full_path == "/usr/lib/nls////strerror.cat" ) full_path = "/usr/lib/nls/C/strerror.cat\0"; #endif if( use_local_access(full_path.Value()) ) { method = "local"; } else { method = "remote"; } if( use_fetch(method,full_path.Value()) ) { urlbuf += "fetch:"; } if( use_compress(method,full_path.Value()) ) { urlbuf += "compress:"; } append_buffer_info(urlbuf,method,full_path.Value()); if( use_append(method,full_path.Value()) ) { urlbuf += "append:"; } if (method) { urlbuf += method; urlbuf += ":"; } urlbuf += full_path; actual_url = strdup(urlbuf.Value()); dprintf(D_SYSCALLS,"\tactual_url: %s\n",actual_url); return 0; }