<commit_before>/*
 * Main routine and function for the startd.
 */

#define _STARTD_NO_DECLARE_GLOBALS 1
#include "startd.h"
static char *_FileName_ = __FILE__;

// Define global variables

// Resource manager
ResMgr*	resmgr;			// Pointer to the resource manager object

// Polling variables
int	polling_interval;	// Interval for polling when there are resources in use
int	update_interval;	// Interval to update CM

// Paths
char*	exec_path = NULL;
char*	kbd_dev = NULL;
char*	mouse_dev = NULL;

// Starter paths
char*	PrimaryStarter = NULL;
char*	AlternateStarter[MAX_STARTERS];
char*	RealStarter = NULL;

// Hosts
char*	negotiator_host = NULL;
char*	collector_host = NULL;
char*	condor_view_host = NULL;
char*	accountant_host = NULL;

// Others
int		match_timeout;			// How long you're willing to be
								// matched before claimed 
int		last_x_event = 0;		// Time of the last x event

char*	mySubSystem = "STARTD";

/*
 * Prototypes of static functions.
 */

void usage( const char *s );
int main_init( int argc, char* argv[] );
int init_params(int);
int main_config();
int main_shutdown_fast();
int main_shutdown_graceful();
void reaper_loop();
int	handle_dc_sigchld( Service*, int );
int	shutdown_sigchld( Service*, int ); 

int
main_init( int, char* [] )
{
		// Seed the random number generator for capability generation.
	set_seed( 0 );

	init_params(1);		// The 1 indicates that this is the first time

	resmgr = new ResMgr;
	resmgr->walk( config_classad );

		// Do a little sanity checking and cleanup
	check_perms();
	cleanup_execute_dir();

		// register daemoncore stuff

		// Commands
		// RegisterCommand( int cmd, char* "name_of_command",
		// 					(CommandHandler)handler_function,
		//					char* "name_of_handler_function" );

		// These commands all read the capability off the wire, find
		// the resource with that capability, and call appropriate
		// action on that resource.  Plus, all of these commands only
		// make sense when we're in the claimed state.  So, we can
		// handle them all with a common handler.
	daemonCore->Register_Command( ALIVE, "ALIVE", 
								  (CommandHandler)command_handler,
								  "command_handler" );
	daemonCore->Register_Command( RELEASE_CLAIM, "RELEASE_CLAIM", 
								  (CommandHandler)command_handler,
								  "command_handler" );
	daemonCore->Register_Command( DEACTIVATE_CLAIM,
								  "DEACTIVATE_CLAIM",  
								  (CommandHandler)command_handler,
								  "command_handler" );
	daemonCore->Register_Command( DEACTIVATE_CLAIM_FORCIBLY, 
								  "DEACTIVATE_CLAIM_FORCIBLY", 
								  (CommandHandler)command_handler,
								  "command_handler" );
	daemonCore->Register_Command( PCKPT_FRGN_JOB, "PCKPT_FRGN_JOB", 
								  (CommandHandler)command_handler,
								  "command_handler" );
	daemonCore->Register_Command( REQ_NEW_PROC, "REQ_NEW_PROC", 
								  (CommandHandler)command_handler,
								  "command_handler" );

		// These commands are special and need their own handlers
	daemonCore->Register_Command( ACTIVATE_CLAIM, "ACTIVATE_CLAIM",
								  (CommandHandler)command_activate_claim,
								  "command_activate_claim", NULL, WRITE );
	daemonCore->Register_Command( REQUEST_CLAIM, "REQUEST_CLAIM", 
								  (CommandHandler)command_request_claim,
								  "command_request_claim", NULL, WRITE );
	daemonCore->Register_Command( PCKPT_ALL_JOBS, "PCKPT_ALL_JOBS", 
								  (CommandHandler)command_pckpt_all,
								  "command_pckpt_all", NULL, WRITE );
	daemonCore->Register_Command( X_EVENT_NOTIFICATION,
								  "X_EVENT_NOTIFICATION",
								  (CommandHandler)command_x_event,
								  "command_x_event", NULL, WRITE );
	daemonCore->Register_Command( VACATE_ALL_CLAIMS,
								  "VACATE_ALL_CLAIMS",
								  (CommandHandler)command_vacate,
								  "command_vacate", NULL, WRITE);
	daemonCore->Register_Command( GIVE_STATE,
								  "GIVE_STATE",
								  (CommandHandler)command_give_state,
								  "command_give_state", NULL, READ );
	daemonCore->Register_Command( GIVE_CLASSAD,
								  "GIVE_CLASSAD",
								  (CommandHandler)command_give_classad,
								  "command_give_classad", NULL, READ );

		// This command should be registered with negotiator permission
	daemonCore->Register_Command( MATCH_INFO, "MATCH_INFO",
								  (CommandHandler)command_match_info,
								  "command_match_info", NULL, NEGOTIATOR );

		// Signals 
	daemonCore->Register_Signal( DC_SIGCHLD, "DC_SIGCHLD", 
								 (SignalHandler)handle_dc_sigchld,
								 "handle_dc_sigchld" );

		// Reapers (not yet, since we're doing it outside DC)

		// Walk through all resources and start an update timer for
		// each one.  
	resmgr->walk( Resource::start_update_timer );

		// Evaluate the state of all resources and update CM
	resmgr->walk( Resource::eval_and_update );

	return TRUE;
}


