Exemplo n.º 1
0
/***** check one process */
static void check_proc(int pid){
  char buf[128];
  struct stat statbuf;
  char *tmp;
  int tty;
  int fd;
  int i;
  if(pid==my_pid) return;
  sprintf(buf, "/proc/%d/stat", pid); /* pid (cmd) state ppid pgrp session tty */
  fd = open(buf,O_RDONLY);
  if(fd==-1){  /* process exited maybe */
    if(pids && w_flag) printf("WARNING: process %d could not be found.",pid);
    return;
  }
  fstat(fd, &statbuf);
  if(uids){  /* check the EUID */
    i=uid_count;
    while(i--) if(uids[i]==statbuf.st_uid) break;
    if(i==-1) goto closure;
  }
  read(fd,buf,128);
  buf[127] = '\0';
  tmp = strrchr(buf, ')');
  *tmp++ = '\0';
  i = 5; while(i--) while(*tmp++!=' '); /* scan to find tty */
  tty = atoi(tmp);
  if(ttys){
    i=tty_count;
    while(i--) if(ttys[i]==tty) break;
    if(i==-1) goto closure;
  }
  tmp = strchr(buf, '(') + 1;
  if(cmds){
    i=cmd_count;
    /* fast comparison trick -- useful? */
    while(i--) if(cmds[i][0]==*tmp && !strcmp(cmds[i],tmp)) break;
    if(i==-1) goto closure;
  }
  /* This is where we kill/nice something. */
/*  fprintf(stderr, "PID %d, UID %d, TTY %d,%d, COMM %s\n",
    pid, statbuf.st_uid, tty>>8, tty&0xf, tmp
  );
*/
  hurt_proc(tty, statbuf.st_uid, pid, tmp);
closure:
  close(fd); /* kill/nice _first_ to avoid PID reuse */
}
Exemplo n.º 2
0
// wrapper around hurt_proc for cases where the damage is caused by something that can be caught by virtual interface.
// damage sources that are not caught by virtual interface should call hurt_proc directly
void apply_packet_damage_to_proc(struct proc_struct* pr, int damage, int cause_team, int cause_core_index, timestamp cause_core_timestamp)
{

		struct core_struct* core = &w.core[pr->core_index];

		core->damage_source_core_index = cause_core_index;
		core->damage_source_core_timestamp = cause_core_timestamp;
		core->damage_this_cycle += damage;

// if (pr->interface_object_present
//	 && pr->interface_on_process_set_on) // checks for core->interface_active just below
 if (pr->interface_protects) // checks for core->interface_active just below
	{

		if (core->interface_active)
		{
   if (pr->interface_stability)
    damage /= 2;
   core->interface_strength -= damage;
			if (core->interface_strength > 0)
			{
				pr->interface_hit_time = w.world_time;
				return;
			}
// interface broken:
//   fpr("\n broken interface core %i", core->index);
   core->interface_active = 0;
   core->interface_broken_time = w.world_time;
		 play_game_sound(SAMPLE_INT_BREAK, TONE_1G, 140, 1, pr->position.x, pr->position.y);
   int i;
   for (i = 0; i < core->group_members_max; i ++)
			{
				if (core->group_member[i].exists
				 &&	w.proc[core->group_member[i].index].interface_protects)
//				 &&	w.proc[core->group_member[i].index].interface_object_present
//				 && w.proc[core->group_member[i].index].interface_on_process_set_on)
				{
     struct cloud_struct* cl = new_cloud(CLOUD_INTERFACE_BREAK, 32, w.proc[core->group_member[i].index].position.x, w.proc[core->group_member[i].index].position.y);
     if (cl != NULL)
     {
      cl->angle = w.proc[core->group_member[i].index].angle;
      cl->colour = w.proc[core->group_member[i].index].player_index;
      cl->data [0] = w.proc[core->group_member[i].index].shape;
      cl->speed.x = 0;
      cl->speed.y = 0;
      cl->display_size_x1 = -200;
      cl->display_size_y1 = -200;
      cl->display_size_x2 = 200;
      cl->display_size_y2 = 200;
     }
				}
			}
/*
   struct cloud_struct* cl = new_cloud(CLOUD_INTERFACE_BREAK, 32, pr->position.x, pr->position.y);
   if (cl != NULL)
   {
    cl->angle = pr->angle;
    cl->colour = pr->player_index;
    cl->data [0] = pr->shape;
    cl->speed.x = 0;
    cl->speed.y = 0;
    cl->display_size_x1 = -200;
    cl->display_size_y1 = -200;
    cl->display_size_x2 = 200;
    cl->display_size_y2 = 200;
   }

*/
// after interface is broken strength may be -ve, in which case the interface may need to recharge for a while.
   return;
		}

	}

/*
 if (pr->virtual_method != -1
  && pr->method[pr->virtual_method].data [MDATA_PR_VIRTUAL_STATE] > 0)
 {
  if (damage >= pr->method[pr->virtual_method].data [MDATA_PR_VIRTUAL_STATE])
  {
   damage -= pr->method[pr->virtual_method].data [MDATA_PR_VIRTUAL_STATE];

   virtual_method_break(pr);

  }
   else
   {
    pr->method[pr->virtual_method].data [MDATA_PR_VIRTUAL_STATE] -= damage;
    pr->method[pr->virtual_method].data [MDATA_PR_VIRTUAL_PULSE] += (damage / 2);
    if (pr->method[pr->virtual_method].data [MDATA_PR_VIRTUAL_PULSE] > VIRTUAL_METHOD_PULSE_MAX)
     pr->method[pr->virtual_method].data [MDATA_PR_VIRTUAL_PULSE] = VIRTUAL_METHOD_PULSE_MAX;
    return;
   }
 }
*/
 if (damage <= 0)
  return;

 pr->hit_pulse_time = w.world_time;

 hurt_proc(pr->index, damage, cause_team);

}