Beispiel #1
0
int		main(int argc, char **argv)
{
	t_env	*e;
	t_objs	*obj;

	if (argc == 2)
	{
		e = (t_env *)malloc(sizeof(t_env));
		obj = (t_objs *)malloc(sizeof(t_objs));
		if (!e || !obj)
			ft_error("Malloc error", 2);
		if (!(init_env(e)))
			return (0);
		if (!extension(argv[1]))
			ft_error("File need .rt extension", 2);
		if (!(obj = parsing(argv[1], e, obj)))
			ft_error("Parsing error", 2);
		obj = manage_data(e, obj);
		e->begin_list = obj;
		mlx_expose_hook(e->win, expose_hook, e);
		mlx_key_hook(e->win, key_events, e);
		mlx_loop(e->mlx);
	}
	return (0);
}
int main(int argc, char *argv[]) {

  char error[256];
  int capture = 1;
  time_t last_refresh_t;
  scap_t *h ;
  //apro la cattura live degli eventi
  
  
  read_argv(argc, argv);

  if(global_data.export_elk)
    init_connection_socket();

  if(global_data.show_help_enabled){
    print_help();
    return(1);
  }
  printf("\n\t\t INIZIO INIZIALIZZAZIONE \n");
  if( ( h = scap_open_live(error)) == NULL){
    printf("Unable to connect to open sysdig: %s\n", error);
    return(false);
    }


  //setto i filtri per gli eventi da catturare solo se la cattura è live
    scap_clear_eventmask(h);
    if(scap_set_eventmask(h, PPME_CLONE_16_X) != SCAP_SUCCESS)
      printf("[ERROR] scap call failed: old driver ?\n");
    if(scap_set_eventmask(h, PPME_PROCEXIT_E) != SCAP_SUCCESS)
      printf("[ERROR] scap call failed: old driver ?\n");
    if(scap_set_eventmask(h, PPM_SC_EXIT_GROUP) != SCAP_SUCCESS)
      printf("[ERROR] scap call failed: old driver ?\n");
    if(scap_set_eventmask(h, PPM_SC_EXIT) != SCAP_SUCCESS)
      printf("[ERROR] scap call failed: old driver ?\n");

  if(global_data.get_all_proc)
    init_add_active_proc(h);

  printf("\n\t\t FINE INIZIALIZZAZIONE \n");
  //ciclo di cattura
  last_refresh_t = time(NULL);
  while(capture)
    {	
      struct ppm_evt_hdr* ev;
      u_int16_t cpuid;
      int32_t res = scap_next(h, &ev, &cpuid);

      if(res > 0 ) {
	printf("[ERROR] %s\n", scap_getlasterr(h));
	scap_close(h);
	break;
      } else if( res == SCAP_SUCCESS ) {
	handle_event(ev,cpuid,h);
      } else if( res != -1 ) 	//timeout
	fprintf(stderr, "scap_next() returned %d\n", res);
      /*si aggiornano i dati ogni refresh_t secondi (5 default)
	(XXX numero da regolare) */
      if( (time(NULL) - last_refresh_t) > global_data.refresh_t){
        manage_data(h);
	last_refresh_t = time(NULL);
      }
    }
  //chiudo la cattura live degli eventi
  close(global_data.socket_desc);
  scap_close(h);
}