示例#1
0
void monitor_agents()
{
    char **cr_agents;
    char **av_agents;

    av_agents = get_agents(GA_ACTIVE);


    /* No agent saved */
    if(!mond.agents)
    {
        mond.agents = av_agents;
        return;
    }

    /* Checking if any of the previous available agents
     * are disconnected.
     */
    cr_agents = mond.agents;
    while(*cr_agents)
    {
        int available = 0;
        char **tmp_av;
        
        tmp_av = av_agents;
        while(tmp_av && *tmp_av)
        {
            if(strcmp(*cr_agents, *tmp_av) == 0)
            {
                available = 1;
                break;
            }
            tmp_av++;
        }

        /* Agent disconnected */
        if(available == 0)
        {
            char str[OS_SIZE_1024 +1];
            
            /* Sending disconnected message */
            snprintf(str, OS_SIZE_1024 -1, OS_AG_DISCON, *cr_agents);
            if(SendMSG(mond.a_queue, str, ARGV0,
                        LOCALFILE_MQ) < 0)
            {
                merror(QUEUE_SEND, ARGV0);
            }
        }
        
        cr_agents++;
    }


    /* Removing old agent list and adding currently one */
    free_agents(mond.agents);
    mond.agents = av_agents;
    return;
}
示例#2
0
int main(int argc, char* argv[]) {
    char *mapPath, *agentPath; //The location of the files
    int rows, cols, maxSteps; //Dimensions of the map and the max steps
    char** map; //Character map
    //Check the command line args
    if (argc != 4) {
        handler_exit(1);
    }

    mapPath = argv[1];
    agentPath = argv[3];

    long tempL;
    char** tempP = NULL;
    tempL = strtol(argv[2], tempP, 10);
        
    if (tempL < 1 || tempL > INT_MAX) {
        handler_exit(2);
    }
    
    //Set variables needed later in the program - max steps, map and agents
    maxSteps = (int)tempL;
    map = open_map_file(mapPath, &rows, &cols);
    get_num_agents(agentPath);
    agents = (AgentData *)malloc(sizeof(AgentData)*numAgents);
    get_agents(agentPath, rows, cols);

    //Set up signal handling
    signal(SIGINT, sig_handler);
    signal(SIGCHLD, sig_handler);

    //Start agents
    start_agents(rows, cols, map);

    //Start the game
    for (int i = 0; i < maxSteps; i++) {
        //Let each agent take turns, process their move and print the map
        for(int j = 0; j < numAgents; j++) {
            agent_move(j);
            check_move(map, j, rows, cols);
            print_map(map, rows, cols);
        }
    }
    //No agent succeeded with given steps
    handler_exit(10);
}
示例#3
0
/** main **/
int main(int argc, char **argv)
{
    char *dir = DEFAULTDIR;
    char *group = GROUPGLOBAL;
    char *user = USER;

    char *msg;
    char **agent_list;
    int gid;
    int uid;
    int flag = 0;


    /* Setting the name */
    OS_SetName(ARGV0);


    /* user arguments */
    if(argc < 2)
    {
        helpmsg();
    }

    /* Getting the group name */
    gid = Privsep_GetGroup(group);
    uid = Privsep_GetUser(user);
    if(gid < 0)
    {
	    ErrorExit(USER_ERROR, ARGV0, user, group);
    }


    /* Setting the group */
    if(Privsep_SetGroup(gid) < 0)
    {
	    ErrorExit(SETGID_ERROR,ARGV0, group);
    }


    /* Chrooting to the default directory */
    if(Privsep_Chroot(dir) < 0)
    {
        ErrorExit(CHROOT_ERROR, ARGV0, dir);
    }


    /* Inside chroot now */
    nowChroot();


    /* Setting the user */
    if(Privsep_SetUser(uid) < 0)
    {
        ErrorExit(SETUID_ERROR, ARGV0, user);
    }

    /* User options */
    if(strcmp(argv[1], "-h") == 0)
    {
        helpmsg();
    }
    else if(strcmp(argv[1], "-a") == 0)
    {
        flag = GA_ALL;
        msg = "is available.";
    }
    else if(strcmp(argv[1], "-c") == 0)
    {
        flag = GA_ACTIVE;
        msg = "is active.";
    }
    else if(strcmp(argv[1], "-n") == 0)
    {
        flag = GA_NOTACTIVE;
        msg = "is not active.";
    }
    else
    {
        printf("\n** Invalid option '%s'.\n", argv[1]);
        helpmsg();
    }


    agent_list = get_agents(flag);
    if(agent_list)
    {
        char **agent_list_pt = agent_list;

        while(*agent_list)
        {
            printf("%s %s\n", *agent_list, msg);
            agent_list++;
        }

        free_agents(agent_list_pt);
    }
    else
    {
        printf("** No agent available.\n");
    }
    return(0);
}