int
main_config()
{
	resmgr->walk( config_classad );
	init_params(0);
	return TRUE;
}


int
init_params( int first_time)
{
	char *tmp, buf[1024];
	int i;
	struct hostent *hp;

	if( exec_path ) {
		free( exec_path );
	}
	exec_path = param( "EXECUTE" );
	if( exec_path == NULL ) {
		EXCEPT( "No Execute file specified in config file" );
	}<commit_msg>In main_config() (when we get a SIGHUP), we now walk through our resources and eval_and_update each one in case something changed in the config file that's going to change our state, and so that the new update_interval (if it's different) gets used for polling and updating, etc.<commit_after>/*
 * Main routine and function for the startd.
 */

#define _STARTD_NO_DECLARE_GLOBALS 1
#include "startd.h"
static char *_FileName_ = __FILE__;

// Define global variables

// Resource manager
ResMgr*	resmgr;			// Pointer to the resource manager object

// Polling variables
int	polling_interval;	// Interval for polling when there are resources in use
int	update_interval;	// Interval to update CM

// Paths
char*	exec_path = NULL;
char*	kbd_dev = NULL;
char*	mouse_dev = NULL;

// Starter paths
char*	PrimaryStarter = NULL;
char*	AlternateStarter[MAX_STARTERS];
char*	RealStarter = NULL;

// Hosts
char*	negotiator_host = NULL;
char*	collector_host = NULL;
char*	condor_view_host = NULL;
char*	accountant_host = NULL;

// Others
int		match_timeout;			// How long you're willing to be
								// matched before claimed 
int		last_x_event = 0;		// Time of the last x event

char*	mySubSystem = "STARTD";

/*
 * Prototypes of static functions.
 */

void usage( const char *s );
int main_init( int argc, char* argv[] );
int init_params(int);
int main_config();
int main_shutdown_fast();
int main_shutdown_graceful();
void reaper_loop();
int	handle_dc_sigchld( Service*, int );
int	shutdown_sigchld( Service*, int ); 

