Пример #1
0
static int wait_to_complete_snapshot_item(GHashTable *pid_table, GPtrArray *target_array, complete_snapshot_item_mapping_function complete_snapshot_item_mapping)
{
    int wstatus;
    pid_t pid = wait(&wstatus);
    
    if(pid == -1)
        return FALSE;
    else
    {
        Target *target;
        ProcReact_Status status;
        
        /* Find the corresponding snapshot mapping and remove it from the pids table */
        SnapshotMapping *mapping = g_hash_table_lookup(pid_table, &pid);
        g_hash_table_remove(pid_table, &pid);
        
        /* Mark mapping as transferred to prevent it from snapshotting again */
        mapping->transferred = TRUE;
        
        /* Signal the target to make the CPU core available again */
        target = find_target(target_array, mapping->target);
        signal_available_target_core(target);
        
        /* Return the status */
        int result = procreact_retrieve_boolean(pid, wstatus, &status);
        complete_snapshot_item_mapping(mapping, status, result);
        return(status == PROCREACT_STATUS_OK && result);
    }
}
Пример #2
0
static int clear_nacks(ptl_process_t target_id)
{
    struct rptl_target *target;
    struct rptl_op *op;
    int ret = PTL_OK;
    MPIDI_STATE_DECL(MPID_STATE_CLEAR_NACKS);

    MPIDI_FUNC_ENTER(MPID_STATE_CLEAR_NACKS);

    ret = find_target(target_id, &target);
    RPTLU_ERR_POP(ret, "error finding target\n");

    for (op = target->data_op_list; op; op = op->next) {
        if ((op->op_type == RPTL_OP_PUT && IDS_ARE_EQUAL(op->u.put.target_id, target_id)) ||
            (op->op_type == RPTL_OP_GET && IDS_ARE_EQUAL(op->u.get.target_id, target_id))) {
            if (op->state == RPTL_OP_STATE_NACKED)
                op->state = RPTL_OP_STATE_QUEUED;
        }
    }
    target->state = RPTL_TARGET_STATE_ACTIVE;

    ret = poke_progress();
    RPTLU_ERR_POP(ret, "error in poke_progress\n");

  fn_exit:
    MPIDI_FUNC_EXIT(MPID_STATE_CLEAR_NACKS);
    return ret;

  fn_fail:
    goto fn_exit;
}
Пример #3
0
const bfd_target *
bfd_find_target (const char *target_name, bfd *abfd)
{
    const char *targname;
    const bfd_target *target;

    if (target_name != NULL)
        targname = target_name;
    else
        targname = getenv ("GNUTARGET");

    /* This is safe; the vector cannot be null.  */
    if (targname == NULL || strcmp (targname, "default") == 0)
    {
        abfd->target_defaulted = TRUE;
        if (bfd_default_vector[0] != NULL)
            abfd->xvec = bfd_default_vector[0];
        else
            abfd->xvec = bfd_target_vector[0];
        return abfd->xvec;
    }

    abfd->target_defaulted = FALSE;

    target = find_target (targname);
    if (target == NULL)
        return NULL;

    abfd->xvec = target;
    return target;
}
Пример #4
0
void AGENT::update_fight(GROUP* target_group)
{
	// get target
	AGENT * t = find_target(target_group); //group->is_single_unit() ? find_target(target_group) : find_target_random(target_group);
	if (!t) return; // didn't find one

	// fight
	move_mult(collision ? 3.0 : 1.0);
	set_dest(t->get_x(), t->get_y());
	if (dist_dest() > (t->getRadius() + getRadius()) * 2) { // move to target
		fight_timer--;
		if (!collision) move((int)get_dest_x(), (int)get_dest_y(), true); // move
		else collision_avoid(); // collision avoid
		state = AGENT::READY_FIGHT;
		setAnimation(is_stuckcounter() ? ANIMATION_DATA::STAND : ANIMATION_DATA::MOVE, true);
	} else { // at target
		move_stop();
		state = AGENT::FIGHTING;
		if (is_near_dest_angle(45)) { // deal damage
			set_dest(x, y);
			t->hurt_by(unitData->damage, this);
			setAnimation(ANIMATION_DATA::ATTACK, true);
		} else { // face target
			fight_timer--;
			rotate_towards((int)get_angle_dest());
			if (!is_near_dest_angle(90)) setAnimation(ANIMATION_DATA::STAND, true);
		}
	}

	// single units sync group position with their own
	if (group->is_single_unit()) group->sync_to(this);

	// update gemeric stuff
	update();
}
// parse the response to reading the other device's Basic Attributes
int basic_parse( zcl_command_t *zcl)
{
	uint8_t			response = ZCL_STATUS_SUCCESS;
	int				i;

/*
	find the device in our target_t list
	use a list of offsets into target_t, along with attr ID, type and length limits
	copy the attribute values from the response, ignore non-SUCCESS status

*/
	i = find_target( &zcl->envelope->ieee_address);
	if (i >= 0)
	{
		if (target_list[i].basic.app_ver > 0)
		{
			//puts( "ignoring duplicate basic response");
		}
		else
		{
			memset( &basic_value, 0, sizeof basic_value);

			response = zcl_process_read_attr_response( zcl, &basic_attr.app_ver);

			target_list[i].basic = basic_value;
			print_target( i);
		}
	}

	return zcl_default_response( zcl, response);
}
Пример #6
0
	void	as_environment::set_variable (
	    const tu_string &varname,
	    const as_value &val,
	    const array<with_stack_entry>& with_stack )
	// Given a path to variable, set its value.
	{
		IF_VERBOSE_ACTION ( log_msg ( "-------------- %s = %s\n", varname.c_str(), val.to_string() ) ); //xxxxxxxxxx
		// Path lookup rigamarole.
		character	*target = get_target();
		tu_string	path;
		tu_string	var;

		if ( parse_path ( varname, &path, &var ) )
		{
			target = cast_to<character> ( find_target ( path.c_str() ) );

			if ( target )
			{
				target->set_member ( var, val );
			}
		}

		else
		{
			set_variable_raw ( varname, val, with_stack );
		}
	}
