<commit_before>#define _POSIX_SOURCE

#include "afs.h"
#include "condor_common.h"
#include "condor_config.h"
#include "condor_debug.h"
#include "condor_constants.h"
#include "subproc.h"
#include <string.h>

static char *_FileName_ = __FILE__;     // Used by EXCEPT (see condor_debug.h)

AFS_Info::AFS_Info()
{
	char	*tmp;

	my_cell_name = 0;

		// find out if we're running AFS here
	if( (tmp=param("HAS_AFS")) == NULL ) {
		has_afs = FALSE;
		return;
	}
	if( tmp[0] == 't' || tmp[0] == 'T' ) {
		has_afs = TRUE;
	} else {
		free( tmp );	/* BUG FIXED : Ashish */
		has_afs = FALSE;
		return;
	}
	free( tmp );	/* BUG FIXED : Ashish */

		// get pathname for the "fs" program
	if( (tmp=param("FS_PATHNAME")) == NULL ) {
		EXCEPT( "FS_PATHNAME not defined" );
	}
	strcpy( fs_pathname, tmp );
	free( tmp );	 /* BUG FIXED : Ashish */

		// get pathname for the "vos" program
	if( (tmp=param("VOS_PATHNAME")) == NULL ) {
		EXCEPT( "VOS_PATHNAME not defined" );
	}
	strcpy( vos_pathname, tmp );
	free( tmp );	/* BUG FIXED : Ashish */

	my_cell_name = 0;
}

AFS_Info::~AFS_Info()
{
	delete [] my_cell_name;
}

void
AFS_Info::display()
{
	if( !has_afs ) {
		dprintf( D_ALWAYS, "This machine doesn't run AFS\n" );
		return;
	}
	dprintf( D_ALWAYS, "fs_pathname: \"%s\"\n", fs_pathname );
	dprintf( D_ALWAYS, "vos_pathname: \"%s\"\n", vos_pathname );
	if( my_cell_name ) {
		dprintf( D_ALWAYS, "my_cell_name: \"%s\"\n", my_cell_name );
	} else {
		dprintf( D_ALWAYS, "my_cell_name: \"%s\"\n", "(NULL)" );
	}
}

char *
AFS_Info::my_cell()
{
	char	*ptr;

	if( !my_cell_name ) {

			// find out what AFS cell we're in
		if( (ptr=find_my_cell()) == NULL ) {
			return NULL;
		}
		my_cell_name = new char[ strlen(ptr) + 1 ];
		strcpy( my_cell_name, ptr );
	}
	return my_cell_name;
}

/*
  Use the "fs wscell" command to find the AFS cell of this host.
*/
char *
AFS_Info::find_my_cell()
{
	char 	*answer;
	char	buf[_POSIX_PATH_MAX ];
	FILE	*fp;
	char	*ptr;
	SubProc	p( fs_pathname, "wscell", "r" );

	if( !has_afs ) {
		return NULL;
	}
	return p.parse_output( "belongs to cell", "'", "'" );
}


/*
  Use the "fs whichcell" command to find the AFS cell of the given pathname.
*/
char *
AFS_Info::which_cell( const char *path )
{
	char 	*answer;
	char	args[ _POSIX_PATH_MAX ];
	FILE	*fp;
	SubProc	*fs;

	if( !has_afs ) {
		return NULL;<commit_msg>changed AFS_Info::find_my_cell() to check has_afs _first_, because if it is not true, then fs_pathname string is used uninitialized.<commit_after>#define _POSIX_SOURCE

#include "afs.h"
#include "condor_common.h"
#include "condor_config.h"
#include "condor_debug.h"
#include "condor_constants.h"
#include "subproc.h"
#include <string.h>

static char *_FileName_ = __FILE__;     // Used by EXCEPT (see condor_debug.h)

AFS_Info::AFS_Info()
{
	char	*tmp;

	my_cell_name = 0;

		// find out if we're running AFS here
	if( (tmp=param("HAS_AFS")) == NULL ) {
		has_afs = FALSE;
		return;
	}
	if( tmp[0] == 't' || tmp[0] == 'T' ) {
		has_afs = TRUE;
	} else {
		free( tmp );	/* BUG FIXED : Ashish */
		has_afs = FALSE;
		return;
	}
	free( tmp );	/* BUG FIXED : Ashish */

		// get pathname for the "fs" program
	if( (tmp=param("FS_PATHNAME")) == NULL ) {
		EXCEPT( "FS_PATHNAME not defined" );
	}
	strcpy( fs_pathname, tmp );
	free( tmp );	 /* BUG FIXED : Ashish */

		// get pathname for the "vos" program
	if( (tmp=param("VOS_PATHNAME")) == NULL ) {
		EXCEPT( "VOS_PATHNAME not defined" );
	}
	strcpy( vos_pathname, tmp );
	free( tmp );	/* BUG FIXED : Ashish */

	my_cell_name = 0;
}

AFS_Info::~AFS_Info()
{
	delete [] my_cell_name;
}

void
AFS_Info::display()
{
	if( !has_afs ) {
		dprintf( D_ALWAYS, "This machine doesn't run AFS\n" );
		return;
	}
	dprintf( D_ALWAYS, "fs_pathname: \"%s\"\n", fs_pathname );
	dprintf( D_ALWAYS, "vos_pathname: \"%s\"\n", vos_pathname );
	if( my_cell_name ) {
		dprintf( D_ALWAYS, "my_cell_name: \"%s\"\n", my_cell_name );
	} else {
		dprintf( D_ALWAYS, "my_cell_name: \"%s\"\n", "(NULL)" );
	}
}

char *
AFS_Info::my_cell()
{
	char	*ptr;

	if( !my_cell_name ) {

			// find out what AFS cell we're in
		if( (ptr=find_my_cell()) == NULL ) {
			return NULL;
		}
		my_cell_name = new char[ strlen(ptr) + 1 ];
		strcpy( my_cell_name, ptr );
	}
	return my_cell_name;
}

/*
  Use the "fs wscell" command to find the AFS cell of this host.
*/
char *
AFS_Info::find_my_cell()
{
	char 	*answer;
	char	buf[_POSIX_PATH_MAX ];
	FILE	*fp;
	char	*ptr;

	// must check has_afs _first_, because if it is not true,
	// then fs_pathname is unitialized.  -Todd 7/97
	if( !has_afs ) {
		return NULL;
	}

	SubProc	p( fs_pathname, "wscell", "r" );
	return p.parse_output( "belongs to cell", "'", "'" );
}


/*
  Use the "fs whichcell" command to find the AFS cell of the given pathname.
*/
char *
AFS_Info::which_cell( const char *path )
{
	char 	*answer;
	char	args[ _POSIX_PATH_MAX ];
	FILE	*fp;
	SubProc	*fs;

	if( !has_afs ) {
		return NULL;
{'fraction_non_alphanumeric': 0.16584766584766586, 'fraction_numerical': 0.0026617526617526617, 'mean_word_length': 3.5484171322160147, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2068664', 'n_tokens_mistral': 2207, 'n_tokens_neox': 2104, 'n_words': 518}