int
main_init( int, char* [] )
{
		// Seed the random number generator for capability generation.
	set_seed( 0 );

	init_params(1);		// The 1 indicates that this is the first time

	resmgr = new ResMgr;
	resmgr->walk( config_classad );

		// Do a little sanity checking and cleanup
	check_perms();
	cleanup_execute_dir();

		// register daemoncore stuff

		// Commands
		// RegisterCommand( int cmd, char* "name_of_command",
		// 					(CommandHandler)handler_function,
		//					char* "name_of_handler_function" );

		// These commands all read the capability off the wire, find
		// the resource with that capability, and call appropriate
		// action on that resource.  Plus, all of these commands only
		// make sense when we're in the claimed state.  So, we can
		// handle them all with a common handler.
	daemonCore->Register_Command( ALIVE, "ALIVE", 
								  (CommandHandler)command_handler,
								  "command_handler" );
	daemonCore->Register_Command( RELEASE_CLAIM, "RELEASE_CLAIM", 
								  (CommandHandler)command_handler,
								  "command_handler" );
	daemonCore->Register_Command( DEACTIVATE_CLAIM,
								  "DEACTIVATE_CLAIM",  
								  (CommandHandler)command_handler,
								  "command_handler" );
	daemonCore->Register_Command( DEACTIVATE_CLAIM_FORCIBLY, 
								  "DEACTIVATE_CLAIM_FORCIBLY", 
								  (CommandHandler)command_handler,
								  "command_handler" );
	daemonCore->Register_Command( PCKPT_FRGN_JOB, "PCKPT_FRGN_JOB", 
								  (CommandHandler)command_handler,
								  "command_handler" );
	daemonCore->Register_Command( REQ_NEW_PROC, "REQ_NEW_PROC", 
								  (CommandHandler)command_handler,
								  "command_handler" );

		// These commands are special and need their own handlers
	daemonCore->Register_Command( ACTIVATE_CLAIM, "ACTIVATE_CLAIM",
								  (CommandHandler)command_activate_claim,
								  "command_activate_claim", NULL, WRITE );
	daemonCore->Register_Command( REQUEST_CLAIM, "REQUEST_CLAIM", 
								  (CommandHandler)command_request_claim,
								  "command_request_claim", NULL, WRITE );
	daemonCore->Register_Command( PCKPT_ALL_JOBS, "PCKPT_ALL_JOBS", 
								  (CommandHandler)command_pckpt_all,
								  "command_pckpt_all", NULL, WRITE );
	daemonCore->Register_Command( X_EVENT_NOTIFICATION,
								  "X_EVENT_NOTIFICATION",
								  (CommandHandler)command_x_event,
								  "command_x_event", NULL, WRITE );
	daemonCore->Register_Command( VACATE_ALL_CLAIMS,
								  "VACATE_ALL_CLAIMS",
								  (CommandHandler)command_vacate,
								  "command_vacate", NULL, WRITE);
	daemonCore->Register_Command( GIVE_STATE,
								  "GIVE_STATE",
								  (CommandHandler)command_give_state,
								  "command_give_state", NULL, READ );
	daemonCore->Register_Command( GIVE_CLASSAD,
								  "GIVE_CLASSAD",
								  (CommandHandler)command_give_classad,
								  "command_give_classad", NULL, READ );

		// This command should be registered with negotiator permission
	daemonCore->Register_Command( MATCH_INFO, "MATCH_INFO",
								  (CommandHandler)command_match_info,
								  "command_match_info", NULL, NEGOTIATOR );

		// Signals 
	daemonCore->Register_Signal( DC_SIGCHLD, "DC_SIGCHLD", 
								 (SignalHandler)handle_dc_sigchld,
								 "handle_dc_sigchld" );

		// Reapers (not yet, since we're doing it outside DC)

		// Walk through all resources and start an update timer for
		// each one.  
	resmgr->walk( Resource::start_update_timer );

		// Evaluate the state of all resources and update CM
	resmgr->walk( Resource::eval_and_update );

	return TRUE;
}


int
main_config()
{
		// Re-read config file for startd-wide stuff.
	init_params(0);
		// Re-read config file for each resource.
	resmgr->walk( config_classad );  
		// Re-evaluate and update the CM for each resource.
	resmgr->walk( Resource::eval_and_update );
	return TRUE;
}


int
init_params( int first_time)
{
	char *tmp, buf[1024];
	int i;
	struct hostent *hp;

	if( exec_path ) {
		free( exec_path );
	}
	exec_path = param( "EXECUTE" );
	if( exec_path == NULL ) {
		EXCEPT( "No Execute file specified in config file" );
	}
{'fraction_non_alphanumeric': 0.09856530650270169, 'fraction_numerical': 0.001863238308179616, 'mean_word_length': 3.6013716245177885, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 42, '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': '2732664', 'n_tokens_mistral': 4212, 'n_tokens_neox': 3416, 'n_words': 902}