コード例 #1
0
ファイル: agent.c プロジェクト: CoryXie/opensolaris
/* destroy hanging agent when no outstanding session which
   relates to the agent */
void destroy_hanging_agent()
{
	Agent *ap;
	int rslt ; 

	for (ap = first_agent; ap ; ap = ap->next_agent) {

		if (ap->numOfFailRequest <= 5)
			continue ; 

		/* Even if the subagent isn't responding, we need to let the
		** sessions timeout and rip-down thru the normal mechanism.
		*/
		if (!no_outstanding_session_for_the_agent (ap))
			continue ; 

		/* subagent is quiesced and not talking -- check proces */
		if ( ap->agentProcessID != 0 && kill (ap->agentProcessID, 0) < 0) { 
			error ("Subagent died: %s PID=%d -- deleted from the agent table",
				ap->name, ap->agentProcessID ) ;	
			agent_destroy (ap) ; 
			return ; 		/* only kill one at a time */
		}

		/* subagent appears to be alive but hung and not responding */

		if (MaxFails <= 0 || ap->numOfFailRequest < MaxFails)
			continue ; 

		/* If the subagent receives a request with a bad community string
		// it is obliged to discard the string and _not_ respond.  This
		// doesn't jive with our stateful relay model.  We timeout and
		// can't distinguish a hung agent from an agent that is dropping
		// packets because of the "bad" community strings.  Thus, before
		// putting the ax to an agent we see if it's still alive.
		// 
		// The ssa_subagent_is_alive() routine "pings" the subagent with
		// a valid but innocuous request packet.  Unfortunately the dummy
		// we build has the community string set to "public".  If the subagent
		// doesn't accept "public" requests it will ignore our ping attempt.
		//
		// Sunil indicated that snmpdx would pre-validate incoming community
		// strings and only pass requests that would be accepted by the subagent.
		// This doesn't appear to work as advertised.
	 	*/

		if (ssa_subagent_is_alive (ap)) {
			error ("Agent %s appeared dead but responded to ping", ap->name) ; 
			ap->numOfFailRequest = 0 ; 
			continue ; 
		}

		error ("Agent not responding: %s -- deleted from the agent table", ap->name ) ; 
		agent_destroy(ap);
		return;
	}
}
コード例 #2
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//agenttype_mixer_create
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int agenttype_mixer_create_xp (agent * a, char * parameterstring)
{
	bool errorflag = false; //If there's an error

	//Check for error conditions
	if (strlen(parameterstring) >= 30) return false;
	//Break up the parts
	int tokensfound = BBTokenize(parameterstring, mixer_tokenptrs, 4, NULL);
	//Three tokens exactly required
	if (tokensfound != 3) return 1;

	long values[3];
	//Make sure they are all valid integers
	for (int i = 0; i < 3; i++)
		if (!config_set_long(mixer_tokenptrs[i], &values[i]))
			return 1;

	AgentType_Mixer_XP * details = new AgentType_Mixer_XP(values);
	if (details->Init())
	{
		//Set the window property
		SetProp(details->m_hwnd_reciever, "mixagtptr", a);
		a->agentdetails = static_cast<void *>(details);
	}
	else
	{
		details->Destroy();
		delete details;
		a->agentdetails = NULL;

		agent_destroy(&a);
		return 1;   
	}
	return 0;
}
コード例 #3
0
ファイル: ocr.c プロジェクト: testfarm/testfarm
static void ocr_terminate(ocr_t *ocr)
{
  if ( ocr->agent != NULL ) {
    agent_destroy(ocr->agent);
    ocr->agent = NULL;
  }
}
コード例 #4
0
ファイル: nom_server.c プロジェクト: AlexGiovanentti/zguide
static void
server_agent (void *args, zctx_t *ctx, void *pipe)
{
    agent_t *self = agent_new (ctx, pipe);
    zmq_pollitem_t items [] = {
        { self->pipe, 0, ZMQ_POLLIN, 0 },
        { self->router, 0, ZMQ_POLLIN, 0 }
    };
    while (!self->stopped) {
        //  Calculate tickless timer, up to 1 hour
        uint64_t tickless = zclock_time () + 1000 * 3600;
        zhash_foreach (self->clients, client_tickless, &tickless);

        //  Poll until at most next timer event
        int rc = zmq_poll (items, 2,
            (tickless - zclock_time ()) * ZMQ_POLL_MSEC);
        if (rc == -1)
            break;              //  Context has been shut down

        //  Process incoming message from either socket
        if (items [0].revents & ZMQ_POLLIN)
            agent_control_message (self);

        if (items [1].revents & ZMQ_POLLIN)
            agent_client_message (self);

        //  Send heartbeats to idle clients as needed
        zhash_foreach (self->clients, client_ping, self->router);
    }
    agent_destroy (&self);
}
コード例 #5
0
ファイル: flcliapi.c プロジェクト: tzuryby/zguide
static void *
flcliapi_task (void *context) 
{
    agent_t *self = agent_new (context, "inproc://flcliapi");
    zmq_pollitem_t items [] = { 
        { self->control, 0, ZMQ_POLLIN, 0 },
        { self->router, 0, ZMQ_POLLIN, 0 } 
    };

    while (!s_interrupted) {
        //  Calculate tickless timer, up to 1 hour
        uint64_t tickless = s_clock () + 1000 * 3600;
        if (self->request
        &&  tickless > self->expires)
            tickless = self->expires;
        zhash_apply (self->servers, server_tickless, &tickless);

        int rc = zmq_poll (items, 2, (tickless - s_clock ()) * 1000);
        if (rc == -1 && errno == ETERM)
            break;              //  Context has been shut down

        if (items [0].revents & ZMQ_POLLIN)
            agent_control_message (self);

        if (items [1].revents & ZMQ_POLLIN)
            agent_router_message (self);

        //  If we're processing a request, dispatch to next server
        if (self->request) {
            if (s_clock () >= self->expires) {
                //  Request expired, kill it
                zmsg_t *reply = zmsg_new ("FAILED");
                zmsg_send (&reply, self->control);
                zmsg_destroy (&self->request);
            }
            else {
                //  Find server to talk to, remove any expired ones
                while (zlist_size (self->actives)) {
                    server_t *server = (server_t *) zlist_first (self->actives);
                    if (s_clock () >= server->expires) {
                        zlist_pop (self->actives);
                        server->alive = 0;
                    }
                    else {
                        zmsg_t *request = zmsg_dup (self->request);
                        zmsg_push (request, server->endpoint);
                        zmsg_send (&request, self->router);
                        break;
                    }
                }
            }
        }
        //  Disconnect and delete any expired servers
        //  Send heartbeats to idle servers if needed
        zhash_apply (self->servers, server_ping, self->router);
    }
    agent_destroy (&self);
    return NULL;
}
コード例 #6
0
ファイル: agent.c プロジェクト: qstesiro/Larva
JNIEXPORT
void JNICALL Agent_OnUnload(JavaVM *vm) {
	printf("OnUnload\n");
	if (NULL != agent) {
		network_manager_stop(agent->network);
		agent_destroy(agent); agent = NULL;
	}	
}
コード例 #7
0
ファイル: agent.c プロジェクト: Mcjesus15/Zio_Other
static void agent_exited(DBusConnection *conn, void *user_data)
{
	struct agent *agent = user_data;

	debug("Agent exited without calling Unregister");

	agent_destroy(agent, TRUE);
}
コード例 #8
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//agenttype_switchedstate_destroy
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int agenttype_switchedstate_destroy(agent *a)
{
	if (a->agentdetails)
	{		
		agenttype_switchedstate_details *details = (agenttype_switchedstate_details *) a->agentdetails;

		//Destroy all child agents
		for (int  i = 0; i < 3; i++) agent_destroy(&details->agents[i]);

		delete details;
		a->agentdetails = NULL;
	}

	//No errors
	return 0;
}
コード例 #9
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//controltype_button_destroy
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int controltype_button_destroy(control *c)
{
	//Get the details
	controltype_button_details *details = (controltype_button_details *) c->controldetails;
	
	//Delete the agents
	for (int i = 0; i < CONTROLTYPE_BUTTON_AGENTCOUNT; i++)
		agent_destroy(&details->agents[i]);

	//Destroy the window
	window_destroy(&c->windowptr);

	//Delete the details
	delete (controltype_button_details *) c->controldetails;

	return 0;
}
コード例 #10
0
ファイル: zre_node.c プロジェクト: Aluminus/zyre
static void
zre_node_agent (void *args, zctx_t *ctx, void *pipe)
{
    //  Create agent instance to pass around
    agent_t *self = agent_new (ctx, pipe);
    if (!self)                  //  Interrupted
        return;
    
    //  Send first beacon immediately
    uint64_t ping_at = zclock_time ();
    zmq_pollitem_t pollitems [] = {
        { self->pipe,                           0, ZMQ_POLLIN, 0 },
        { self->inbox,                          0, ZMQ_POLLIN, 0 },
        { 0,           zre_udp_handle (self->udp), ZMQ_POLLIN, 0 },
        { fmq_client_handle (self->fmq_client), 0, ZMQ_POLLIN, 0 }
    };
    while (!zctx_interrupted) {
        long timeout = (long) (ping_at - zclock_time ());
        assert (timeout <= PING_INTERVAL);
        if (timeout < 0)
            timeout = 0;
        if (zmq_poll (pollitems, 4, timeout * ZMQ_POLL_MSEC) == -1)
            break;              //  Interrupted

        if (pollitems [0].revents & ZMQ_POLLIN)
            agent_recv_from_api (self);
        
        if (pollitems [1].revents & ZMQ_POLLIN)
            agent_recv_from_peer (self);

        if (pollitems [2].revents & ZMQ_POLLIN)
            agent_recv_udp_beacon (self);

        if (pollitems [3].revents & ZMQ_POLLIN)
            agent_recv_fmq_event (self);

        if (zclock_time () >= ping_at) {
            agent_beacon_send (self);
            ping_at = zclock_time () + PING_INTERVAL;
            //  Ping all peers and reap any expired ones
            zhash_foreach (self->peers, agent_ping_peer, self);
        }

    }
    agent_destroy (&self);
}
コード例 #11
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//agenttype_compoundtext_destroy
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int agenttype_compoundtext_destroy(agent *a)
{
	if (a->agentdetails)
	{
		agenttype_compoundtext_details *details = (agenttype_compoundtext_details *) a->agentdetails;

		//Delete all subagents
		for (int i = 0; i < AGENTTYPE_COMPOUNDTEXT_MAXAGENTS; i++) agent_destroy(&details->agents[i]);

		//Delete the text
		free_string(&details->text);

		//Delete the details
		delete details;    
		a->agentdetails = NULL;
	}

	//No errors
	return 0;
}
コード例 #12
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//controltype_label_destroy
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int controltype_label_destroy(control *c)
{
	int i;

	//Get the details
	controltype_label_details *details = (controltype_label_details *) c->controldetails;

	//Delete the agents
	for (i = 0; i < CONTROLTYPE_LABEL_AGENT_COUNT; i++)
		agent_destroy(&details->agents[i]);

	unloadPlugin(&details->module_info, NULL);

	//Destroy the window
	window_destroy(&c->windowptr);

	//Delete the details
	delete (controltype_label_details *) c->controldetails;

	return 0;
}
コード例 #13
0
ファイル: agent.c プロジェクト: qstesiro/Larva
struct agent* agent_create(JavaVM* vm) {
	if (NULL != vm) {
		struct agent* agent = (struct agent*)malloc(sizeof(struct agent));
		if (NULL != agent) {		
			memset(agent, 0, sizeof(struct agent));
			agent->vm = vm;
			if (JNI_OK == (*agent->vm)->GetEnv(agent->vm, (void**)&agent->jvmti, JVMTI_VERSION_1_2)) {
				agent->network = network_manager_create(agent);
				agent->command = command_manager_create(agent);
				agent->event = event_manager_create(agent);
				if (NULL != agent->network &&
					NULL != agent->command &&
					NULL != agent->event) {
					return agent;					
				}
			}
		}
		if (NULL != agent) {
			agent_destroy(agent); agent = NULL;
		}		
	}
	return NULL;
}
コード例 #14
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//agenttype_graph_destroy
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int agenttype_graph_destroy(agent *a)
{
	//Delete the details if possible
	if (a->agentdetails)
	{
		agenttype_graph_details *details =(agenttype_graph_details *) a->agentdetails;

		//Delete all subagents
		for (int i = 0; i < AGENTTYPE_GRAPH_AGENTCOUNT; i++) agent_destroy(&details->agents[i]);

		//Remove from tracking list
		if (details->internal_identifier != NULL)
		{
			list_remove(agenttype_graph_agents, details->internal_identifier);
			free_string(&details->internal_identifier);
		}

		delete details;
		a->agentdetails = NULL;
	}

	//No errors
	return 0;
}
コード例 #15
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//agenttype_mixer_create
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int agenttype_mixer_create(agent *a, char *parameterstring)
{
	//If there's an error
	bool errorflag = false;;

	//Check for error conditions
	if (strlen(parameterstring) >= 30) return false;

	//Break up the parts
	int tokensfound = BBTokenize(parameterstring, mixer_tokenptrs, 4, NULL);

	//Three tokens exactly required
	if (tokensfound != 3) return 1;

	long values[3];
	//Make sure they are all valid integers
	for (int i = 0; i < 3; i++)
	{
		if (!config_set_long(mixer_tokenptrs[i], &values[i])) return 1;
	}

	//Create the details
	agenttype_mixer_details *details = new agenttype_mixer_details;
	a->agentdetails = (void *) details;

	//Copy the values
	details->device = values[0];
	details->line = values[1];
	details->control = values[2];

	//Create the reciever window class if neccessary
	//No errors
	mixer_controlcount++;
	if (mixer_controlcount > 0 && !mixer_recieverregistered)
	{
		if (!window_helper_register(mixer_recieverclass, &agenttype_mixer_recieverevent)) mixer_recieverregistered = true;
		else errorflag = true;
	}

	//Create the reciever window
	details->hwnd_reciever = NULL;
	if (!errorflag)
	{
		details->hwnd_reciever = window_helper_create(mixer_recieverclass);
		if (!details->hwnd_reciever) errorflag = true;
	}

	if (!errorflag)
	{
		//Initialize the mixer values
		if (MMSYSERR_NOERROR != mixerOpen(&details->mixer_handle, details->device, (DWORD_PTR) details->hwnd_reciever, 0, CALLBACK_WINDOW)) errorflag = true;
	}

	if (!errorflag)
	{
		//Set the control properties
		details->mixer_controldetails.cbStruct = sizeof(MIXERCONTROLDETAILS);
		details->mixer_controldetails.dwControlID = details->control;
		details->mixer_controldetails.cChannels = 1;
		details->mixer_controldetails.cMultipleItems = 0;
		details->mixer_controldetails.cbDetails = sizeof(MIXERCONTROLDETAILS_UNSIGNED);

		//Set the window property
		SetProp(details->hwnd_reciever, "mixagtptr", a);
	}

	if (errorflag)
	{
		if (details->hwnd_reciever)
			window_helper_destroy(details->hwnd_reciever);

		delete details;
		a->agentdetails = NULL;

		agent_destroy(&a);
		return 1;
	}

	return 0;
}