Ejemplo n.º 1
0
bool cf_set(const struct CfContext *cf, const char *sect, const char *key, const char *val)
{
	const struct CfSect *s;
	const struct CfKey *k;
	void *base, *p;
	struct CfValue cv;

	/* find section */
	s = find_sect(cf, sect);
	if (!s) {
		log_error("Unknown section: %s", sect);
		return false;
	}

	/* find section base */
	base = cf->base;
	if (s->base_lookup)
	    base = s->base_lookup(base, sect);

	/* handle dynamic keys */
	if (s->set_key)
		return s->set_key(base, key, val);

	/* set fixed key */
	k = find_key(s, key);
	if (!k) {
		log_error("Unknown parameter: %s/%s", sect, key);
		return false;
	}
	if (!k->op.setter || (k->flags & CF_READONLY)) {
		/* silently ignore */
		return true;
	}
	if ((k->flags & CF_NO_RELOAD) && cf->loaded) {
		/* silently ignore */
		return true;
	}
	p = get_dest(base, k);
	if (!p) {
		log_error("Bug - no base for relative key: %s/%s", sect, key);
		return false;
	}
	cv.key_name = k->key_name;
	cv.extra = k->op.op_extra;
	cv.value_p = p;
	cv.buf = NULL;
	cv.buflen = 0;
	return k->op.setter(&cv, val);
}
Ejemplo n.º 2
0
void Levels::generate_passenger(int time){
    for (int l = 0; l < nl; l++) {
        int newp = pd.get_next();
        logger.add(l, newp);
        while (newp--){
            Passenger p;
            p.arrival_time = time;
            p.arrival_level = l;
            p.destination_level = get_dest(l);
            if (p.destination_level > l)
                go_up[l].push_back(p);
            else
                go_down[l].push_back(p);
        }
    }
}
Ejemplo n.º 3
0
void write_ipether(struct libnet_link_int *iface, char *dev, struct eth_pair *src)
{
    unsigned char pkt[ETH_H + IP_H + UDP_H];
    struct eth_pair *dst = get_dest();
    
    libnet_build_ethernet(dst->eth, src->eth, ETHERTYPE_IP, NULL, 0, pkt);
    libnet_build_ip(UDP_H, 0, 0, 0, 2, IPPROTO_UDP, src->ip, dst->ip,
	    NULL, 0, pkt + ETH_H);
    libnet_build_udp(rand() % (0xffff-1024) + 1024, rand() % 1024, 
		     NULL, 0, pkt + ETH_H + IP_H);
    if(libnet_do_checksum(pkt+ETH_H, IPPROTO_IP, IP_H) == -1)
	perror("ipv4 cksum");
    if(libnet_do_checksum(pkt+ETH_H, IPPROTO_UDP, UDP_H) == -1)
	perror("ipv4 cksum");
    if(libnet_write_link_layer(iface, dev, pkt, sizeof(pkt)) 
	    != sizeof(pkt))
	perror("Write link layer");
}
Ejemplo n.º 4
0
const char *cf_get(const struct CfContext *cf, const char *sect, const char *key,
		   char *buf, int buflen)
{
	const struct CfSect *s;
	const struct CfKey *k;
	void *base, *p;
	struct CfValue cv;

	/* find section */
	s = find_sect(cf, sect);
	if (!s)
		return NULL;

	/* find section base */
	base = cf->base;
	if (s->base_lookup)
	    base = s->base_lookup(base, sect);

	/* handle dynamic keys */
	if (s->set_key) {
		if (!s->get_key)
			return NULL;
		return s->get_key(base, key, buf, buflen);
	}

	/* get fixed key */
	k = find_key(s, key);
	if (!k || !k->op.getter)
		return NULL;
	p = get_dest(base, k);
	if (!p)
		return NULL;
	cv.key_name = k->key_name;
	cv.extra = k->op.op_extra;
	cv.value_p = p;
	cv.buf = buf;
	cv.buflen = buflen;
	return k->op.getter(&cv);
}
Ejemplo n.º 5
0
int main (int argc, char** argv)
{
    world_skeleton_t *s;
    map_t *map;
    announcer_t a;

    char* name = "mrscolumbo";

    brain_t* brain;

    if(argc>1)
    {
	    srand(argv[1][0]);
	    
    }

    a = init_announcer(stdout);
    announce_reg(a, name, PTYPE_COP_FOOT);

    s = parse_world_skeleton(stdin);

    //parser_print_world_skeleton(s);

    map = build_map(s);

    dprintf("NAME: %s\n", s->name);

    brain = create_brain(s->name, map);
    /*
    printf("dist: %d\n", get_dist(map, CHOOSE_FOOT,
				  node_index(map, "55-and-woodlawn"),
				  node_index(map, "54-and-ridgewood")));
    */


    for(;;)
    {
	world_message_t *m;
	node_line_t *my_node;
	cop_inform_msg_t* inform;
	cop_plan_msg_t* plans;
	cop_vote_msg_t* votes;
	vote_tally_t* tally;
	int bestdst;
	int* path;

	m = parse_world_message(s);
	
	announce_inform(a, NULL);

	if(!m->game_running)
		break; 

	my_node = player_node(m, map, s->name, 0); 

	update_brain(s, m, map, brain);
	
	inform = parse_inform_messages(s);
	free_inform_messages(inform);

	announce_plan(a, NULL);
	plans = parse_plan_messages(s);

	free_plan_messages(plans);
	
	votes = make_stupid_votes(s, brain);
	announce_vote(a, votes);
	free(votes);

	tally = parse_vote_tally(s);
	free_vote_tally(tally);


	bestdst = get_dest(s, m, map, brain);
	
	if(ada_kurds_here_p(s, m, map, brain))
	{
		bestdst = (rand()%(map->num_nodes));
	}


	//path = get_combined_prev(map, CHOOSE_FROM_PTYPE(brain->my_ptype), brain->my_pos);
	// ALERT
	path = get_prev(map, CHOOSE_FROM_PTYPE(brain->my_ptype), brain->my_pos);
	
	if(get_combined_switchp(map, CHOOSE_FROM_PTYPE(brain->my_ptype), brain->my_pos))
	{
		// ALERT
		//switch_transport(brain, map);
	}
	

	while(path[bestdst]!=brain->my_pos)
	{
		bestdst = path[bestdst];
	}

	announce_move(a, s, m, node_by_index(map, bestdst)->loc, brain->my_ptype);
    }
	

    return 0;
}
Ejemplo n.º 6
0
/*
  double forks to avoid zombie process
*/
char* exec_cmd(const char* cmdString, char *resultString)
{
  int pipe_fd[2];
  pid_t child_pid = -1;
  pid_t grandchild_pid = -1;
  int status = 0;
  struct timeval timeout;
  char buf[LINE_MAX];
  int bytesRead = 0;
  fd_set read_fds;
  const char* dest = get_dest();
  const char* zbxConf = get_zbx_conf();

//  syslog(LOG_DEBUG, ("[%d] exec_cmd(): [%s]", getpid(), cmdString);

  if (cmdString == NULL) {
    syslog(LOG_DEBUG, "exec_cmd(): cmd error");
    return strncat(resultString, RESULT_STRINGS[1], strlen(RESULT_STRINGS[1]));
  }

  if (pipe(pipe_fd) < 0) { // create a pipes (0 = read end, 1 = write end)
    syslog(LOG_NOTICE, "exec_cmd(): pipe error: %s", strerror(errno));
    return strncat(resultString, RESULT_STRINGS[0], strlen(RESULT_STRINGS[0]));
  }

  child_pid = fork();
  if (child_pid < 0) {
    syslog(LOG_NOTICE, "exec_cmd(): fork error: %s", strerror(errno));
    return strncat(resultString, RESULT_STRINGS[0], strlen(RESULT_STRINGS[0]));
  }
  else if (child_pid == 0) {
    // child - which will exit immediately after forking a grandchild
    close(pipe_fd[0]);   // child doesn't need the read end of the pipe
    if ((grandchild_pid = fork()) < 0) {
      syslog(LOG_NOTICE, "exec_cmd(): child fork error: %s\n", strerror(errno));
      exit(-1);
    }
    else if (grandchild_pid == 0) {
      // grandchild - which actually executes the command
      close(1);        // close grandchild stdout
      dup(pipe_fd[1]); // and make the stdout the same as the pipe_fd[1]
      execl(cmdString, cmdString, dest, zbxConf, (char*)0);
      exit(0);
    }
    else {
      // child
      //syslog(LOG_DEBUG, ("grandchild_pid[%d]", grandchild_pid);
      sprintf(buf, "%d", grandchild_pid);
      write(pipe_fd[1], buf, strlen(buf));
      exit(0);
    }
  }
  else {
    // parent
    waitpid(child_pid, &status, 0);

    // get grandchild pid - the first string to be written to the pipe
    memset(buf, '\0', sizeof(buf));
    read(pipe_fd[0], buf, 20); // assume max length of pid string is 20
    sscanf(buf, "%d", &grandchild_pid);
    syslog(LOG_DEBUG, "exec_cmd(): [%d->%d->%d: %s %s]",
            getpid(), child_pid, grandchild_pid,
            cmdString, dest);

    timeout.tv_sec  = get_cmd_timeout();
    timeout.tv_usec = 0;
    FD_ZERO(&read_fds);
    FD_SET(pipe_fd[0], &read_fds);
    switch (select(pipe_fd[0]+1, &read_fds, NULL, NULL, &timeout)) {
      case -1:
        syslog(LOG_NOTICE, "exec_cmd(): select() error: %s", strerror(errno));
        return strncat(resultString, RESULT_STRINGS[0], strlen(RESULT_STRINGS[0]));
      case 0:
        syslog(LOG_NOTICE, "exec_cmd(): timeout [%s]", cmdString);
        close(pipe_fd[0]);
        //send a signal the script can trap and cleanup
        kill(grandchild_pid, SIGTERM);
        return strncat(resultString, RESULT_STRINGS[0], strlen(RESULT_STRINGS[0]));
      default:
        memset(buf, '\0', sizeof(buf));
        bytesRead = read(pipe_fd[0], buf, sizeof(buf));
        close(pipe_fd[0]);
        syslog(LOG_DEBUG, "exec_cmd(): read [%d] [%s]", bytesRead, buf);
        return strcat(resultString, buf);
    }
  }

  return NULL;
}
Ejemplo n.º 7
0
static GLuint emit_texenv( struct i915_fragment_program *p, int unit )
{
   struct gl_texture_unit *texUnit = &p->ctx->Texture.Unit[unit];
   GLenum envMode = texUnit->EnvMode;
   struct gl_texture_object *tObj = texUnit->_Current;
   GLenum format = tObj->Image[0][tObj->BaseLevel]->_BaseFormat;
   GLuint saturate = unit < p->last_tex_stage ? A0_DEST_SATURATE : 0;

   switch(envMode) {
   case GL_BLEND: {
      const int cf = get_source(p, GL_PREVIOUS, unit);
      const int cc = get_source(p, GL_CONSTANT, unit);
      const int cs = get_source(p, GL_TEXTURE, unit);
      const int out = get_dest(p, unit);

      if (format == GL_INTENSITY) {
	 /* cv = cf(1 - cs) + cc.cs
	  * cv = cf - cf.cs + cc.cs
	  */
	 /* u[2] = MAD( -cf * cs + cf )
	  * cv   = MAD( cc * cs + u[2] )
	  */
	 
	 i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, 0, 
			 negate(cf,1,1,1,1), cs, cf );

	 i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, saturate, 
			 cc, cs, out );

	 return out;
      } else {
	 /* cv = cf(1 - cs) + cc.cs
	  * cv = cf - cf.cs + cc.cs
	  * av =      af.as
	  */
	 /* u[2] = MAD( cf.-x-y-zw * cs.xyzw + cf.xyz0 )
	  * oC   = MAD( cc.xyz0 * cs.xyz0 + u[2].xyzw )
	  */
	 i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, 0,
			 negate(cf,1,1,1,0),  
			 cs,
			 swizzle(cf,X,Y,Z,ZERO) );


	 i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, saturate,
			 swizzle(cc,X,Y,Z,ZERO),  
			 swizzle(cs,X,Y,Z,ZERO),
			 out );

	 return out;
      }
   }

   case GL_DECAL: {
      if (format == GL_RGB ||
	  format == GL_RGBA) {
	 int cf = get_source( p, GL_PREVIOUS, unit );
	 int cs = get_source( p, GL_TEXTURE, unit );
	 int out = get_dest(p, unit);
	 
	 /* cv = cf(1-as) + cs.as
	  * cv = cf.(-as) + cf + cs.as
	  * av = af
	  */ 
	 
	 /* u[2] = mad( cf.xyzw * cs.-w-w-w1 + cf.xyz0 )
	  * oc = mad( cs.xyz0 * cs.www0 + u[2].xyzw )
	  */
	 i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, 0,
			 cf,  
			 negate(swizzle(cs,W,W,W,ONE),1,1,1,0),
			 swizzle(cf,X,Y,Z,ZERO) );
	 
	 i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, saturate,
			 swizzle(cs,X,Y,Z,ZERO),  
			 swizzle(cs,W,W,W,ZERO),
			 out );
	 return out;
      }
      else {
	 return get_source( p, GL_PREVIOUS, unit );
      }
   }

   case GL_REPLACE: {
      const int cs = get_source( p, GL_TEXTURE, unit );	/* saturated */
      switch (format) {
      case GL_ALPHA: {
	 const int cf = get_source( p, GL_PREVIOUS, unit ); /* saturated */
	 i915_emit_arith( p, A0_MOV, cs, A0_DEST_CHANNEL_XYZ, 0, cf, 0, 0 );
	 return cs;
      }
      case GL_RGB:
      case GL_LUMINANCE: {
	 const int cf = get_source( p, GL_PREVIOUS, unit ); /* saturated */
	 i915_emit_arith( p, A0_MOV, cs, A0_DEST_CHANNEL_W, 0, cf, 0, 0 );
	 return cs;
      }
      default:
	 return cs;
      }
   }

   case GL_MODULATE: {
      const int cf = get_source( p, GL_PREVIOUS, unit );
      const int cs = get_source( p, GL_TEXTURE, unit );
      const int out = get_dest(p, unit);
      switch (format) {
      case GL_ALPHA: 
	 i915_emit_arith( p, A0_MUL, out, A0_DEST_CHANNEL_ALL, saturate,
			 swizzle(cs, ONE, ONE, ONE, W), cf, 0 );
	 break;
      default:
	 i915_emit_arith( p, A0_MUL, out, A0_DEST_CHANNEL_ALL, saturate, 
			 cs, cf, 0 );
	 break;
      }
      return out;
   }
   case GL_ADD: {
      int cf = get_source( p, GL_PREVIOUS, unit );
      int cs = get_source( p, GL_TEXTURE, unit );
      const int out = get_dest( p, unit );

      if (format == GL_INTENSITY) {
	 /* output-color.rgba = add( incoming, u[1] )
	  */
	 i915_emit_arith( p, A0_ADD, out, A0_DEST_CHANNEL_ALL, saturate, 
			 cs, cf, 0 );
	 return out;
      }
      else {
	 /* cv.xyz = cf.xyz + cs.xyz
	  * cv.w   = cf.w * cs.w
	  *
	  * cv.xyzw = MAD( cf.111w * cs.xyzw + cf.xyz0 )
	  */
 	 i915_emit_arith( p, A0_MAD, out, A0_DEST_CHANNEL_ALL, saturate,
			 swizzle(cf,ONE,ONE,ONE,W), 
			 cs,  
			 swizzle(cf,X,Y,Z,ZERO) ); 
	 return out;
      }
      break;
   }
   case GL_COMBINE: {
      GLuint rgb_shift, alpha_shift, out, shift;
      GLuint dest = get_dest(p, unit);

      /* The EXT version of the DOT3 extension does not support the
       * scale factor, but the ARB version (and the version in OpenGL
       * 1.3) does.
       */
      switch (texUnit->Combine.ModeRGB) {
      case GL_DOT3_RGB_EXT:
	 alpha_shift = texUnit->Combine.ScaleShiftA;
	 rgb_shift = 0;
	 break;

      case GL_DOT3_RGBA_EXT:
	 alpha_shift = 0;
	 rgb_shift = 0;
	 break;

      default:
	 rgb_shift = texUnit->Combine.ScaleShiftRGB;
	 alpha_shift = texUnit->Combine.ScaleShiftA;
	 break;
      }


      /* Emit the RGB and A combine ops
       */
      if (texUnit->Combine.ModeRGB == texUnit->Combine.ModeA && 
	  args_match( texUnit )) {
	 out = emit_combine( p, dest, A0_DEST_CHANNEL_ALL, saturate,
			     unit,
			     texUnit->Combine.ModeRGB,
			     texUnit->Combine.SourceRGB,
			     texUnit->Combine.OperandRGB );
      }
      else if (texUnit->Combine.ModeRGB == GL_DOT3_RGBA_EXT ||
	       texUnit->Combine.ModeRGB == GL_DOT3_RGBA) {

	 out = emit_combine( p, dest, A0_DEST_CHANNEL_ALL, saturate,
			     unit,
			     texUnit->Combine.ModeRGB,
			     texUnit->Combine.SourceRGB,
			     texUnit->Combine.OperandRGB );
      }
      else {
	 /* Need to do something to stop from re-emitting identical
	  * argument calculations here:
	  */
	 out = emit_combine( p, dest, A0_DEST_CHANNEL_XYZ, saturate,
			     unit,
			     texUnit->Combine.ModeRGB,
			     texUnit->Combine.SourceRGB,
			     texUnit->Combine.OperandRGB );
	 out = emit_combine( p, dest, A0_DEST_CHANNEL_W, saturate,
			     unit,
			     texUnit->Combine.ModeA,
			     texUnit->Combine.SourceA,
			     texUnit->Combine.OperandA );
      }

      /* Deal with the final shift:
       */
      if (alpha_shift || rgb_shift) {
	 if (rgb_shift == alpha_shift) {
	    shift = i915_emit_const1f(p, 1<<rgb_shift);
	    shift = swizzle(shift,X,X,X,X);
	 }
	 else {
	    shift = i915_emit_const2f(p, 1<<rgb_shift, 1<<alpha_shift);
	    shift = swizzle(shift,X,X,X,Y);
	 }
	 return i915_emit_arith( p, A0_MUL, dest, A0_DEST_CHANNEL_ALL, 
				saturate, out, shift, 0 );
      }

      return out;
   }

   default:
      return get_source(p, GL_PREVIOUS, 0);
   }
}