コード例 #1
0
// Read a file into a std::string.  Return false on error.
MyString
MultiLogFiles::readFile(char const *filename,std::string& buf)
{
    char chunk[4000];
	MyString rtnVal;

	int fd = safe_open_wrapper_follow(filename, O_RDONLY);
	if (fd < 0) {
		rtnVal.formatstr("error opening submit file %s: %s",
				filename, strerror(errno) );
		dprintf(D_ALWAYS, "%s\n", rtnVal.Value() );
		return rtnVal;
	}

    while(1) {
        size_t n = read(fd,chunk,sizeof(chunk)-1);
        if(n>0) {
            chunk[n] = '\0';
            buf += chunk;
        }
        else if(n==0) {
            break;
        }
        else {
            rtnVal.formatstr("failed to read submit file %s: %s",
					filename, strerror(errno) );
			dprintf(D_ALWAYS, "%s\n", rtnVal.Value() );
			close(fd);
			return rtnVal;
        }
    }

	close(fd);
    return rtnVal;
}
コード例 #2
0
ファイル: FTEST_tokener.cpp プロジェクト: bbockelm/htcondor
static bool test_tokener_parse_regex() {
    emit_test("Test tokener regex parsing");

	MyString msg;
	int fl;
	std::string temp;
	tokener toke("/(.*)/i");

	REQUIRE(toke.next() && toke.is_regex());
	REQUIRE(toke.copy_regex(temp,fl) && temp=="(.*)");
	if (fl != 1) {
		emit_step_failure(__LINE__, msg.formatstr("toke.copy_regex() returned pcre_flags==%d, should be 1", fl));
	}

	toke.set(" /([\\d]*)/i ");
	REQUIRE(toke.next() && toke.is_regex());
	REQUIRE(toke.copy_regex(temp,fl) && temp=="([\\d]*)");
	if (fl != 1) {
		emit_step_failure(__LINE__, msg.formatstr("toke.copy_regex() returned pcre_flags==%d, should be 1", fl));
	}

	toke.set(" /^Now is the|Time$/ ");
	REQUIRE(toke.next() && toke.is_regex());
	REQUIRE(toke.copy_regex(temp,fl) && temp=="^Now is the|Time$");
	if (fl != 0) {
		emit_step_failure(__LINE__, msg.formatstr("toke.copy_regex() returned pcre_flags==%d, should be 1", fl));
	}

	return REQUIRED_RESULT();
}
コード例 #3
0
ファイル: FTEST_tokener.cpp プロジェクト: bbockelm/htcondor
static bool test_unsorted_table() {
    emit_test("Test UNSORTED_TOKENER_TABLE");

	MyString msg;

	for (size_t ii = 0; ii < TestTbl.cItems; ++ii) {
		const char * key = TestTbl.pTable[ii].key;
		const TestTableItem * tti = UnTestTbl.lookup(key);
		if ( ! tti) {
			emit_step_failure(__LINE__, msg.formatstr("lookup('%s') returned NULL", key));
			continue;
		}
		if (tti->id != TestTbl.pTable[ii].id) {
			emit_step_failure(__LINE__, msg.formatstr("lookup('%s') returned '%s'", key, tti->key));
		}

		tokener toke(key); toke.next();
		tti = UnTestTbl.lookup_token(toke);
		if ( ! tti) {
			emit_step_failure(__LINE__, msg.formatstr("lookup_token('%s') returned NULL", key));
			continue;
		}
		if (tti->id != TestTbl.pTable[ii].id) {
			emit_step_failure(__LINE__, msg.formatstr("lookup_token('%s') returned '%s'", key, tti->key));
		}
	}

	return REQUIRED_RESULT();
}
コード例 #4
0
ファイル: FTEST_tokener.cpp プロジェクト: bbockelm/htcondor
static bool test_nocase_sorted_table() {
    emit_test("Test NOCASE SORTED_TOKENER_TABLE");

	MyString msg;

	// test the case sensitive sorted table
	for (size_t ii = 0; ii < UnTestTbl.cItems; ++ii) {
		const char * key = UnTestTbl.pTable[ii].key;
		int id = UnTestTbl.pTable[ii].id;
		if (id == item_aaa) { id = item_AAA; } //  This table has only the AAA item, not the aaa item.
		const TestTableItem * tti = NcTestTbl.lookup(key);
		if ( ! tti) {
			emit_step_failure(__LINE__, msg.formatstr("lookup('%s') returned NULL", key));
			continue;
		}
		if (tti->id != id) {
			emit_step_failure(__LINE__, msg.formatstr("lookup('%s') returned '%s'", key, tti->key));
		}

		tokener toke(key); toke.next();
		tti = NcTestTbl.lookup_token(toke);
		if ( ! tti) {
			emit_step_failure(__LINE__, msg.formatstr("lookup_token('%s') returned NULL", key));
			continue;
		}
		if (tti->id != id) {
			emit_step_failure(__LINE__, msg.formatstr("lookup_token('%s') returned '%s'", key, tti->key));
		}
	}

	return REQUIRED_RESULT();
}
コード例 #5
0
ファイル: file_sql.cpp プロジェクト: AlanDeSmet/htcondor
/*static */ FILESQL *
FILESQL::createInstance(bool use_sql_log) { 
	FILESQL *ptr = NULL;
	MyString outfilename = "";

	MyString param_name;
	param_name.formatstr("%s_SQLLOG", get_mySubSystem()->getName());

	char *tmp = param(param_name.Value());
	if( tmp ) {
		outfilename = tmp;
		free(tmp);
	}
	else {
		tmp = param ("LOG");		

		if (tmp) {
			outfilename.formatstr("%s/sql.log", tmp);
			free(tmp);
		}
		else {
			outfilename.formatstr("sql.log");
		}
	}

	ptr = new FILESQL(outfilename.Value(), O_WRONLY|O_CREAT|O_APPEND, use_sql_log);

	if (ptr->file_open() == QUILL_FAILURE) {
		dprintf(D_ALWAYS, "FILESQL createInstance failed\n");
	}

	return ptr;
}
コード例 #6
0
ファイル: file_sql.cpp プロジェクト: AlanDeSmet/htcondor
/*static */ void 
FILESQL::daemonAdInsert(
ClassAd *cl, 
const char *adType,
FILESQL *dbh, 
int &prevLHF)
{
	ClassAd clCopy;
	MyString tmp;
	
		// make a copy so that we can add timestamp attribute into it
	clCopy = *cl;
	
	tmp.formatstr("%s = %d", "PrevLastReportedTime", prevLHF);
	(&clCopy)->Insert(tmp.Value());

		// set the lastReportedTime and make it the new prevLHF
	prevLHF = (int)time(NULL);

	tmp.formatstr("%s = %d", "LastReportedTime", prevLHF);
	(&clCopy)->Insert(tmp.Value());

	ASSERT( dbh );
	dbh->file_newEvent(adType, &clCopy);	
}
コード例 #7
0
ファイル: hashkey.cpp プロジェクト: bbockelm/htcondor
void AdNameHashKey::sprint (MyString &s)
{
	if (ip_addr.Length() )
		s.formatstr( "< %s , %s >", name.Value(), ip_addr.Value() );
	else
		s.formatstr( "< %s >", name.Value() );
}
コード例 #8
0
ファイル: internet.cpp プロジェクト: dcbradley/htcondor
MyString generate_sinful(const char* ip, int port) {
	MyString buf;
	if (strchr(ip, ':')) {
		buf.formatstr("<[%s]:%d>", ip, port);
	} else {
		buf.formatstr("<%s:%d>", ip, port);
	}
	return buf;
}
コード例 #9
0
ファイル: transfer_data.cpp プロジェクト: AlainRoy/htcondor
void
procArg(const char* arg)
{
	int		c, p;								// cluster/proc #
	char*	tmp;

	MyString constraint;

	if(isdigit(*arg))
	// process by cluster/proc #
	{
		c = strtol(arg, &tmp, 10);
		if(c <= 0)
		{
			fprintf(stderr, "Invalid cluster # from %s.\n", arg);
			had_error = true;
			return;
		}
		if(*tmp == '\0')
		// delete the cluster
		{
			constraint.formatstr( "%s==%d", ATTR_CLUSTER_ID, c );
			addConstraint(constraint.Value());
			return;
		}
		if(*tmp == '.')
		{
			p = strtol(tmp + 1, &tmp, 10);
			if(p < 0)
			{
				fprintf( stderr, "Invalid proc # from %s.\n", arg);
				had_error = 1;
				return;
			}
			if(*tmp == '\0')
			// process a proc
			{
				constraint.formatstr( "(%s==%d && %s==%d)", 
					ATTR_CLUSTER_ID, c,
					ATTR_PROC_ID, p);
				addConstraint(constraint.Value());
				return;
			}
		}
		fprintf( stderr, "Warning: unrecognized \"%s\" skipped.\n", arg );
		return;
	}
	else if(isalpha(*arg))
	// process by user name
	{
		constraint.formatstr( "%s == \"%s\"", ATTR_OWNER, arg );
		addConstraint(constraint.Value());
	} else {
		fprintf( stderr, "Warning: unrecognized \"%s\" skipped\n", arg );
	}
}
コード例 #10
0
void stats_recent_counter_timer::Unpublish(ClassAd & ad, const char * pattr) const
{
   ad.Delete(pattr);
   MyString attr;
   attr.formatstr("Recent%s",pattr);
   ad.Delete(attr.Value());
   attr.formatstr("Recent%sRuntime",pattr);
   ad.Delete(attr.Value());
   ad.Delete(attr.Value()+6); // +6 to skip "Recent" prefix
}
コード例 #11
0
/* Function   : finalizeDelta
 * Description: clears and resets all inner structures and data members declared
 *				in this class only (excluding inherited classes)
 */