Пример #7
0
static int lock(const GPtrArray *distribution_array, const GPtrArray *target_array, gchar *profile)
{
    unsigned int i;
    GPtrArray *try_array = g_ptr_array_new();
    GPtrArray *lock_array = g_ptr_array_new();
    int exit_status = 0;
    int status;
    
    /* For each machine acquire a lock */
    for(i = 0; i < distribution_array->len; i++)
    {
        DistributionItem *item = g_ptr_array_index(distribution_array, i);
        Target *target = find_target(target_array, item->target);
        gchar *interface = find_target_client_interface(target);
        
        g_print("[target: %s]: Acquiring a lock\n", item->target);
        status = exec_lock(interface, item->target, profile);
        
        /* If a process fails, change the exit status */
        if(status == -1)
        {
            g_printerr("[target: %s]: Error with forking lock process!\n", item->target);
            exit_status = -1;
        }
        else
            g_ptr_array_add(try_array, item);
    }
    
    /* Wait until every lock is acquired */
    for(i = 0; i < try_array->len; i++)
    {
        status = wait_to_finish(0);
        
        /* If a process fails, change the exit status */
        if(status != 0)
        {
            g_printerr("Failed to acquire a lock!\n");
            exit_status = status;
        }
        else if(interrupted)
        {
            g_printerr("[coordinator]: The lock phase has been interrupted!\n");
            exit_status = 1;
        }
    }
    
    /* If a lock fails then unlock every machine that is locked */
    if(!exit_status)
        unlock(lock_array, target_array, profile);
    
    /* Cleanup */
    g_ptr_array_free(try_array, TRUE);
    g_ptr_array_free(lock_array, TRUE);
    
    /* Return exit status, which is 0 if everything succeeds */
    return exit_status;
}
Пример #8
0
static int rptl_put(ptl_handle_md_t md_handle, ptl_size_t local_offset, ptl_size_t length,
                    ptl_ack_req_t ack_req, ptl_process_t target_id, ptl_pt_index_t pt_index,
                    ptl_match_bits_t match_bits, ptl_size_t remote_offset, void *user_ptr,
                    ptl_hdr_data_t hdr_data, enum rptl_pt_type pt_type)
{
    struct rptl_op *op;
    int ret = PTL_OK;
    struct rptl_target *target;
    MPIDI_STATE_DECL(MPID_STATE_RPTL_PUT);

    MPIDI_FUNC_ENTER(MPID_STATE_RPTL_PUT);

    ret = find_target(target_id, &target);
    RPTLU_ERR_POP(ret, "error finding target structure\n");

    ret = rptli_op_alloc(&op, target);
    RPTLU_ERR_POP(ret, "error allocating op\n");

    op->op_type = RPTL_OP_PUT;
    op->state = RPTL_OP_STATE_QUEUED;

    /* store the user parameters */
    op->u.put.md_handle = md_handle;
    op->u.put.local_offset = local_offset;
    op->u.put.length = length;
    op->u.put.ack_req = ack_req;
    op->u.put.target_id = target_id;
    op->u.put.pt_index = pt_index;
    op->u.put.match_bits = match_bits;
    op->u.put.remote_offset = remote_offset;
    op->u.put.user_ptr = user_ptr;
    op->u.put.hdr_data = hdr_data;

    /* place to store the send and ack events */
    op->u.put.send = NULL;
    op->u.put.ack = NULL;
    op->u.put.pt_type = pt_type;
    op->events_ready = 0;
    op->target = target;

    if (op->u.put.pt_type == RPTL_PT_DATA)
        MPL_DL_APPEND(target->data_op_list, op);
    else
        MPL_DL_APPEND(target->control_op_list, op);

    ret = poke_progress();
    RPTLU_ERR_POP(ret, "Error from poke_progress\n");

  fn_exit:
    MPIDI_FUNC_EXIT(MPID_STATE_RPTL_PUT);
    return ret;

  fn_fail:
    goto fn_exit;
}
Пример #9
0
Файл: project.C Проект: gnb/cant
gboolean
project_t::execute_target_by_name(const char *name)
{
    target_t *targ;
    
    if ((targ = find_target(name)) == 0)
    {
    	log::errorf("no such target \"%s\"\n", name);
    	return FALSE;
    }
    return targ->execute();
}
Пример #10
0
Файл: pr8.c Проект: njb5174/Hake
void pr8_work(char *goal)
{
  if (goal == NULL) return;

  printf("goal: %s\n", goal);
  
  struct target *target_goal = find_target(goal);
  
  if(target_goal == NULL)
  {
  	
  }
  
  else
  {
  	struct timespec t1 = mtime(target_goal->target_name);
  	
  	struct source *temp = target_goal->target_sources;
  	
  	bool recipe_flag = false;
  	  	
  	while(temp->next != NULL)
  	{
		struct timespec t2 = mtime(temp->source_name);  // source
		
		if (t1.tv_sec == 0  || t1.tv_sec < t2.tv_sec || ((t1.tv_sec == t2.tv_sec) && (t1.tv_nsec < t2.tv_nsec)))
		  { 
		  	recipe_flag = true;
		  
		   }
  		temp = temp->next;
  	}
  	
  	if(recipe_flag)
  	{
  		printf("%s is outdated or nonexistant, execute recipes\n", temp->source_name);
		  	recipe_list_print(target_goal->target_recipes);
		}
  }

  // if goal is a known target,
  //   iterate through goal's list of sources,
  //     call pr8_work() on each source
  //   iterate through goal's list of sources,
  //     compare times of goal and its sources
  //   if necessary, iterate through goal's list of recipes,
  //     print the recipe

  // ... more later

  return;
}
Пример #11
0
	void as_environment::set_target ( as_value &target, character *original_target )
	{
		if ( target.is_string() )
		{
			tu_string path = target.to_tu_string();
			IF_VERBOSE_ACTION ( log_msg ( "-------------- ActionSetTarget2: %s", path.c_str() ) );

			if ( path.size() > 0 )
			{
				character *tar = cast_to<character> ( find_target ( path.c_str() ) );

				if ( tar )
				{
					set_target ( tar );
					return;
				}
			}

			else
			{
				set_target ( original_target );
				return;
			}
		}

		else if ( target.is_object() )
		{
			IF_VERBOSE_ACTION ( log_msg ( "-------------- ActionSetTarget2: %s", target.to_string() ) );
			character *tar = cast_to<character> ( find_target ( target ) );

			if ( tar )
			{
				set_target ( tar );
				return;
			}
		}

		IF_VERBOSE_ACTION ( log_msg ( "can't set target %s\n", target.to_string() ) );
	}
