Beispiel #1
0
void Defrag::saveState()
{
	ClassAd ad;
	ad.Assign(ATTR_LAST_POLL,(int)m_last_poll);

	std::string new_state_file;
	sprintf(new_state_file,"%s.new",m_state_file.c_str());
	FILE *fp;
	if( !(fp = safe_fopen_wrapper_follow(new_state_file.c_str(), "w")) ) {
		EXCEPT("failed to save state to %s\n",new_state_file.c_str());
	}
	else {
		ad.fPrint(fp);
		fclose( fp );
		if( rotate_file(new_state_file.c_str(),m_state_file.c_str())!=0 ) {
			EXCEPT("failed to save state to %s\n",m_state_file.c_str());
		}
	}
}
Beispiel #2
0
int
main(int argc, const char **argv)
{
	set_debug_flags(NULL, D_ALWAYS);

		// initialize to read from config file
	myDistro->Init( argc, argv );
	config();

		// Set up the dprintf stuff...
	Termlog = true;
	dprintf_config("TEST_NETWORK_ADAPTER", get_param_functions());

	const char	*tmp;
	int			 status = 0;
	Options		 opts;

	if ( CheckArgs(argc, argv, opts) ) {
		exit( 1 );
	}

	NetworkAdapterBase	*net = NULL;

	if ( opts.m_if_name ) {
		printf( "Creating network adapter object for name %s\n",
				opts.m_if_name );
		net = NetworkAdapterBase::createNetworkAdapter( opts.m_if_name );
	}
	else {
		MyString	sinful;
		sinful.formatstr( "<%s:1234>", opts.m_address );
		printf( "Creating network adapter object for %s\n", sinful.Value() );
		net = NetworkAdapterBase::createNetworkAdapter( sinful.Value() );
	}
	if ( !net ) {
		printf( "Error creating adapter\n" );
		exit(1);
	}

	// Initialize it
	if ( !net->getInitStatus() ) {
		printf( "Initialization of adaptor with address %s failed\n",
				opts.m_address );
		delete net;
		exit(1);
	}

	// And, check for it's existence
	if ( !net->exists() ) {
		printf( "Adaptor with address %s not found\n",
				opts.m_address );
		delete net;
		exit(1);
	}

	// Now, extract information from it
	tmp = net->hardwareAddress();
	if ( !tmp || !strlen(tmp) ) tmp = "<NONE>";
	printf( "hardware address: %s\n", tmp );

	tmp = net->subnetMask();
	if ( !tmp || !strlen(tmp) ) tmp = "<NONE>";
	printf( "subnet: %s\n", tmp );

	printf( "wakable: %s\n", net->isWakeable() ? "YES" : "NO" );

	MyString	tmpstr;
	net->wakeSupportedString( tmpstr );
	printf( "wake support flags: %s\n", tmpstr.Value() );

	net->wakeEnabledString( tmpstr );
	printf( "wake enable flags: %s\n", tmpstr.Value() );

	HibernatorBase	*hibernator = new RealHibernator( );
	if ( opts.m_method ) {
		printf( "Setting method to %s\n", opts.m_method );
		hibernator->setMethod( opts.m_method );
	}
	HibernationManager	hman( hibernator );
	if ( !hman.initialize( ) ) {
		fprintf( stderr, "Initialization of hibernation manager failed\n" );
		status = 1;
	}
	hman.addInterface( *net );

	ClassAd	ad;
	hman.publish( ad );
	ad.fPrint( stdout );

	const char	*method = hman.getHibernationMethod();
	printf( "Hibernation method used: %s\n", method );

	printf( "Can hibernate: %s\n", BoolString(hman.canHibernate()) );
	printf( "Can wake: %s\n", BoolString(hman.canWake()) );

	if ( hman.canHibernate() && opts.m_state != HibernatorBase::NONE ) {
		printf( "Setting state %s\n", hman.sleepStateToString(opts.m_state) );
		if ( ! hman.switchToState( opts.m_state ) ) {
			printf( "Failed to switch states\n" );
			status = 1;
		}
	}

	if ( status != 0 && opts.m_verbosity >= 1 ) {
		fprintf(stderr, "test_hibernation FAILED\n");
	}

	delete net;
	return status;
}