void
ReplicatorStateMachine::finalizeDelta( )
{
    ClassAd invalidate_ad;
    MyString line;

    dprintf( D_ALWAYS, "ReplicatorStateMachine::finalizeDelta started\n" );
    utilCancelTimer(m_replicationTimerId);
    utilCancelTimer(m_versionRequestingTimerId);
    utilCancelTimer(m_versionDownloadingTimerId);
    utilCancelTimer(m_updateCollectorTimerId);
    m_replicationInterval               = -1;
    m_hadAliveTolerance                 = -1;
    m_maxTransfererLifeTime             = -1;
    m_newlyJoinedWaitingVersionInterval = -1;
    m_lastHadAliveTime                  = -1;
    m_updateInterval                    = -1;

    if ( m_classAd != NULL ) {
        delete m_classAd;
        m_classAd = NULL;
    }

    SetMyTypeName( invalidate_ad, QUERY_ADTYPE );
    SetTargetTypeName( invalidate_ad, "Replication" );
    line.formatstr( "TARGET.%s == \"%s\"", ATTR_NAME, m_name.Value( ) );
    invalidate_ad.AssignExpr( ATTR_REQUIREMENTS, line.Value( ) );
	invalidate_ad.Assign( ATTR_NAME, m_name.Value() );
    daemonCore->sendUpdates( INVALIDATE_ADS_GENERIC, &invalidate_ad, NULL, false );
}
コード例 #12
0
ファイル: job.cpp プロジェクト: Clusterforge/htcondor
bool
Job::AddScript( bool post, const char *cmd, int defer_status, time_t defer_time, MyString &whynot )
{
	if( !cmd || strcmp( cmd, "" ) == 0 ) {
		whynot = "missing script name";
		return false;
	}
	if( post ? _scriptPost : _scriptPre ) {
		whynot.formatstr( "%s script already assigned (%s)",
						post ? "POST" : "PRE", GetPreScriptName() );
		return false;
	}
	Script* script = new Script( post, cmd, defer_status, defer_time, 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;
}
コード例 #13
0
/**
 * Before evaluating user policy expressions, temporarily update
 * any stale time values.  Currently, this is just RemoteWallClock.
 * 
 * @param old_run_time - we will put the job's old run time in this
 **/
void
BaseUserPolicy::updateJobTime( float *old_run_time )
{
	if ( ! this->job_ad ) {
		return;
	}

	float previous_run_time, total_run_time;
	time_t now = time(NULL);

	job_ad->LookupFloat( ATTR_JOB_REMOTE_WALL_CLOCK, previous_run_time );

		//
		// The objects that extend this class will need to 
		// implement how we can determine the start time for
		// a job
		//
	int bday = this->getJobBirthday( );
	
	total_run_time = previous_run_time;
	if ( old_run_time ) {
		*old_run_time = previous_run_time;
	}
	if ( bday ) {
		total_run_time += (now - bday);
	}
	
	MyString buf;
	buf.formatstr( "%s = %f", ATTR_JOB_REMOTE_WALL_CLOCK, total_run_time );
	this->job_ad->Insert( buf.Value() );
}
コード例 #14
0
int
main(int argc, char *argv[])
{
	myDistro->Init( argc, argv );
	if (argc != 2) {
		fprintf(stderr, "usage: %s collection-file\n", argv[0]);
	}

	// rename the collection file to some temporary file, so we don't
	// mess up the actual collection file
	char tmpfile[L_tmpnam];
	tmpnam(tmpfile);
	MyString cmd;
	cmd.formatstr( "cp %s %s", argv[1], tmpfile);
	system(cmd.Value());
	
	ClassAdCollection c(tmpfile);

	c.StartIterateAllCollections();

	ClassAd *ad = NULL; 
	while (c.IterateAllClassAds(ad)) {
		fPrintAd(stdout, *ad);
		printf("\n");
	}

	unlink(tmpfile);

	return 0;
}
コード例 #15
0
ファイル: user_proc.cpp プロジェクト: AlainRoy/htcondor
void
set_iwd()
{
	char	*iwd = NULL;

	if( REMOTE_CONDOR_get_iwd(iwd) < 0 ) {
		REMOTE_CONDOR_report_error(const_cast<char*>("Can't determine initial working directory"));
		exit( 4 );
	}

	if( chdir(iwd) < 0 ) {

		int rval = -1;
		for (int count = 0; count < 360 && rval == -1 &&
				 (errno == ETIMEDOUT || errno == ENODEV); count++) {
			dprintf(D_FAILURE|D_ALWAYS, "Connection timed out on chdir(%s), trying again"
					" in 5 seconds\n", iwd);
			sleep(5);
			rval = chdir(iwd);
		}
		if (errno == ETIMEDOUT || errno == ENODEV) {
			EXCEPT("Connection timed out for 30 minutes on chdir(%s)", iwd);
		}
			
		MyString err;
		err.formatstr( "Can't open working directory \"%s\": %s", iwd,
			    strerror(errno) );
		REMOTE_CONDOR_report_error(const_cast<char *>(err.Value()));
		exit( 4 );
	}
	free( iwd );
}
コード例 #16
0
ファイル: ccb_listener.cpp プロジェクト: osg-bosco/htcondor
bool
CCBListener::RegisterWithCCBServer(bool blocking)
{
	ClassAd msg;

	if( m_waiting_for_connect || m_reconnect_timer != -1 || m_waiting_for_registration || m_registered) {
			// already registered or being registered
		return m_registered;
	}

	msg.Assign( ATTR_COMMAND, CCB_REGISTER );
	if( !m_ccbid.IsEmpty() ) {
		// we are reconnecting; trying to preserve ccbid so that prospective
		// clients with stale information can still contact us
		msg.Assign( ATTR_CCBID, m_ccbid.Value() );
		msg.Assign( ATTR_CLAIM_ID, m_reconnect_cookie.Value() );
	}

		// for debugging purposes only, identify ourselves to the CCB server
	MyString name;
	name.formatstr("%s %s",get_mySubSystem()->getName(),daemonCore->publicNetworkIpAddr());
	msg.Assign( ATTR_NAME, name.Value() );

	bool success = SendMsgToCCB(msg,blocking);
	if( success ) {
		if( blocking ) {
			success = ReadMsgFromCCB();
		}
		else {
			// now we wait for CCB server to respond with our CCBID
			m_waiting_for_registration = true;
		}
	}
	return success;
}
コード例 #17
0
ファイル: jic_local.cpp プロジェクト: AlainRoy/htcondor
char* 
JICLocal::getJobStdFile( const char* attr_name )
{
	char* tmp = NULL;
	MyString filename;

		// the only magic here is to make sure we have full paths for
		// these, by prepending the job's iwd if the filename doesn't
		// start with a '/'
	job_ad->LookupString( attr_name, &tmp );
	if( ! tmp ) {
		return NULL;
	}
	if ( !nullFile(tmp) ) {
		if( ! fullpath(tmp) ) { 
			filename.formatstr( "%s%c", job_iwd, DIR_DELIM_CHAR );
		}
		filename += tmp;
	}
	free( tmp );
	if( filename[0] ) { 
		return strdup( filename.Value() );
	}
	return NULL;
}
コード例 #18
0
ファイル: job.cpp プロジェクト: Clusterforge/htcondor
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.formatstr( "%s child may not be given a new %s parent",
						this->GetStatusName(), parent->GetStatusName() );
		return false;
	}
	whynot = "n/a";
	return true;
}
コード例 #19
0
ファイル: slot_builder.cpp プロジェクト: AmesianX/htcondor
void initTypes( int max_types, StringList **type_strings, int except )
{
	int i;
	char* tmp;
	MyString buf;

	_checkInvalidParam("SLOT_TYPE_0", except);
		// CRUFT
	_checkInvalidParam("VIRTUAL_MACHINE_TYPE_0", except);

	if (! type_strings[0]) {
			// Type 0 is the special type for evenly divided slots.
		type_strings[0] = new StringList();
		type_strings[0]->initializeFromString("auto");
	}

	for( i=1; i < max_types; i++ ) {
		if( type_strings[i] ) {
			continue;
		}
		buf.formatstr("SLOT_TYPE_%d", i);
		tmp = param(buf.Value());
		if (!tmp) {
			if (param_boolean("ALLOW_VM_CRUFT", false)) {
				buf.formatstr("VIRTUAL_MACHINE_TYPE_%d", i);
				if (!(tmp = param(buf.Value()))) {
					continue;
				}
			} else {
				continue;
			}
		}
		type_strings[i] = new StringList();
		type_strings[i]->initializeFromString( tmp );
		free( tmp );
#if 0
		// check for pairings
		buf += "PAIRED_WITH";
		tmp = param(buf.Value());
		if ( ! tmp)
			continue;
		PRAGMA_REMIND("tj: treating the slot that has PAIRED_WITH as subordinate! fix this!")
		type_strings[i]->insert("minimal");
		free (tmp);
#endif
	}
}
コード例 #20
0
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.formatstr( "%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;
}
コード例 #21
0
const char * DCloudResource::HashName( const char *resource_name,
									   const char *username,
									   const char *password )
{
	static MyString hash_name;
	hash_name.formatstr( "%s#%s#%s", resource_name, username, password );
	return hash_name.Value();
}
コード例 #22
0
struct chirp_client *
chirp_client_connect_starter()
{
    FILE *file;
    int fields;
    struct chirp_client *client;
    char *default_filename;
    char host[CONDOR_HOSTNAME_MAX];
    char cookie[CHIRP_LINE_MAX];
	MyString path;
    int port;
    int result;
	const char *dir;

	if ((default_filename = getenv("_CONDOR_CHIRP_CONFIG"))) {
		path.formatstr( "%s", default_filename );
	} else {
		if (NULL == (dir = getenv("_CONDOR_SCRATCH_DIR"))) {
			dir = ".";
		}
		path.formatstr( "%s%c%s",dir,DIR_DELIM_CHAR,".chirp.config");
	}
    file = safe_fopen_wrapper_follow(path.Value(),"r");
    if(!file) {
		fprintf(stderr, "Can't open %s file\n",path.Value());
		return 0;
	}

    fields = fscanf(file,"%s %d %s",host,&port,cookie);
    fclose(file);

    if(fields!=3) {
        errno = EINVAL;
        return 0;
    }

    client = chirp_client_connect(host,port);
    if(!client) return 0;

    result = chirp_client_cookie(client,cookie);
    if(result!=0) {
		DISCONNECT_AND_RETURN(client, 0);
    }

    return client;
}
コード例 #23
0
//Process related functions
BOOL SystemHandleInformation::GetProcessPath( HANDLE h, MyString& strPath, DWORD remoteProcessId )
{
	h; strPath; remoteProcessId;

	strPath.formatstr( "%d", remoteProcessId );

	return TRUE;
}
コード例 #24
0
ファイル: condor_sockaddr.cpp プロジェクト: cwmartin/htcondor
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.formatstr("<%s:%d>", tmp, ntohs(v4.sin_port));
	}
	else if (is_ipv6()) {
		ret.formatstr("<[%s]:%d>", tmp, ntohs(v6.sin6_port));
	}

	return ret;
}
コード例 #25
0
ファイル: mpiresource.cpp プロジェクト: AlainRoy/htcondor
void 
MpiResource::printExit( FILE *fp )
{
	MyString line;
	line.formatstr( "%25s    ", machineName ? machineName : "Unknown machine" );
	printExitString( jobAd, exit_reason, line );
	fprintf( fp, "%s\n", line.Value() );
}
コード例 #26
0
ファイル: ccb_listener.cpp プロジェクト: osg-bosco/htcondor
bool
CCBListener::DoReversedCCBConnect( char const *address, char const *connect_id, char const *request_id, char const *peer_description )
{
	Daemon daemon( DT_ANY, address );
	CondorError errstack;
	Sock *sock = daemon.makeConnectedSocket(
		Stream::reli_sock,CCB_TIMEOUT,0,&errstack,true /*nonblocking*/);

	ClassAd *msg_ad = new ClassAd;
	ASSERT( msg_ad );
	msg_ad->Assign( ATTR_CLAIM_ID, connect_id );
	msg_ad->Assign( ATTR_REQUEST_ID, request_id );
		// the following is put in the message because that is an easy (lazy)
		// way to make it available to ReportReverseConnectResult
	msg_ad->Assign( ATTR_MY_ADDRESS, address);

	if( !sock ) {
			// Failed to create socket or initiate connect
		ReportReverseConnectResult(msg_ad,false,"failed to initiate connection");
		delete msg_ad;
		return false;
	}

	if( peer_description ) {
		char const *peer_ip = sock->peer_ip_str();
		if( peer_ip && !strstr(peer_description,peer_ip)) {
			MyString desc;
			desc.formatstr("%s at %s",peer_description,sock->get_sinful_peer());
			sock->set_peer_description(desc.Value());
		}
		else {
			sock->set_peer_description(peer_description);
		}
	}

	incRefCount();      // do not delete self until called back

	MyString sock_desc;
	int rc = daemonCore->Register_Socket(
		sock,
		sock->peer_description(),
		(SocketHandlercpp)&CCBListener::ReverseConnected,
		"CCBListener::ReverseConnected",
		this);

	if( rc < 0 ) {
		ReportReverseConnectResult(msg_ad,false,"failed to register socket for non-blocking reversed connection");
		delete msg_ad;
		delete sock;
		decRefCount();
		return false;
	}

	rc = daemonCore->Register_DataPtr(msg_ad);
	ASSERT( rc );

	return true;
}
コード例 #27
0
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.formatstr("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);
}
コード例 #28
0
template <> void stats_entry_recent<Probe>::Unpublish(ClassAd& ad, const char * pattr) const
{
   MyString attr;
   ad.Delete(pattr);
   attr.formatstr("Recent%s", pattr);
   ad.Delete(attr.Value());

   attr.formatstr("Recent%sCount", pattr);
   ad.Delete(attr.Value());
   ad.Delete(attr.Value()+6);
   attr.formatstr("Recent%sSum", pattr);
   ad.Delete(attr.Value());
   ad.Delete(attr.Value()+6);
   attr.formatstr("Recent%sAvg", pattr);
   ad.Delete(attr.Value());
   ad.Delete(attr.Value()+6);
   attr.formatstr("Recent%sMin", pattr);
   ad.Delete(attr.Value());
   ad.Delete(attr.Value()+6);
   attr.formatstr("Recent%sMax", pattr);
   ad.Delete(attr.Value());
   ad.Delete(attr.Value()+6);
   attr.formatstr("Recent%sStd", pattr);
   ad.Delete(attr.Value());
   ad.Delete(attr.Value()+6);
}
コード例 #29
0
char *
Condor_Auth_Passwd::fetchLogin()
{
	// return malloc-ed string "user@domain" that represents who we are.

	MyString login;
	
		// decide the login name we will try to authenticate with.  
	if ( is_root() ) {
		login.formatstr("%s@%s",POOL_PASSWORD_USERNAME,getLocalDomain());
	} else {
		// for now, always use the POOL_PASSWORD_USERNAME.  at some
		// point this code should call my_username() my_domainname().
		login.formatstr("%s@%s",POOL_PASSWORD_USERNAME,getLocalDomain());
	}

	return strdup( login.Value() );
}
コード例 #30
0
ファイル: os_proc.cpp プロジェクト: valtri/htcondor
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;
	}

	char *affinityParamResult = param("STARTD_ASSIGNED_AFFINITY");
	if (!affinityParamResult) {
		MyString affinityParam;
		affinityParam.formatstr("SLOT%d_CPU_AFFINITY", slotId);
		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;
}