Пример #12
0
bool melee_actor::call( monster &z ) const
{
    Creature *target = find_target( z );
    if( target == nullptr ) {
        return false;
    }

    z.mod_moves( -move_cost );

    add_msg( m_debug, "%s attempting to melee_attack %s", z.name().c_str(),
             target->disp_name().c_str() );

    const int acc = accuracy >= 0 ? accuracy : z.type->melee_skill;
    int hitspread = target->deal_melee_attack( &z, dice( acc, 10 ) );

    if( hitspread < 0 ) {
        auto msg_type = target == &g->u ? m_warning : m_info;
        sfx::play_variant_sound( "mon_bite", "bite_miss", sfx::get_heard_volume( z.pos() ),
                                 sfx::get_heard_angle( z.pos() ) );
        target->add_msg_player_or_npc( msg_type, miss_msg_u.c_str(), miss_msg_npc.c_str(),
                                       z.name().c_str() );
        return true;
    }

    damage_instance damage = damage_max_instance;

    double multiplier = rng_float( min_mul, max_mul );
    damage.mult_damage( multiplier );

    body_part bp_hit = body_parts.empty() ?
                       target->select_body_part( &z, hitspread ) :
                       *body_parts.pick();

    target->on_hit( &z, bp_hit );
    dealt_damage_instance dealt_damage = target->deal_damage( &z, bp_hit, damage );
    dealt_damage.bp_hit = bp_hit;

    int damage_total = dealt_damage.total_damage();
    add_msg( m_debug, "%s's melee_attack did %d damage", z.name().c_str(), damage_total );
    if( damage_total > 0 ) {
        on_damage( z, *target, dealt_damage );
    } else {
        sfx::play_variant_sound( "mon_bite", "bite_miss", sfx::get_heard_volume( z.pos() ),
                                 sfx::get_heard_angle( z.pos() ) );
        target->add_msg_player_or_npc( no_dmg_msg_u.c_str(), no_dmg_msg_npc.c_str(), z.name().c_str(),
                                       body_part_name_accusative( bp_hit ).c_str() );
    }

    return true;
}
Пример #13
0
void out_range(Tower* tower, GameState* state) {
	register int p;

	tower->target = find_target(tower, state->enemies, state->enemies_length);
	for (p = 0; p < tower->ammo;p++) {
		//verwijder projectiel
		if (tower->target == NULL) {
			tower->projectiles[p].live = 0;
		} //laat projectiel naar een nieuw doel vliegen
		else {
			if (tower->projectiles[p].live != 0) {
				tower->projectiles[p].target = tower->target;
			}
		}
	}
}
Пример #14
0
bfd_boolean
bfd_set_default_target (const char *name)
{
  const bfd_target *target;

  if (bfd_default_vector[0] != NULL
      && strcmp (name, bfd_default_vector[0]->name) == 0)
    return TRUE;

  target = find_target (name);
  if (target == NULL)
    return FALSE;

  bfd_default_vector[0] = target;
  return TRUE;
}
int play( string str ) {
  int val;

  if (in_use) {
    write("The dartboard is in use right now.\n");
    return 1;
  }

  if (!str) str = "0";

  if (!sscanf(str, "%d", val) || val < 0) {
    write("Bets must be for zero or greater coins.\n");
    return 1;
  }

  if (this_player()->query_money() < val) {
    write("Betting is not yet supported... I'm working on it! "
   "Just type \"play\".\n");
    return 1;
  }

  if (player1) {
    if (this_player() == player1) {
      write("You can't play against yourself!\n");
      return 1;
    }

    if (val != bet) {
      write("Bet amounts must match. " + name1 + " bet " + bet + ".\n");
      return 1; 
    }

    player2 = this_player();
    name2 = player2->query_short();
    target = find_target();
    tell_room( environment(), name1 + " and " + name2 + 
      " have started a game of darts, throwing at " + target 
      + ".\n", ({ player1, player2 }) );
    tell_object( player2, "You accept " + name1 + "'s challenge, "
      "and you both prepare to throw darts at " + target + ".\n" );
    tell_object( player1, name2 + " accepts your challenge, and you "
      "both prepare to throw darts at " + target + ".\nThrow your darts.\n");

    in_use = 1;
    return 1;
  }
Пример #16
0
int MPID_nem_ptl_rptl_get(ptl_handle_md_t md_handle, ptl_size_t local_offset, ptl_size_t length,
                          ptl_process_t target_id, ptl_pt_index_t pt_index,
                          ptl_match_bits_t match_bits, ptl_size_t remote_offset, void *user_ptr)
{
    struct rptl_op *op;
    int ret = PTL_OK;
    struct rptl_target *target;
    MPIDI_STATE_DECL(MPID_STATE_MPID_NEM_PTL_RPTL_GET);

    MPIDI_FUNC_ENTER(MPID_STATE_MPID_NEM_PTL_RPTL_GET);

    ret = find_target(target_id, &target);
    RPTLU_ERR_POP(ret, "error finding target structure\n");

    ret = rptli_op_alloc(&op, target);
    RPTLU_ERR_POP(ret, "error allocating op\n");

    op->op_type = RPTL_OP_GET;
    op->state = RPTL_OP_STATE_QUEUED;

    /* store the user parameters */
    op->u.get.md_handle = md_handle;
    op->u.get.local_offset = local_offset;
    op->u.get.length = length;
    op->u.get.target_id = target_id;
    op->u.get.pt_index = pt_index;
    op->u.get.match_bits = match_bits;
    op->u.get.remote_offset = remote_offset;
    op->u.get.user_ptr = user_ptr;

    op->events_ready = 0;
    op->target = target;

    MPL_DL_APPEND(target->data_op_list, op);

    ret = poke_progress();
    RPTLU_ERR_POP(ret, "Error from poke_progress\n");

  fn_exit:
    MPIDI_FUNC_EXIT(MPID_STATE_MPID_NEM_PTL_RPTL_GET);
    return ret;

  fn_fail:
    goto fn_exit;
}
Пример #17
0
/* Search for enemies and shoot */
static void soldier_animate(struct Critter *soldier) {
    if(soldier->cooloff>0)
        soldier->cooloff--;
    else if(soldier->ff==0 || soldier->cornered>60.0) {
        float targx,targy;
        if(find_target(soldier->physics.x, soldier->physics.y,
                    soldier->owner, &targx, &targy, NULL, 0))
        {
            if(critter_shoot(soldier,atan2(targy-soldier->physics.y,targx-soldier->physics.x))) {
                soldier->walker.walking = 0;
                if(soldier->cornered>70.0) /* Shoot like mad when cornered */
                    soldier->cooloff = 0.15*GAME_SPEED;
                else
                    soldier->cooloff = 0.7*GAME_SPEED;
            }
        }
    }
}
Пример #18
0
void do_tower_attacks(GameState * state) {
	register int i,j;
	for (i = 0; i < state->towers_length; i++) {
		Tower* tower = &state->towers[i]->tower;
		if (tower->target == NULL) {
			tower->target = find_target(tower, state->enemies, state->enemies_length);
			for (j = 0; j < tower->ammo; j++) {
				tower->projectiles[j].target = tower->target;
			}
		}else{
			if (!is_out_of_range(tower->projectiles, tower, &state->world)) {
				out_range(tower, state);
			} else {
				in_range(tower, state);
				tower->frames_since_last_shot = (tower->frames_since_last_shot + 1) % (tower->shoot_interval + 1);
			}
		}
	}
}
Пример #19
0
void g1_base_launcher_class::think()
{
	find_target();

	// can't hurt me.... I'm invincible! (no more)
	//health = 1000;

	pitch = 0; //groundpitch;//*cos(theta) - groundroll *sin(theta);
	roll  = 0; //groundroll;// *cos(theta) + groundpitch*sin(theta);

	if (fire_delay)
	{
		fire_delay--;
	}
	request_think();
	//aim the turet
	if (attack_target.valid())
	{


		i4_float dx,dy,angle,dangle;

		//this will obviously only be true if attack_target.ref != NULL
		dx = (attack_target->x - x);
		dy = (attack_target->y - y);

		//aim the turet

		angle = i4_atan2(dy,dx);

		//snap it
		i4_normalize_angle(angle);

		dangle = i4_rotate_to(theta,angle,defaults->turn_speed);
		if (dangle<defaults->turn_speed && dangle>-defaults->turn_speed)
		{
			if (!fire_delay)
			{
				fire();
			}
		}
	}
}
Пример #20
0
int attach(){
  // scan through proc fs
  DIR *dirp;
  struct dirent entry;
  struct dirent *endp;
  
  if((dirp = opendir("/proc/")) == NULL)
	return -1;

  for(;;){
	endp = NULL;
	if(readdir_r(dirp, &entry, &endp) == -1){
	  closedir(dirp);
	  return -1;
	}
	if(endp == NULL){
	  break;
	}

	int pid;
	if(sscanf(entry.d_name, "%d", &pid) == 1){
	  //printf("%s, %d\n", entry.d_name, pid);	  
	}else{
	  continue;
	}
	
	// this is the cmdline 
	char file_name[256];
	snprintf(file_name, sizeof(file_name), "/proc/%d/cmdline", pid);
	//printf("%s\n", file_name);
	
	FILE *cmdline = fopen(file_name, "r");
	if(cmdline != NULL){
	  char package_name[512];
	  fgets(package_name, sizeof(package_name), cmdline);
	  if(find_target(package_name)){
		printf("found %s\n", package_name);
		start_strace(pid);
	  }
	}
  }
}
Пример #21
0
static int unlock(const GPtrArray *distribution_array, const GPtrArray *target_array, gchar *profile)
{
    unsigned int i, running_processes = 0;
    int exit_status = 0;
    int status;
    
    /* For each locked machine, release the lock */
    for(i = 0; i < distribution_array->len; i++)
    {
        DistributionItem *item = g_ptr_array_index(distribution_array, i);
        Target *target = find_target(target_array, item->target);
        gchar *interface = find_target_client_interface(target);
        
        g_print("[target: %s]: Releasing a lock!\n", item->target);
        status = exec_unlock(interface, item->target, profile);
        
        if(status == -1)
        {
            g_printerr("[target: %s]: Error with forking unlock process!\n", item->target);
            exit_status = -1;
        }
        else
            running_processes++;
    }
    
    /* Wait until every lock is released */
    for(i = 0; i < running_processes; i++)
    {
        status = wait_to_finish(0);
        
        /* If a process fails, change the exit status */
        if(status != 0)
        {
            g_printerr("Failed to release the lock!\n");
            exit_status = status;
        }
    }
    
    /* Return exit status, which is 0 if everything succeeds */
    return exit_status;
}
Пример #22
0
int map_snapshot_items(GPtrArray *snapshots_array, GPtrArray *target_array, map_snapshot_item_function map_snapshot_item, complete_snapshot_item_mapping_function complete_snapshot_item_mapping)
{
    unsigned int num_processed = 0;
    int status = TRUE;
    GHashTable *pid_table = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, NULL);
    
    while(num_processed < snapshots_array->len)
    {
        unsigned int i;
    
        for(i = 0; i < snapshots_array->len; i++)
        {
            SnapshotMapping *mapping = g_ptr_array_index(snapshots_array, i);
            Target *target = find_target(target_array, mapping->target);
            
            if(!mapping->transferred && request_available_target_core(target)) /* Check if machine has any cores available, if not wait and try again later */
            {
                gchar **arguments = generate_activation_arguments(target, mapping->container); /* Generate an array of key=value pairs from container properties */
                unsigned int arguments_length = g_strv_length(arguments); /* Determine length of the activation arguments array */
                pid_t pid = map_snapshot_item(mapping, target, arguments, arguments_length);
                gint *pid_ptr;
                
                /* Add pid and mapping to the hash table */
                pid_ptr = g_malloc(sizeof(gint));
                *pid_ptr = pid;
                g_hash_table_insert(pid_table, pid_ptr, mapping);
              
                /* Cleanup */
                g_strfreev(arguments);
            }
        }
    
        if(!wait_to_complete_snapshot_item(pid_table, target_array, complete_snapshot_item_mapping))
            status = FALSE;
        
        num_processed++;
    }
    
    g_hash_table_destroy(pid_table);
    return status;
}
Пример #23
0
/* Search for enemies and shoot */
static void helicopter_animate(struct Critter *hc) {
    if(hc->cooloff>0)
        hc->cooloff--;
    else if(hc->ff==0) {
        double distance;
        float targx,targy;
        if(find_target(hc->physics.x,hc->physics.y, hc->owner, &targx, &targy,
                    &distance, 1))
        {
            if(distance>60.0) {
                hc->flyer.targx = targx;
                hc->flyer.targy = targy;
            }
            if(distance<150.0) {
                if(critter_shoot(hc,atan2(targy-hc->physics.y,targx-hc->physics.x))) {
                    hc->cooloff = 0.7*GAME_SPEED;
                }
            }
        }
    }
}
Пример #24
0
void generate_parsingtree(target_t *node, pid_t *child_pid)
{
	if(node == NULL)
		return;
	int ndep = 0;
	pid_t cpid[node->nDependencyCount];
	int status[node->nDependencyCount];
	memset(status, 0, node->nDependencyCount);

	while(ndep < node->nDependencyCount)  {
		generate_parsingtree(find_target(node->szDependencies[ndep]), cpid+ndep);
		ndep++;
	}
	// Wait for all the children to execute
	ndep=0;
	while(ndep < node->nDependencyCount)  {
		cpid[ndep] = waitpid( cpid[ndep], status+ndep, 0);
		ndep++;
	}

	// Execute the code if the dependencies are modified;
	ndep=0; int virginity = 1;
	while(ndep < node->nDependencyCount)  {
		int temp = compare_modification_time(node->szTarget, node->szDependencies[ndep]);
		if(temp!=1)
			virginity = -1;
		ndep++;
	}
	if(virginity ==-1)  { /* virginity is lost.  */
		*child_pid = fork();
		if(*child_pid==0)  {
			system(node->szCommand);
			printf("\n%s\t%d", node->szCommand, getpid());
			exit(0);
		}	
	}
	else  { /* virginity is maintained.  */
		printf("\n no need of %s", node->szCommand);
	}
}
Пример #25
0
	void process_frame(ClFrame &in_frame, ClFrame &out_frame, ClFrame &orig_frame) {
		PERF_START("process_frame");

		if(m_crop) {
			in_frame.set_origin(m_width/2, m_height/2, 0);
			in_frame.set_region( m_width/3, m_height/3, 1);
			out_frame.set_origin(m_width/2, m_height/2, 0);
			out_frame.set_region( m_width/3, m_height/3, 1);
#ifndef _WITH_FRAMECPY
			//in_frame.vflip(); // no need to flip for frame memcpy
#endif //_WITH_FRAMECPY
		}

		if(m_crop) {
			set_background_image(bg_img);
		}

		if(m_ocl_image) {
			if(copyimg.proc(in_frame, out_frame) == false) {
				return;
			}
		}

		if(m_motion) {
			if(transimg.proc(3, in_frame, out_frame) == false) {
				return;
			}
		}  

		if(m_target.is_search()) {
			find_target(in_frame.get());
		}

		if(m_ocl_image || m_motion) {
			display_frame(out_frame);
		} else {
			display_frame(in_frame);
		}
		PERF_END("process_frame");
	}
