HTCondor Project List Archives



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Condor-devel] [Condor-team] <SUBSYSTE>_ADDRESS_FILE



On Mon, Dec 18, 2006 at 09:51:26PM -0600, Erik Paulson wrote:
> On Tue, Aug 29, 2006 at 05:10:30PM -0500, Erik Paulson wrote:
>
> I am not heart-set on any of the config file names, so any substitutions
> are welcome. It's against the trunk. If you want to see it in context, see
> /p/condor/workspaces/epaulson.1/src_trees/V69
> 

Attached is a 2nd version - this one uses the counted_ptr class to not
leak a ClassAd. It appears to be the first use of the class in Condor. :)
Hopefully more things will start using counted_ptrs after this. 

The fact that getDaemonInfo() bails out if it sees it's already got a valid 
address (without figuring out the name of the daemon) might be a problem for 
quill++ eventually, but we'll solve that some other day.

-Erik

Index: condor_daemon_client/daemon.C
===================================================================
RCS file: /p/condor/repository/CONDOR_SRC/src/condor_daemon_client/daemon.C,v
retrieving revision 1.7
diff -r1.7 daemon.C
45a46,47
> #include "counted_ptr.h"
> 
101c103
< 	dprintf( D_HOSTNAME, "New Daemon obj (%s) name: \"%s\", pool: "
---
> 	dprintf( D_HOSTNAME, "New Daemon obj (%s) name: \"%s\", pool: "  
1285c1287,1290
< 		readAddressFile( subsys );
---
> 		bool foundLocalAd = readLocalClassAd( subsys );
> 		if(!foundLocalAd) {
> 			readAddressFile( subsys );
> 		}
1800a1806,1868
> bool
> Daemon::readLocalClassAd( const char* subsys )
> {
> 	char* addr_file;
> 	FILE* addr_fp;
> 	ClassAd *adFromFile;
> 	MyString param_name;
> 	MyString buf;
> 
> 	param_name.sprintf( "%s_DAEMON_AD_FILE", subsys );
> 	addr_file = param( param_name.Value() );
> 	if( ! addr_file ) {
> 		return false;
> 	}
> 
> 	dprintf( D_HOSTNAME, "Finding classad for local daemon, "
> 			 "%s is \"%s\"\n", param_name.Value(), addr_file );
> 
> 	if( ! (addr_fp = fopen(addr_file, "r")) ) {
> 		dprintf( D_HOSTNAME,
> 				 "Failed to open classad file %s: %s (errno %d)\n",
> 				 addr_file, strerror(errno), errno );
> 		free( addr_file );
> 		return false;
> 	}
> 		// now that we've got a FILE*, we should free this so we don't
> 		// leak it.
> 	free( addr_file );
> 	addr_file = NULL;
> 
> 	int adIsEOF, errorReadingAd, adEmpty = 0;
> 	adFromFile = new ClassAd(addr_fp, "...", adIsEOF, errorReadingAd, adEmpty);
> 	ASSERT(adFromFile);
> 	counted_ptr<ClassAd> smart_ad_ptr(adFromFile);
> 	
> 	fclose(addr_fp);
> 
> 	if(errorReadingAd) {
> 		return false;	// did that just leak adFromFile?
> 	}
> 
> 	// construct the IP_ADDR attribute
> 	buf.sprintf( "%sIpAddr", subsys );
> 	if( initStringFromAd(smart_ad_ptr, buf.Value(), &_addr) ) {
> 		_tried_locate = true;		
> 	} else { return false; }
> 
> 	if( initStringFromAd( smart_ad_ptr, ATTR_VERSION, &_version ) ) {
> 		_tried_init_version = true;
> 	} else { return false; }
> 
> 	initStringFromAd( smart_ad_ptr, ATTR_PLATFORM, &_platform );
> 
> 	initStringFromAd( smart_ad_ptr, ATTR_NAME, &_name );
> 
> 	if( initStringFromAd( smart_ad_ptr, ATTR_MACHINE, &_full_hostname ) ) {
> 		initHostnameFromFull();
> 		_tried_init_hostname = false;
> 	} else { return false; }
> 
> 	return true;
> }
> 
1824c1892
< 	dprintf( D_HOSTNAME, "Found %s in ClassAd from collector, "
---
> 	dprintf( D_HOSTNAME, "Found %s in ClassAd from ClassAd, "
1830a1899,1904
> bool
> Daemon::initStringFromAd( counted_ptr<class ClassAd>& ad, const char* attrname, char** value )
> {
> 	return initStringFromAd( ad.get(), attrname, value);
> }
> 
Index: condor_daemon_client/daemon.h
===================================================================
RCS file: /p/condor/repository/CONDOR_SRC/src/condor_daemon_client/daemon.h,v
retrieving revision 1.6
diff -r1.6 daemon.h
37a38
> template <class p> class counted_ptr; // Forward declaration
536a538,543
> 		/** Code for parsing a locally-written classad, which should
> 			contain everything about the daemon
> 			@return true if we found everthing in the ad, false if not
> 		*/
> 	bool readLocalClassAd( const char* subsys );
> 
553a561,563
> 	bool initStringFromAd(counted_ptr<class ClassAd>& ad, const char* attrname, 
> 		char** value_str );
> 
Index: condor_daemon_core.V6/condor_daemon_core.h
===================================================================
RCS file: /p/condor/repository/CONDOR_SRC/src/condor_daemon_core.V6/condor_daemon_core.h,v
retrieving revision 1.48
diff -r1.48 condor_daemon_core.h
1036a1037,1039
> 	char 	*localAdFile;
> 	void	UpdateLocalAd(ClassAd *daemonAd); 
> 
Index: condor_daemon_core.V6/daemon_core.C
===================================================================
RCS file: /p/condor/repository/CONDOR_SRC/src/condor_daemon_core.V6/daemon_core.C,v
retrieving revision 1.95
diff -r1.95 daemon_core.C
356a357,358
> 	
> 	localAdFile = NULL;
469a472,478
> 
> 		
> 	if(localAdFile) {
> 		free(localAdFile);
> 		localAdFile = NULL;
> 	}
> 	
8222a8232,8259
> 
> 
> void
> DaemonCore::UpdateLocalAd(ClassAd *daemonAd) 
> {
>     FILE    *AD_FILE;
>     char    localAd_path[100];
> 
>     sprintf( localAd_path, "%s_DAEMON_AD_FILE", mySubSystem );
> 
> 	//localAdFile is a global from daemon_core_main.C
>     if( localAdFile ) {
>         free( localAdFile );
>     }
>     localAdFile = param( localAd_path );
> 
>     if( localAdFile ) {
>         if( (AD_FILE = fopen(localAdFile, "w")) ) {
>             daemonAd->fPrint(AD_FILE);
>             fclose( AD_FILE );
>         } else {
>             dprintf( D_ALWAYS,
>                      "DaemonCore: ERROR: Can't open daemon address file %s\n",
>                      localAdFile );
>         }
>     }
> }
> 
Index: condor_daemon_core.V6/daemon_core_main.C
===================================================================
RCS file: /p/condor/repository/CONDOR_SRC/src/condor_daemon_core.V6/daemon_core_main.C,v
retrieving revision 1.70
diff -r1.70 daemon_core_main.C
193a194,211
> 	
> 	if(daemonCore) {
> 		if( daemonCore->localAdFile ) {
> 			if( unlink(daemonCore->localAdFile) < 0 ) {
> 				dprintf( D_ALWAYS, 
> 						 "DaemonCore: ERROR: Can't delete classad file %s\n",
> 						 daemonCore->localAdFile );
> 			} else {
> 				if( DebugFlags & (D_FULLDEBUG | D_DAEMONCORE) ) {
> 					dprintf( D_DAEMONCORE, "Removed local classad file %s\n", 
> 							 daemonCore->localAdFile );
> 				}
> 			}
> 			free( daemonCore->localAdFile );
> 			daemonCore->localAdFile = NULL;
> 		}
> 	}
> 
268d285
< 
Index: condor_schedd.V6/schedd.C
===================================================================
RCS file: /p/condor/repository/CONDOR_SRC/src/condor_schedd.V6/schedd.C,v
retrieving revision 1.246
diff -r1.246 schedd.C
9791a9792,9798
> 	// This is foul, but a SCHEDD_ADTYPE _MUST_ have a NUM_USERS attribute
> 	// (see condor_classad/classad.C
> 	// Since we don't know how many there are yet, just say 0, it will get
> 	// fixed in count_job() -Erik 12/18/2006
> 	sprintf(expr, "%s = %d", ATTR_NUM_USERS, 0);
>     ad->Insert(expr);
> 
9868a9876
> 	daemonCore->UpdateLocalAd(ad);