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

Re: [Condor-users] Checking if a binary file is compiled for condor



Hi, I've managed to get it to work using:

bool isLinked(char *filename)
{
	FILE *fp=fopen(filename,"r");
	
	if(fp==NULL)
	{
		perror("fopen");
		return false;
	}
	
	const char verstring[]="$CondorVersion: ";
	char ch;
	
	do{
		if((ch=fgetc(fp))=='$')
		{
			unsigned i=0;
			
			while((ch=fgetc(fp))==verstring[++i]);
			
			if(i==(strlen(verstring)))
			{
				while((ch=fgetc(fp))!='$') ++i;
				
				if((ch=fgetc(fp))=='\0' && i<50)
				{
					fclose(fp);
					return true;
				}
			}
		}
	}while(!feof(fp));

	fclose(fp);
	return false;
}

In effect this matches "$CondorVersion: <stuff> $\0" if the total
length is <50 chars. The 50 includes a fudge factor. My current magic
string length is 37:

Solid: bgoncalves$ strings test_condor | grep CondorVersion: | wc -c
      37
Solid: bgoncalves$
but I don't know if this is value is well defined or not.
Thanks,

Bruno

On 10/23/07, Erik Paulson <epaulson@xxxxxxxxxxx> wrote:
> On Tue, Oct 23, 2007 at 06:36:46PM -0400, Bruno Goncalves wrote:
> > Dear All,
> >
> > I would like to write a C/C++ program to verify if a given executable
> > has been compiled with condor_compile or not. In the command line, I
> > know that something like this:
> >
> > strings foo_condor.x | grep -m 1 condor_exec.exe | wc -l
> >
> > works, returning one (or zero) if the string condor_exec.exe is
> > defined (or not) inside the file foo_condor.x. Is there anyway of
> > detecting this inside C? For instance, how does condor check for this?
> > Thanks!
> >
>
> Condor opens up the file, scans through it looking for the string
> $CondorVersion:
> then reads to the next '$' character.
>
> It's not foolproof, if you submited the schedd as a std universe job it
> would say it's valid. (I suppose the more worrisome example would be
> forgetting universe=scheduler when submitting a DAGMan, since Condor
> might still default to the std universe for jobs)
>
> -Erik
>
>       // Look for the magic version string
>         // '$CondorVersion: x.y.z <date> <extra info> $' in the file.
>         // What we look for is a string that begins with '$CondorVersion: '
>         // and continues with a non-NULL character. We need to be careful
>         // not to match the string '$CondorVersion: \0' which this file
>         // includes as static data in a Condor executable.
>     int i = 0;
>     bool got_verstring = false;
>     const char* verprefix = "$CondorVersion: ";
>     int ch;
>     while( (ch=fgetc(fp)) != EOF ) {
>         if ( verprefix[i] == '\0' && ch != '\0' ) {
>             do {
>                 ver[i++] = ch;
>                 if ( ch == '$' ) {
>                     got_verstring = true;
>                     ver[i] = '\0';
>                     break;
>                 }
>             } while ( (i < maxlen) && ((ch=fgetc(fp)) != EOF) );
>             break;
>         }
>
>         if ( ch != verprefix[i] ) {
>             i = 0;
>             if ( ch != verprefix[0] ) {
>                 continue;
>             }
>         }
>
>         ver[i++] = ch;
>         }
> _______________________________________________
> Condor-users mailing list
> To unsubscribe, send a message to condor-users-request@xxxxxxxxxxx with a
> subject: Unsubscribe
> You can also unsubscribe by visiting
> https://lists.cs.wisc.edu/mailman/listinfo/condor-users
>
> The archives can be found at:
> https://lists.cs.wisc.edu/archive/condor-users/
>


-- 
*******************************************
Bruno Miguel Tavares Goncalves, MS
PhD Candidate
Emory University
Department of Physics
Office No. N117-C
400 Dowman Drive
Atlanta, Georgia 30322
Homepage: www.bgoncalves.com
Email: bgoncalves@xxxxxxxxx
Phone: (404) 712-2441
Fax:   (404) 727-0873
*******************************************