Beispiel #1
0
Datei: ion.c Projekt: b/ION
static void	writeMemoToIonLog(char *text)
{
	static ResourceLock	logFileLock;
	static char		ionLogFileName[264] = "";
	static int		ionLogFile = -1;
	time_t			currentTime = getUTCTime();
	char			timestampBuffer[20];
	int			textLen;
	static char		msgbuf[256];

	if (text == NULL) return;

	/*	The log file is shared, so access to it must be
	 *	mutexed.						*/

	if (initResourceLock(&logFileLock) < 0)
	{
		return;
	}

	lockResource(&logFileLock);
	if (ionLogFile == -1)
	{
		if (ionLogFileName[0] == '\0')
		{
			isprintf(ionLogFileName, sizeof ionLogFileName,
					"%.255s%cion.log",
					getIonWorkingDirectory(),
					ION_PATH_DELIMITER);
		}

		ionLogFile = open(ionLogFileName, O_WRONLY | O_APPEND | O_CREAT,
				00666);
		if (ionLogFile == -1)
		{
			unlockResource(&logFileLock);
			perror("Can't redirect ION error msgs to log");
			return;
		}
	}

	writeTimestampLocal(currentTime, timestampBuffer);
	isprintf(msgbuf, sizeof msgbuf, "[%s] %s\n", timestampBuffer, text);
	textLen = strlen(msgbuf);
	if (write(ionLogFile, msgbuf, textLen) < 0)
	{
		perror("Can't write ION error message to log file");
	}
#ifdef TargetFFS
	close(ionLogFile);
	ionLogFile = -1;
#endif
	unlockResource(&logFileLock);
}
Beispiel #2
0
/******************************************************************************
 *
 * \par Function Name: mgr_init
 *
 * \par Initialize the manager...
 *
 * \par Notes:
 *
 * Modification History:
 *  MM/DD/YY  AUTHOR         DESCRIPTION
 *  --------  ------------   ---------------------------------------------
 **  09/01/11  V. Ramachandran Initial Implementation
 **  08/20/13  E. Birrane      Code Review Updates
 *****************************************************************************/
int mgr_init(char *argv[])
{

	DTNMP_DEBUG_ENTRY("mgr_init","(0x%x)",(unsigned long) argv);

    strcpy((char *) manager_eid.name, argv[1]);

    if(iif_register_node(&ion_ptr, manager_eid) == 0)
    {
        DTNMP_DEBUG_ERR("mgr_init","Unable to register BP Node. Exiting.", NULL);
        DTNMP_DEBUG_EXIT("mgr_init","->-1.",NULL);
        return -1;
    }

    if (iif_is_registered(&ion_ptr))
    {
        DTNMP_DEBUG_INFO("mgr_init", "Mgr registered with ION, EID: %s",
        		         iif_get_local_eid(&ion_ptr).name);
    }
    else
    {
        DTNMP_DEBUG_ERR("mgr_init","Failed to register mgr with ION, EID %s",
        				 iif_get_local_eid(&ion_ptr).name);
        DTNMP_DEBUG_EXIT("mgr_init","->-1.",NULL);
        return -1;
    }

    g_sdr = getIonsdr();

    if((known_agents = lyst_create()) == NULL)
        {
            DTNMP_DEBUG_ERR("mgr_init","Failed to create known agents list.",NULL);
            //MRELEASE(ion_ptr);
            DTNMP_DEBUG_EXIT("mgr_init","->-1.",NULL);
            return -1;
        }

    if (initResourceLock(&agents_mutex))
    {
    	DTNMP_DEBUG_ERR("mgr_init","Can't initialize rcv rpt list. . errno = %s",
    			        strerror(errno));
        //MRELEASE(ion_ptr);
        DTNMP_DEBUG_EXIT("mgr_init","->-1.",NULL);
    	return -1;
    }

    if((macro_defs = lyst_create()) == NULL)
    {
        DTNMP_DEBUG_ERR("mgr_init","Failed to create macro def list.%s",NULL);
        //MRELEASE(ion_ptr);
        DTNMP_DEBUG_EXIT("mgr_init","->-1.",NULL);
        return -1;
    }

    if (initResourceLock(&macro_defs_mutex))
    {
    	DTNMP_DEBUG_ERR("mgr_init","Cant init macro def list mutex. errno = %s",
    			        strerror(errno));
        //MRELEASE(ion_ptr);
        DTNMP_DEBUG_EXIT("mgr_init","->-1.",NULL);
    	return -1;
    }


	adm_init();

#ifdef HAVE_MYSQL
	db_mgt_init("localhost", "root", "NetworkManagement", "dtnmp", 1);
#endif

	DTNMP_DEBUG_EXIT("mgr_init","->0.",NULL);
    return 0;
}
Beispiel #3
0
agent_t* mgr_agent_create(eid_t *in_eid)
{
	Object  *entry = NULL;
	agent_t *agent	= NULL;

	DTNMP_DEBUG_ENTRY("mgr_agent_create", "(%s)", in_eid->name);

	/* Step 0: Sanity Check. */
	if(in_eid == NULL)
	{
		DTNMP_DEBUG_ENTRY("mgr_agent_create", "(NULL)", NULL);
		DTNMP_DEBUG_EXIT("mgr_agent_create", "->NULL", NULL);
		return NULL;
	}

	/* Step 1:  Allocate space for the new agent. */
	if((agent = (agent_t*)MTAKE(sizeof(agent_t))) == NULL)
	{
		DTNMP_DEBUG_ERR("mgr_agent_create",
				        "Unable to allocate %d bytes for new agent %s",
				        sizeof(agent_t), in_eid->name);
		DTNMP_DEBUG_EXIT("mgr_agent_create", "->NULL", NULL);
		return NULL;
	}

	/* Step 2: Copy over the name. */
	strncpy(agent->agent_eid.name, in_eid->name, MAX_EID_LEN);

	/* Step 3: Create associated lists. */
	if((agent->custom_defs = lyst_create()) == NULL)
	{
		DTNMP_DEBUG_ERR("mgr_agent_create","Unable to create custom definition lyst for agent %s",
				in_eid->name);
		MRELEASE(agent);

		DTNMP_DEBUG_EXIT("mgr_agent_create","->NULL", NULL);
		return NULL;
	}

	if((agent->reports = lyst_create()) == NULL)
	{
		DTNMP_DEBUG_ERR("mgr_agent_create","Unable to create report lyst for agent %s",
				in_eid->name);
		lyst_destroy(agent->custom_defs);
		MRELEASE(agent);

		DTNMP_DEBUG_EXIT("mgr_agent_create","->NULL", NULL);
		return NULL;
	}

	if(lyst_insert(known_agents, agent) == NULL)
	{
		DTNMP_DEBUG_ERR("mgr_agent_create","Unable to insert agent %s into known agents lyst",
				in_eid->name);
		lyst_destroy(agent->custom_defs);
		lyst_destroy(agent->reports);
		MRELEASE(agent);

		DTNMP_DEBUG_EXIT("mgr_agent_create","->NULL", NULL);
		return NULL;
	}

	initResourceLock(&(agent->mutex));

	DTNMP_DEBUG_EXIT("mgr_agent_create", "->New Agent %s", agent->agent_eid.name);
	return agent;
}