void AdNameHashKey::sprint (MyString &s) { if (ip_addr.Length() ) s.sprintf( "< %s , %s >", name.Value(), ip_addr.Value() ); else s.sprintf( "< %s >", name.Value() ); }
int main(int, char* argv[]) { MyString err; // dup FD 0 since well will later replace FD 0 with the job's stdin // int sock_fd = dup(0); if (sock_fd == -1) { err.sprintf("dup error on FD 0: %s", strerror(errno)); full_write(0, err.Value(), err.Length() + 1); exit(1); } // set up an Env object that we'll use for the job. we'll initialize // it with the environment that Condor sends us then merge on top of // that the environment that glexec prepared for us // Env env; char* env_buf = read_env(sock_fd); MyString merge_err; if (!env.MergeFromV2Raw(env_buf, &merge_err)) { err.sprintf("Env::MergeFromV2Raw error: %s", merge_err.Value()); full_write(sock_fd, err.Value(), err.Length() + 1); exit(1); } env.MergeFrom(environ); delete[] env_buf; // now receive an FD on our stdin (which is a UNIX domain socket) // that we'll use as the job's stdin // int job_fd = read_fd(sock_fd); if (dup2(job_fd, 0) == -1) { err.sprintf("dup2 to FD 0 error: %s", strerror(errno)); full_write(sock_fd, err.Value(), err.Length() + 1); exit(1); } close(job_fd); if (fcntl(sock_fd, F_SETFD, FD_CLOEXEC) == -1) { err.sprintf("fcntl error setting close-on-exec: %s", strerror(errno)); full_write(sock_fd, err.Value(), err.Length() + 1); exit(1); } // now we can exec the job. for arguments, we shift this wrappers // arguments by one. similarly, the job's executable path is taken // as our argv[1] // char** envp = env.getStringArray(); execve(argv[1], &argv[1], envp); err.sprintf("execve error: %s", strerror(errno)); full_write(sock_fd, err.Value(), err.Length() + 1); exit(1); }
void stats_recent_counter_timer::Unpublish(ClassAd & ad, const char * pattr) const { ad.Delete(pattr); MyString attr; attr.sprintf("Recent%s",pattr); ad.Delete(attr.Value()); attr.sprintf("Recent%sRuntime",pattr); ad.Delete(attr.Value()); ad.Delete(attr.Value()+6); // +6 to skip "Recent" prefix }
bool Env::SetEnvWithErrorMessage( const char *nameValueExpr, MyString *error_msg ) { char *expr, *delim; int retval; if( nameValueExpr == NULL || nameValueExpr[0] == '\0' ) { return false; } // make a copy of nameValueExpr for modifying expr = strnewp( nameValueExpr ); ASSERT( expr ); // find the delimiter delim = strchr( expr, '=' ); if(delim == NULL && strstr(expr,"$$")) { // This environment entry is an unexpanded $$() macro. // We just want to keep it in the environment verbatim. SetEnv(expr,NO_ENVIRONMENT_VALUE); delete[] expr; return true; } // fail if either name or delim is missing if( expr == delim || delim == NULL ) { if(error_msg) { MyString msg; if(delim == NULL) { msg.sprintf( "ERROR: Missing '=' after environment variable '%s'.", nameValueExpr); } else { msg.sprintf("ERROR: missing variable in '%s'.",expr); } AddErrorMessage(msg.Value(),error_msg); } delete[] expr; return false; } // overwrite delim with '\0' so we have two valid strings *delim = '\0'; // do the deed retval = SetEnv( expr, delim + 1 ); delete[] expr; return retval; }
void IpVerify::AuthEntryToString(const in6_addr & host, const char * user, perm_mask_t mask, MyString &result) { // every address will be seen as IPv6 format. should do something // to print IPv4 address neatly. char buf[INET6_ADDRSTRLEN]; memset((void*)buf, 0, sizeof(buf)); uint32_t* addr = (uint32_t*)&host; // checks if IPv4-mapped-IPv6 address const char* ret = NULL; if (addr[0] == 0 && addr[1] == 0 && addr[2] == htonl(0xffff)) { ret = inet_ntop(AF_INET, (const void*)&addr[3], buf, sizeof(buf)); } else { ret = inet_ntop(AF_INET6, &host, buf, sizeof(buf)); } #ifndef WIN32 if (!ret) { dprintf(D_HOSTNAME, "IP address conversion failed, errno = %d\n", errno); } #endif MyString mask_str; PermMaskToString( mask, mask_str ); result.sprintf("%s/%s: %s", /* NOTE: this does not need a '\n', all the call sites add one. */ user ? user : "******", buf, mask_str.Value() ); }
bool Job::CanAddParent( Job* parent, MyString &whynot ) { if( !parent ) { whynot = "parent == NULL"; return false; } if(GetFinal()) { whynot = "Tried to add a parent to a Final node"; return false; } // we don't currently allow a new parent to be added to a // child that has already been started (unless the parent is // already marked STATUS_DONE, e.g., when rebuilding from a // rescue DAG) -- but this restriction might be lifted in the // future once we figure out the right way for the DAG to // respond... if( _Status != STATUS_READY && parent->GetStatus() != STATUS_DONE ) { whynot.sprintf( "%s child may not be given a new %s parent", this->GetStatusName(), parent->GetStatusName() ); return false; } whynot = "n/a"; return true; }
bool Env::getDelimitedStringV1Raw(MyString *result,MyString *error_msg,char delim) const { MyString var, val; bool emptyString = true; if(!delim) delim = env_delimiter; ASSERT(result); _envTable->startIterations(); while( _envTable->iterate( var, val ) ) { if(!IsSafeEnvV1Value(var.Value(),delim) || !IsSafeEnvV1Value(val.Value(),delim)) { if(error_msg) { MyString msg; msg.sprintf("Environment entry is not compatible with V1 syntax: %s=%s",var.Value(),val.Value()); AddErrorMessage(msg.Value(),error_msg); } return false; } // only insert the delimiter if there's already an entry... if( !emptyString ) { (*result) += delim; } WriteToDelimitedString(var.Value(),*result); if(val != NO_ENVIRONMENT_VALUE) { WriteToDelimitedString("=",*result); WriteToDelimitedString(val.Value(),*result); } emptyString = false; } return true; }
bool Job::AddScript( bool post, const char *cmd, MyString &whynot ) { if( !cmd || strcmp( cmd, "" ) == 0 ) { whynot = "missing script name"; return false; } if( post ? _scriptPost : _scriptPre ) { whynot.sprintf( "%s script already assigned (%s)", post ? "POST" : "PRE", GetPreScriptName() ); return false; } Script* script = new Script( post, cmd, this ); if( !script ) { dprintf( D_ALWAYS, "ERROR: out of memory!\n" ); // we already know we're out of memory, so filling in // whynot will likely fail, but give it a shot... whynot = "out of memory!"; return false; } if( post ) { _scriptPost = script; } else { _scriptPre = script; } whynot = "n/a"; return true; }
bool ArgList::V1WackedToV1Raw(char const *v1_input,MyString *v1_raw,MyString *errmsg) { if(!v1_input) return true; ASSERT(v1_raw); ASSERT(!IsV2QuotedString(v1_input)); while(*v1_input) { if(*v1_input == '"') { if(errmsg) { MyString msg; msg.sprintf("Found illegal unescaped double-quote: %s",v1_input); AddErrorMessage(msg.Value(),errmsg); } return false; } else if(v1_input[0] == '\\' && v1_input[1] == '"') { // Escaped double-quote. v1_input++; (*v1_raw) += *(v1_input++); } else { (*v1_raw) += *(v1_input++); } } return true; }
bool VMGahpServer::write_line(const char *command) { if( m_is_initialized == false ) { return false; } if( !command || m_vmgahp_writefd == -1 ) { return false; } if( daemonCore->Write_Pipe(m_vmgahp_writefd,command,strlen(command)) <= 0 ) { dprintf( D_ALWAYS, "VMGAHP write line(%s) Error\n", command); return false; } if( daemonCore->Write_Pipe(m_vmgahp_writefd,"\r\n",2) <= 0) { dprintf( D_ALWAYS, "VMGAHP write line(%s) Error\n", "\r\n"); return false; } MyString debug; debug.sprintf( "'%s'", command ); dprintf( D_FULLDEBUG, "VMGAHP[%d] <- %s\n", m_vmgahp_pid, debug.Value() ); return true; }
DCloudResource::BatchStatusResult DCloudResource::StartBatchStatus() { ASSERT(status_gahp); StringList instance_ids; StringList statuses; const char *instance_id; const char *status; int rc = status_gahp->dcloud_status_all( ResourceName(), m_username, m_password, instance_ids, statuses ); if ( rc == GAHPCLIENT_COMMAND_PENDING ) { return BSR_PENDING; } if ( rc != 0 ) { dprintf( D_ALWAYS, "Error attempting a Deltacloud batch status query: %s\n", status_gahp->getErrorString() ); return BSR_ERROR; } DCloudJob *next_job; List<DCloudJob> my_jobs; registeredJobs.Rewind(); while ( (next_job = (DCloudJob *)registeredJobs.Next()) ) { my_jobs.Insert( next_job ); } instance_ids.rewind(); statuses.rewind(); while ( (instance_id = instance_ids.next()) && (status = statuses.next()) ) { MyString hashname; hashname.sprintf( "%s#%s", ResourceName(), instance_id ); DCloudJob *job = NULL; // TODO We can get rid of the hashtable. rc = DCloudJob::JobsByInstanceId.lookup( HashKey( hashname.Value() ), job ); if ( rc != 0 ) { // Job not found. Probably okay; we might see jobs // submitted via other means, or jobs we've abandoned. dprintf( D_FULLDEBUG, "Job %s on remote host is unknown. Skipping.\n", hashname.Value() ); continue; } ASSERT( job ); job->StatusUpdate( status ); my_jobs.Delete( job ); } my_jobs.Rewind(); while ( (next_job = my_jobs.Next()) ) { next_job->StatusUpdate( NULL ); } return BSR_DONE; }
MyString condor_sockaddr::to_sinful() const { MyString ret; char tmp[IP_STRING_BUF_SIZE]; // if it is not ipv4 or ipv6, to_ip_string_ex will fail. if ( !to_ip_string_ex(tmp, IP_STRING_BUF_SIZE) ) return ret; if (is_ipv4()) { ret.sprintf("<%s:%d>", tmp, ntohs(v4.sin_port)); } else if (is_ipv6()) { ret.sprintf("<[%s]:%d>", tmp, ntohs(v6.sin6_port)); } return ret; }
const char * DCloudResource::HashName( const char *resource_name, const char *username, const char *password ) { static MyString hash_name; hash_name.sprintf( "%s#%s#%s", resource_name, username, password ); return hash_name.Value(); }
static pid_t privsep_launch_switchboard(const char* op, FILE*& in_fp, FILE*& err_fp) { ASSERT(switchboard_path != NULL); ASSERT(switchboard_file != NULL); // create the pipes for communication with the switchboard // int child_in_fd; int child_err_fd; if (!privsep_create_pipes(in_fp, child_in_fd, err_fp, child_err_fd)) { return 0; } pid_t switchboard_pid = fork(); if (switchboard_pid == -1) { dprintf(D_ALWAYS, "privsep_launch_switchboard: fork error: %s (%d)\n", strerror(errno), errno); return 0; } // in the parent, we just return back to the caller so they can // start sending commands to the switchboard's input pipe; but // make sure to close the clients sides of our pipes first // if (switchboard_pid != 0) { close(child_in_fd); close(child_err_fd); return switchboard_pid; } // in the child, we need to exec the switchboard binary with the // appropriate arguments // close(fileno(in_fp)); close(fileno(err_fp)); MyString cmd; ArgList arg_list; privsep_get_switchboard_command(op, child_in_fd, child_err_fd, cmd, arg_list); execv(cmd.Value(), arg_list.GetStringArray()); // exec failed; tell our parent using the error pipe that something // went wrong before exiting // MyString err; err.sprintf("exec error on %s: %s (%d)\n", cmd.Value(), strerror(errno), errno); write_error_code = write(child_err_fd, err.Value(), err.Length()); _exit(1); }
template <> void stats_entry_recent<Probe>::Unpublish(ClassAd& ad, const char * pattr) const { MyString attr; ad.Delete(pattr); attr.sprintf("Recent%s", pattr); ad.Delete(attr.Value()); attr.sprintf("Recent%sCount", pattr); ad.Delete(attr.Value()); ad.Delete(attr.Value()+6); attr.sprintf("Recent%sSum", pattr); ad.Delete(attr.Value()); ad.Delete(attr.Value()+6); attr.sprintf("Recent%sAvg", pattr); ad.Delete(attr.Value()); ad.Delete(attr.Value()+6); attr.sprintf("Recent%sMin", pattr); ad.Delete(attr.Value()); ad.Delete(attr.Value()+6); attr.sprintf("Recent%sMax", pattr); ad.Delete(attr.Value()); ad.Delete(attr.Value()+6); attr.sprintf("Recent%sStd", pattr); ad.Delete(attr.Value()); ad.Delete(attr.Value()+6); }
Manageable::status_t SubmissionObject::GetJobSummaries ( Variant::List &jobs, std::string &text ) { ClassAd *ad = NULL; MyString constraint; // id, timestamp (which?), command, args, ins, outs, state, message const char *ATTRS[] = {ATTR_CLUSTER_ID, ATTR_PROC_ID, ATTR_GLOBAL_JOB_ID, ATTR_Q_DATE, ATTR_ENTERED_CURRENT_STATUS, ATTR_JOB_STATUS, ATTR_JOB_CMD, ATTR_JOB_ARGUMENTS1, ATTR_JOB_ARGUMENTS2, ATTR_RELEASE_REASON, ATTR_HOLD_REASON, NULL }; constraint.sprintf("%s == \"%s\"", ATTR_JOB_SUBMISSION, this->m_name.c_str()); dprintf(D_FULLDEBUG,"GetJobSummaries for submission: %s\n",constraint.Value()); Variant::Map job; int init_scan = 1; while (NULL != (ad = GetNextJobByConstraint(constraint.Value(), init_scan))) { // debug // if (IsFulldebug(D_FULLDEBUG)) { // ad->dPrint(D_FULLDEBUG|D_NOHEADER); // } for (int i = 0; NULL != ATTRS[i]; i++) { if (!AddAttribute(*ad, ATTRS[i], job)) { dprintf(D_FULLDEBUG,"Warning: %s attribute not found for job of %s\n",ATTRS[i],constraint.Value()); } } jobs.push_back(job); init_scan = 0; // debug // if (IsFulldebug(D_FULLDEBUG)) { // std::ostringstream oss; // oss << jobs; // dprintf(D_FULLDEBUG|D_NOHEADER, "%s\n",oss.str().c_str()); // } FreeJobAd(ad); ad = NULL; } return STATUS_OK; }
bool ArgList::V2QuotedToV2Raw(char const *v1_input,MyString *v2_raw,MyString *errmsg) { if(!v1_input) return true; ASSERT(v2_raw); // allow leading whitespace while(isspace(*v1_input)) { v1_input++; } ASSERT(IsV2QuotedString(v1_input)); ASSERT(*v1_input == '"'); v1_input++; const char *quote_terminated = NULL; while(*v1_input) { if(*v1_input == '"') { v1_input++; if(*v1_input == '"') { // Repeated (i.e. escaped) double-quote. (*v2_raw) += *(v1_input++); } else { quote_terminated = v1_input-1; break; } } else { (*v2_raw) += *(v1_input++); } } if(!quote_terminated) { AddErrorMessage("Unterminated double-quote.",errmsg); return false; } // allow trailing whitespace while(isspace(*v1_input)) { v1_input++; } if(*v1_input) { if(errmsg) { MyString msg; msg.sprintf( "Unexpected characters following double-quote. " "Did you forget to escape the double-quote by repeating it? " "Here is the quote and trailing characters: %s\n",quote_terminated); AddErrorMessage(msg.Value(),errmsg); } return false; } return true; }
bool VMGahpServer::write_line(const char *command, int req, const char *args) { if( m_is_initialized == false ) { return false; } if( !command || m_vmgahp_writefd == -1 ) { return false; } MyString buf; buf.sprintf(" %d ",req); if( daemonCore->Write_Pipe(m_vmgahp_writefd,command,strlen(command)) <= 0 ) { dprintf( D_ALWAYS, "VMGAHP write line(%s) Error\n", command); return false; } if( daemonCore->Write_Pipe(m_vmgahp_writefd,buf.Value(),buf.Length()) <= 0 ) { dprintf( D_ALWAYS, "VMGAHP write line(%s) Error\n", buf.Value()); return false; } if( args ) { if( daemonCore->Write_Pipe(m_vmgahp_writefd,args,strlen(args)) <= 0 ) { dprintf( D_ALWAYS, "VMGAHP write line(%s) Error\n", args); return false; } } if( daemonCore->Write_Pipe(m_vmgahp_writefd,"\r\n",2) <= 0 ) { dprintf( D_ALWAYS, "VMGAHP write line(%s) Error\n", "\r\n"); return false; } MyString debug; if( args ) { debug.sprintf( "'%s%s%s'", command, buf.Value(), args ); } else { debug.sprintf( "'%s%s'", command, buf.Value() ); } dprintf( D_FULLDEBUG, "VMGAHP[%d] <- %s\n", m_vmgahp_pid, debug.Value() ); return true; }
int * OsProc::makeCpuAffinityMask(int slotId) { bool useAffinity = param_boolean("ENFORCE_CPU_AFFINITY", false); if (!useAffinity) { dprintf(D_FULLDEBUG, "ENFORCE_CPU_AFFINITY not true, not setting affinity\n"); return NULL; } // slotID of 0 means "no slot". Punt. if (slotId < 1) { return NULL; } MyString affinityParam; affinityParam.sprintf("SLOT%d_CPU_AFFINITY", slotId); char *affinityParamResult = param(affinityParam.Value()); if (affinityParamResult == NULL) { // No specific cpu, assume one-to-one mapping from slotid // to cpu affinity dprintf(D_FULLDEBUG, "Setting cpu affinity to %d\n", slotId - 1); int *mask = (int *) malloc(sizeof(int) * 2); ASSERT( mask != NULL ); mask[0] = 2; mask[1] = slotId - 1; // slots start at 1, cpus at 0 return mask; } StringList cpus(affinityParamResult); if (cpus.number() < 1) { dprintf(D_ALWAYS, "Could not parse affinity string %s, not setting affinity\n", affinityParamResult); free(affinityParamResult); return NULL; } int *mask = (int *) malloc(sizeof(int) * (cpus.number() + 1)); if ( ! mask) return mask; mask[0] = cpus.number() + 1; cpus.rewind(); char *cpu; int index = 1; while ((cpu = cpus.next())) { mask[index++] = atoi(cpu); } free(affinityParamResult); return mask; }
static int read_fd(int sock_fd) { MyString err; int bytes; int flag; bytes = full_read(0, &flag, sizeof(flag)); if (bytes != sizeof(flag)) { if (bytes == -1) { err.sprintf("read error getting flag: %s", strerror(errno)); } else { err.sprintf("short read of flag: %d of %lu bytes", bytes, sizeof(flag)); } full_write(sock_fd, err.Value(), err.Length() + 1); exit(1); } int fd; if (flag) { fd = fdpass_recv(sock_fd); if (fd == -1) { err.sprintf("fdpass_recv failed\n"); full_write(sock_fd, err.Value(), err.Length() + 1); exit(1); } } else { fd = open("/dev/null", O_RDONLY); if (fd == -1) { err.sprintf("error opening /dev/null: %s", strerror(errno)); full_write(sock_fd, err.Value(), err.Length() + 1); exit(1); } } return fd; }
bool OsProc::PublishUpdateAd( ClassAd* ad ) { dprintf( D_FULLDEBUG, "Inside OsProc::PublishUpdateAd()\n" ); MyString buf; if (m_proc_exited) { buf.sprintf( "%s=\"Exited\"", ATTR_JOB_STATE ); } else if( is_checkpointed ) { buf.sprintf( "%s=\"Checkpointed\"", ATTR_JOB_STATE ); } else if( is_suspended ) { buf.sprintf( "%s=\"Suspended\"", ATTR_JOB_STATE ); } else { buf.sprintf( "%s=\"Running\"", ATTR_JOB_STATE ); } ad->Insert( buf.Value() ); buf.sprintf( "%s=%d", ATTR_NUM_PIDS, num_pids ); ad->Insert( buf.Value() ); if (m_proc_exited) { if( dumped_core ) { buf.sprintf( "%s = True", ATTR_JOB_CORE_DUMPED ); ad->Insert( buf.Value() ); } // should we put in ATTR_JOB_CORE_DUMPED = false if not? } return UserProc::PublishUpdateAd( ad ); }
int ClassAdAssign(ClassAd & ad, const char * pattr, const Probe& probe) { MyString attr; attr.sprintf("%sCount", pattr); ad.Assign(attr.Value(), probe.Count); attr.sprintf("%sSum", pattr); int ret = ad.Assign(attr.Value(), probe.Sum); if (probe.Count > 0) { attr.sprintf("%sAvg", pattr); ad.Assign(attr.Value(), probe.Avg()); attr.sprintf("%sMin", pattr); ad.Assign(attr.Value(), probe.Min); attr.sprintf("%sMax", pattr); ad.Assign(attr.Value(), probe.Max); attr.sprintf("%sStd", pattr); ad.Assign(attr.Value(), probe.Std()); } return ret; }
//! Gets the writer password required by the quill++ // daemon to access the database static MyString getWritePassword(const char *write_passwd_fname, const char *host, const char *port, const char *db, const char *dbuser) { FILE *fp = NULL; MyString passwd; int len; MyString prefix; MyString msbuf; const char *buf; bool found = FALSE; // prefix is for the prefix of the entry in the .pgpass // it is in the format of the following: // host:port:db:user:password prefix.sprintf("%s:%s:%s:%s:", host, port, db, dbuser); len = prefix.Length(); fp = safe_fopen_wrapper(write_passwd_fname, "r"); if(fp == NULL) { EXCEPT("Unable to open password file %s\n", write_passwd_fname); } //dprintf(D_ALWAYS, "prefix: %s\n", prefix); while(msbuf.readLine(fp)) { msbuf.chomp(); buf = msbuf.Value(); //fprintf(stderr, "line: %s\n", buf); // check if the entry matches the prefix if (strncmp(buf, prefix.Value(), len) == 0) { // extract the password passwd = msbuf.Substr(len, msbuf.Length()); found = TRUE; break; } } fclose(fp); if (!found) { EXCEPT("Unable to find password from file %s\n", write_passwd_fname); } return passwd; }
void UserPolicy::SetDefaults() { MyString buf; ExprTree *ph_expr = m_ad->LookupExpr(ATTR_PERIODIC_HOLD_CHECK); ExprTree *pr_expr = m_ad->LookupExpr(ATTR_PERIODIC_REMOVE_CHECK); ExprTree *pl_expr = m_ad->LookupExpr(ATTR_PERIODIC_RELEASE_CHECK); ExprTree *oeh_expr = m_ad->LookupExpr(ATTR_ON_EXIT_HOLD_CHECK); ExprTree *oer_expr = m_ad->LookupExpr(ATTR_ON_EXIT_REMOVE_CHECK); /* if the default user policy expressions do not exist, then add them here and now with the usual defaults */ if (ph_expr == NULL) { buf.sprintf( "%s = FALSE", ATTR_PERIODIC_HOLD_CHECK ); m_ad->Insert( buf.Value() ); } if (pr_expr == NULL) { buf.sprintf( "%s = FALSE", ATTR_PERIODIC_REMOVE_CHECK ); m_ad->Insert( buf.Value() ); } if (pl_expr == NULL) { buf.sprintf( "%s = FALSE", ATTR_PERIODIC_RELEASE_CHECK ); m_ad->Insert( buf.Value() ); } if (oeh_expr == NULL) { buf.sprintf( "%s = FALSE", ATTR_ON_EXIT_HOLD_CHECK ); m_ad->Insert( buf.Value() ); } if (oer_expr == NULL) { buf.sprintf( "%s = TRUE", ATTR_ON_EXIT_REMOVE_CHECK ); m_ad->Insert( buf.Value() ); } }
MyString AvailStats::serialize() { MyString state; state.sprintf( "%ld %d %d", (long)(time(0)-as_birthdate), as_tot_avail_time, as_last_avail_interval ); as_avail_periods.Rewind(); int item; while( as_avail_periods.Next(item) ) { state.sprintf_cat( " %d", item ); } return state; }
void DBMSManager::InvalidatePublicAd() { ClassAd query_ad; SetMyTypeName(query_ad, QUERY_ADTYPE); SetTargetTypeName(query_ad, DBMSD_ADTYPE); MyString line; line.sprintf("%s = TARGET.%s == \"%s\"", ATTR_REQUIREMENTS, ATTR_NAME, m_name.Value()); query_ad.Insert(line.Value()); query_ad.Assign(ATTR_NAME,m_name.Value()); m_collectors->sendUpdates(INVALIDATE_ADS_GENERIC, &query_ad, NULL, true); //TODO/FIXME - delete the ads of the databases we're advertising return; }
/////////////////////////////////////////////////////////////////////////////// // Note: on Unix/Linux, the file ID is a string encoding the combination of // device number and inode; on Windows the file ID is simply the value // _fullpath() returns on the path we're given. The Unix/Linux version // is preferable because it will work correctly even if there are hard // links to log files; but there are no inodes on Windows, so we're // doing what we can. bool GetFileID( const MyString &filename, MyString &fileID, CondorError &errstack ) { // Make sure the log file exists. Even though we may later call // InitializeFile(), we have to make sure the file exists here // first so we make sure that the file exists and we can therefore // get an inode or real path for it. // We *don't* want to truncate the file here, though, because // we don't know for sure whether it's the first time we're seeing // it. if ( access( filename.Value(), F_OK ) != 0 ) { if ( !MultiLogFiles::InitializeFile( filename.Value(), false, errstack ) ) { errstack.pushf( "ReadMultipleUserLogs", UTIL_ERR_LOG_FILE, "Error initializing log file %s", filename.Value() ); return false; } } #ifdef WIN32 char *tmpRealPath = realpath( filename.Value(), NULL ); if ( !tmpRealPath ) { errstack.pushf( "ReadMultipleUserLogs", UTIL_ERR_LOG_FILE, "Error (%d, %s) getting real path for specified path %s", errno, strerror( errno ), filename.Value() ); return false; } fileID = tmpRealPath; free( tmpRealPath ); #else StatWrapper swrap; if ( swrap.Stat( filename.Value() ) != 0 ) { errstack.pushf( "ReadMultipleUserLogs", UTIL_ERR_LOG_FILE, "Error getting inode for log file %s", filename.Value() ); return false; } fileID.sprintf( "%llu:%llu", (unsigned long long)swrap.GetBuf()->st_dev, (unsigned long long)swrap.GetBuf()->st_ino ); #endif return true; }
bool StartdCronJobParams::Initialize( void ) { if ( !ClassAdCronJobParams::Initialize() ) { return false; } MyString slots_str; Lookup( "SLOTS", slots_str ); m_slots.clear(); StringList slot_list( slots_str.Value() ); slot_list.rewind(); const char *slot; while( ( slot = slot_list.next()) != NULL ) { if( !isdigit(*slot)) { dprintf( D_ALWAYS, "Cron Job '%s': INVALID slot # '%s': ignoring slot list", GetName(), slot ); m_slots.clear(); break; } unsigned slotno = atoi( slot ); m_slots.push_back( slotno ); } // Print out the slots for D_FULLDEBUG if ( IsFulldebug(D_FULLDEBUG) ) { MyString s; s.sprintf( "CronJob '%s' slots: ", GetName() ); if ( m_slots.empty() ) { s += "ALL"; } else { list<unsigned>::iterator iter; for( iter = m_slots.begin(); iter != m_slots.end(); iter++ ) { s.sprintf_cat( "%u ", *iter ); } } dprintf( D_ALWAYS, "%s\n", s.Value() ); } return true; };
bool UserProc::JobReaper(int pid, int status) { MyString line; MyString error_txt; MyString filename; const char* dir = Starter->GetWorkingDir(); FILE* fp; dprintf( D_FULLDEBUG, "Inside UserProc::JobReaper()\n" ); filename.sprintf("%s%c%s", dir, DIR_DELIM_CHAR, JOB_WRAPPER_FAILURE_FILE); if (0 == access(filename.Value(), F_OK)) { // The job wrapper failed, so read the contents of the file // and EXCEPT, just as is done when an executable is unable // to be run. Ideally, both failure cases would propagate // into the job ad fp = safe_fopen_wrapper_follow(filename.Value(), "r"); if (!fp) { dprintf(D_ALWAYS, "Unable to open \"%s\" for reading: " "%s (errno %d)\n", filename.Value(), strerror(errno), errno); } else { while (line.readLine(fp)) { error_txt += line; } fclose(fp); } error_txt.trim(); EXCEPT("The job wrapper failed to execute the job: %s", error_txt.Value()); } if (JobPid == pid) { m_proc_exited = true; exit_status = status; job_exit_time.getTime(); } return m_proc_exited; }
static char* read_env(int sock_fd) { MyString err; int bytes; int env_len; bytes = full_read(0, &env_len, sizeof(env_len)); if (bytes != sizeof(env_len)) { if (bytes == -1) { err.sprintf("read error getting env size: %s", strerror(errno)); } else { err.sprintf("short read of env size: %d of %lu bytes", bytes, sizeof(env_len)); } full_write(sock_fd, err.Value(), err.Length() + 1); exit(1); } if (env_len <= 0) { err.sprintf("invalid env size %d read from stdin", env_len); full_write(sock_fd, err.Value(), err.Length() + 1); exit(1); } char* env_buf = new char[env_len]; if (env_buf == NULL) { err.sprintf("failure to allocate %d bytes", env_len); full_write(sock_fd, err.Value(), err.Length() + 1); exit(1); } bytes = full_read(0, env_buf, env_len); if (bytes != env_len) { if (bytes == -1) { err.sprintf("read error getting env: %s", strerror(errno)); } else { err.sprintf("short read of env: %d of %d bytes", bytes, env_len); } full_write(sock_fd, err.Value(), err.Length() + 1); exit(1); } return env_buf; }