Пример #26
0
	as_value	as_environment::get_variable ( const tu_string &varname, const array<with_stack_entry>& with_stack ) const
	// Return the value of the given var, if it's defined.
	{
		// Path lookup rigamarole.
		as_object	*target = get_target();
		tu_string	path;
		tu_string	var;

		if ( parse_path ( varname, &path, &var ) )
		{
			// @@ Use with_stack here too???  Need to test.
			target = find_target ( path.c_str() );

			if ( target )
			{
				as_value	val;
				target->get_member ( var, &val );
				return val;
			}

			else if ( ( target = get_player()->get_global()->find_target ( path.c_str() ) ) )
			{
				as_value	val;
				target->get_member ( var, &val );
				return val;
			}

			else
			{
				IF_VERBOSE_ACTION ( log_msg ( "find_target(\"%s\") failed\n", path.c_str() ) );
				return as_value();
			}
		}

		else
		{
			return get_variable_raw ( varname, with_stack );
		}
	}
Пример #27
0
static void wait_for_activation_or_deactivation(const int activate, GHashTable *pids, GPtrArray *target_array)
{
    int status;
    Target *target;
    
    /* Wait for an activation/deactivation process to finish */
    pid_t pid = wait(&status);
    
    if(pid != -1)
    {
        /* Find the corresponding activation mapping and remove it from the pids table */
        ActivationMapping *mapping = g_hash_table_lookup(pids, &pid);
        g_hash_table_remove(pids, &pid);
    
        /* Change the status of the mapping, if the process returns success */
        if(WEXITSTATUS(status) == 0)
        {
            if(activate)
                mapping->status = ACTIVATIONMAPPING_ACTIVATED;
            else
                mapping->status = ACTIVATIONMAPPING_DEACTIVATED;
        }
        else
        {
            mapping->status = ACTIVATIONMAPPING_ERROR;
        
            if(activate)
                g_printerr("[target: %s]: Activation failed of service: %s\n", mapping->target, mapping->key);
            else
                g_printerr("[target: %s]: Deactivation failed of service: %s\n", mapping->target, mapping->key);
        }
    
        /* Signal the target to make the CPU core available again */
        target = find_target(target_array, mapping->target);
        signal_available_target_core(target);
    }
}
Пример #28
0
static int
print_ipt(struct action_util *au, FILE * f, struct rtattr *arg)
{
	struct rtattr *tb[TCA_IPT_MAX + 1];
	struct xt_entry_target *t = NULL;

	if (arg == NULL)
		return -1;

	set_lib_dir();

	parse_rtattr_nested(tb, TCA_IPT_MAX, arg);

	if (tb[TCA_IPT_TABLE] == NULL) {
		fprintf(f, "[NULL ipt table name ] assuming mangle ");
	} else {
		fprintf(f, "tablename: %s ",
			rta_getattr_str(tb[TCA_IPT_TABLE]));
	}

	if (tb[TCA_IPT_HOOK] == NULL) {
		fprintf(f, "[NULL ipt hook name ]\n ");
		return -1;
	} else {
		__u32 hook;

		hook = rta_getattr_u32(tb[TCA_IPT_HOOK]);
		fprintf(f, " hook: %s\n", ipthooks[hook]);
	}

	if (tb[TCA_IPT_TARG] == NULL) {
		fprintf(f, "\t[NULL ipt target parameters ]\n");
		return -1;
	} else {
		struct xtables_target *m = NULL;

		t = RTA_DATA(tb[TCA_IPT_TARG]);
		m = find_target(t->u.user.name, TRY_LOAD);
		if (m != NULL) {
			if (build_st(m, t) < 0) {
				fprintf(stderr, " %s error\n", m->name);
				return -1;
			}

			opts =
			    merge_options(opts, m->extra_opts,
					  &m->option_offset);
		} else {
			fprintf(stderr, " failed to find target %s\n\n",
				t->u.user.name);
			return -1;
		}
		fprintf(f, "\ttarget ");
		m->print(NULL, m->t, 0);
		if (tb[TCA_IPT_INDEX] == NULL) {
			fprintf(f, " [NULL ipt target index ]\n");
		} else {
			__u32 index;

			index = rta_getattr_u32(tb[TCA_IPT_INDEX]);
			fprintf(f, "\n\tindex %u", index);
		}

		if (tb[TCA_IPT_CNT]) {
			struct tc_cnt *c  = RTA_DATA(tb[TCA_IPT_CNT]);

			fprintf(f, " ref %d bind %d", c->refcnt, c->bindcnt);
		}
		if (show_stats) {
			if (tb[TCA_IPT_TM]) {
				struct tcf_t *tm = RTA_DATA(tb[TCA_IPT_TM]);

				print_tm(f, tm);
			}
		}
		fprintf(f, "\n");

	}
	free_opts(opts);

	return 0;
}
Пример #29
0
static int parse_ipt(struct action_util *a, int *argc_p,
		     char ***argv_p, int tca_id, struct nlmsghdr *n)
{
	struct xtables_target *m = NULL;
	struct ipt_entry fw;
	struct rtattr *tail;
	int c;
	int rargc = *argc_p;
	char **argv = *argv_p;
	int argc = 0, iargc = 0;
	char k[FILTER_NAMESZ];
	int size = 0;
	int iok = 0, ok = 0;
	__u32 hook = 0, index = 0;

	set_lib_dir();

	{
		int i;

		for (i = 0; i < rargc; i++) {
			if (NULL == argv[i] || 0 == strcmp(argv[i], "action")) {
				break;
			}
		}
		iargc = argc = i;
	}

	if (argc <= 2) {
		fprintf(stderr, "bad arguments to ipt %d vs %d\n", argc, rargc);
		return -1;
	}

	while (1) {
		c = getopt_long(argc, argv, "j:", opts, NULL);
		if (c == -1)
			break;
		switch (c) {
		case 'j':
			m = find_target(optarg, TRY_LOAD);
			if (m != NULL) {

				if (build_st(m, NULL) < 0) {
					printf(" %s error\n", m->name);
					return -1;
				}
				opts =
				    merge_options(opts, m->extra_opts,
						  &m->option_offset);
			} else {
				fprintf(stderr, " failed to find target %s\n\n", optarg);
				return -1;
			}
			ok++;
			break;

		default:
			memset(&fw, 0, sizeof(fw));
			if (m) {
				m->parse(c - m->option_offset, argv, 0,
					 &m->tflags, NULL, &m->t);
			} else {
				fprintf(stderr, " failed to find target %s\n\n", optarg);
				return -1;

			}
			ok++;
			break;

		}
	}

	if (iargc > optind) {
		if (matches(argv[optind], "index") == 0) {
			if (get_u32(&index, argv[optind + 1], 10)) {
				fprintf(stderr, "Illegal \"index\"\n");
				free_opts(opts);
				return -1;
			}
			iok++;

			optind += 2;
		}
	}

	if (!ok && !iok) {
		fprintf(stderr, " ipt Parser BAD!! (%s)\n", *argv);
		return -1;
	}

	/* check that we passed the correct parameters to the target */
	if (m)
		m->final_check(m->tflags);

	{
		struct tcmsg *t = NLMSG_DATA(n);

		if (t->tcm_parent != TC_H_ROOT
		    && t->tcm_parent == TC_H_MAJ(TC_H_INGRESS)) {
			hook = NF_IP_PRE_ROUTING;
		} else {
			hook = NF_IP_POST_ROUTING;
		}
	}

	tail = addattr_nest(n, MAX_MSG, tca_id);
	fprintf(stdout, "tablename: %s hook: %s\n ", tname, ipthooks[hook]);
	fprintf(stdout, "\ttarget: ");

	if (m)
		m->print(NULL, m->t, 0);
	fprintf(stdout, " index %d\n", index);

	if (strlen(tname) > 16) {
		size = 16;
		k[15] = 0;
	} else {
		size = 1 + strlen(tname);
	}
	strncpy(k, tname, size);

	addattr_l(n, MAX_MSG, TCA_IPT_TABLE, k, size);
	addattr_l(n, MAX_MSG, TCA_IPT_HOOK, &hook, 4);
	addattr_l(n, MAX_MSG, TCA_IPT_INDEX, &index, 4);
	if (m)
		addattr_l(n, MAX_MSG, TCA_IPT_TARG, m->t, m->t->u.target_size);
	addattr_nest_end(n, tail);

	argc -= optind;
	argv += optind;
	*argc_p = rargc - iargc;
	*argv_p = argv;

	optind = 0;
	free_opts(opts);
	/* Clear flags if target will be used again */
        m->tflags = 0;
        m->used = 0;
	/* Free allocated memory */
	if (m->t)
	    free(m->t);


	return 0;

}
Пример #30
0
/* We want this to be readable, so only print out neccessary fields.
 * Because that's the kind of world I want to live in.  */
static void print_rule(const struct ip6t_entry *e, 
		ip6tc_handle_t *h, const char *chain, int counters)
{
	struct ip6t_entry_target *t;
	const char *target_name;

	/* print counters */
	if (counters)
		printf("[%llu:%llu] ", (unsigned long long)e->counters.pcnt, (unsigned long long)e->counters.bcnt);

	/* print chain name */
	printf("-A %s ", chain);

	/* Print IP part. */
	print_ip("-s", &(e->ipv6.src), &(e->ipv6.smsk),
			e->ipv6.invflags & IP6T_INV_SRCIP);	

	print_ip("-d", &(e->ipv6.dst), &(e->ipv6.dmsk),
			e->ipv6.invflags & IP6T_INV_DSTIP);

	print_iface('i', e->ipv6.iniface, e->ipv6.iniface_mask,
		    e->ipv6.invflags & IP6T_INV_VIA_IN);

	print_iface('o', e->ipv6.outiface, e->ipv6.outiface_mask,
		    e->ipv6.invflags & IP6T_INV_VIA_OUT);

	print_proto(e->ipv6.proto, e->ipv6.invflags & IP6T_INV_PROTO);

#if 0
	/* not definied in ipv6
	 * FIXME: linux/netfilter_ipv6/ip6_tables: IP6T_INV_FRAG why definied? */
	if (e->ipv6.flags & IPT_F_FRAG)
		printf("%s-f ",
		       e->ipv6.invflags & IP6T_INV_FRAG ? "! " : "");
#endif

	if (e->ipv6.flags & IP6T_F_TOS)
		printf("%s-? %d ",
		       e->ipv6.invflags & IP6T_INV_TOS ? "! " : "", 
		       e->ipv6.tos);

	/* Print matchinfo part */
	if (e->target_offset) {
		IP6T_MATCH_ITERATE(e, print_match, &e->ipv6);
	}

	/* Print target name */	
	target_name = ip6tc_get_target(e, h);
	if (target_name && (*target_name != '\0'))
		printf("-j %s ", target_name);

	/* Print targinfo part */
	t = ip6t_get_target((struct ip6t_entry *)e);
	if (t->u.user.name[0]) {
		struct ip6tables_target *target
			= find_target(t->u.user.name, TRY_LOAD);

		if (!target) {
			fprintf(stderr, "Can't find library for target `%s'\n",
				t->u.user.name);
			exit(1);
		}

		if (target->save)
			target->save(&e->ipv6, t);
		else {
			/* If the target size is greater than ip6t_entry_target
			 * there is something to be saved, we just don't know
			 * how to print it */
			if (t->u.target_size != 
			    sizeof(struct ip6t_entry_target)) {
				fprintf(stderr, "Target `%s' is missing "
						"save function\n",
					t->u.user.name);
				exit(1);
			}
		}
	}
	printf("\n");
}