Esempio n. 1
0
    void execution_context::report_big_relations(unsigned threshold, std::ostream & out) const {
        unsigned n = register_count();
        svector<std::pair<unsigned, unsigned> > sizes;
        size_t total_bytes = 0;
        for(unsigned i = 0; i < n; i++) {
            unsigned sz = reg(i) ? reg(i)->get_size_estimate_bytes() : 0;
            total_bytes += sz;
            sizes.push_back(std::make_pair(i, sz));
        }
        std::sort(sizes.begin(), sizes.end(), compare_size_proc());        

        out << "bytes " << total_bytes << "\n";
        out << "bytes\trows\tannotation\n";
        for(unsigned i = 0; i < n; i++) {
            unsigned sz = sizes[i].second;
            unsigned rg = sizes[i].first;
            unsigned rows = reg(rg) ? reg(rg)->get_size_estimate_rows() : 0;
            if (sz < threshold) {
                continue;
            }
            std::string annotation;
            get_register_annotation(i, annotation);
            out << sz << "\t" << rows << "\t" << annotation << "\n";
        }
    }
Esempio n. 2
0
void
Init_bit_utils(void)
{
  VALUE rb_mCImpl;
  rb_mBitUtils = rb_define_module("BitUtils");
  rb_mCImpl = rb_define_module_under(rb_mBitUtils, "CImpl");
  register_count(rb_mCImpl);
  register_trailing_zeros(rb_mCImpl);
  register_each_bit(rb_mCImpl);
}
Esempio n. 3
0
SplashOverlay::SplashOverlay(QWidget *parent) :
    QWidget(parent),
    so_ui_(new Ui::SplashOverlay),
    blurred_(false),
    last_action_(RA_NONE),
    register_cur_(0)
{
    so_ui_->setupUi(this);

    // Number of register action transitions (e.g. RA_NONE -> RA_DISSECTORS,
    // RA_DISSECTORS -> RA_PLUGIN_REGISTER) minus two.
    int register_add = 5;
#ifdef HAVE_LUA
      register_add += wslua_count_plugins();   /* get count of lua plugins */
#endif
    so_ui_->progressBar->setMaximum((int)register_count() + register_add);
    elapsed_timer_.start();

    QColor bg = QColor(tango_aluminium_6);
    bg.setAlphaF(0.4);
    QPalette pal;
    pal.setColor(QPalette::Background, bg);
    setPalette(pal);
    setAutoFillBackground(true);

    setStyleSheet(QString(
                      "QLabel {"
                      "  color: white;"
                      "  background: rgba(0,0,0,0);"
                      "}"
                      "QProgressBar {"
                      "  height: 1em;"
                      "  width: 20em;"
                      "  border: 0.1em solid white;"
                      "  border-radius: 0.2em;"
                      "  color: white;"
                      "  background: rgba(0,0,0,0);"
                      "}"
                      "QProgressBar::chunk {"
                      "  width: 0.1em;"
                      "  background: rgba(255, 255, 255, 50%);"
                      "}"
                      ));

#ifndef THROTTLE_STARTUP
    // Check for a remote connection
    if (display_is_remote())
        info_update_freq_ = 1000;
#endif

    connect(wsApp, SIGNAL(splashUpdate(register_action_e,const char*)),
            this, SLOT(splashUpdate(register_action_e,const char*)));
}
Esempio n. 4
0
static void
net_ping_threads (void)
{
  mutex_lock (&_net_thrd_r.mutex);
  p_md_obj ptr = _net_thrd_r.first;
  while (ptr)
    {
      po_thrd thrd = (po_thrd) ptr->ptr;
      mutex_lock (&thrd->mutex);

      if (thrd->status & F_THRD_STATUS_SUSPENDED)
	{
	  if ((register_count (&thrd->in_objects) > (off_t) 0
	      || register_count (&thrd->proc_objects) > (off_t) 0))
	    {
	      pthread_kill (thrd->pt, SIGUSR1);
	      if (gfl & F_OPT_VERBOSE)
		{
		  print_str ("D6: [%X]: waking up worker\n", thrd->pt);

		}
	    }
	}
      else
	{
	  if ((thrd->timers.act_f & F_TTIME_ACT_T0)
	      && (time (NULL) - thrd->timers.t0) > T_THRD_PROC_TIMEOUT)
	    {
	      pthread_kill (thrd->pt, SIGUSR1);
	      print_str ("D2: [%X]: thread not responding\n", thrd->pt);
	    }
	}

      pthread_mutex_unlock (&thrd->mutex);

      ptr = ptr->next;
    }
  pthread_mutex_unlock (&_net_thrd_r.mutex);
}
Esempio n. 5
0
SplashOverlay::SplashOverlay(QWidget *parent) :
    QWidget(parent),
    so_ui_(new Ui::SplashOverlay),
    last_action_(RA_NONE),
    register_cur_(0)
{
    so_ui_->setupUi(this);

    /* additional 6 for:
     * dissectors, listeners,
     * registering plugins, handingoff plugins,
     * preferences and configuration
     */
    int register_add = 6;
#ifdef HAVE_LUA
      register_add++;   /* additional one for lua plugins */
#endif
    so_ui_->progressBar->setMaximum((int)register_count() + register_add);
    time_.start();

    setPalette(Qt::transparent);
    setStyleSheet(QString(
                      "QLabel {"
                      "  color: white;"
                      "  background: rgba(0,0,0,0);"
                      "}"
                      "QProgressBar {"
                      "  height: 1em;"
                      "  width: 20em;"
                      "  border: 0.1em solid white;"
                      "  border-radius: 0.2em;"
                      "  color: white;"
                      "  background: rgba(0,0,0,0);"
                      "}"
                      "QProgressBar::chunk {"
                      "  width: 0.1em;"
                      "  background: rgba(255, 255, 255, 50%);"
                      "}"
                      ));

#ifndef THROTTLE_STARTUP
    // Check for a remote connection
    if (strlen (get_conn_cfilter()) > 0)
        info_update_freq_ = 1000;
#endif

    connect(wsApp, SIGNAL(splashUpdate(register_action_e,const char*)),
            this, SLOT(splashUpdate(register_action_e,const char*)));
}
Esempio n. 6
0
static void
net_def_sig_handler (int signal)
{
  if (!(gfl & F_OPT_KILL_GLOBAL) && register_count (&_sock_r) == 0)
    {
      print_str (
	  "NOTICE: net_def_sig_handler: [%ld]: nothing left to process [%d]\n",
	  syscall (SYS_gettid), signal);
      mutex_lock (&mutex_glob00);
      gfl |= F_OPT_KILL_GLOBAL;
      pthread_mutex_unlock (&mutex_glob00);
    }
  else
    {
      //print_str("D6: net_def_sig_handler: pinging threads..\n");
      //net_ping_threads ();
      //sleep(1000);
    }

  return;
}
Esempio n. 7
0
int
net_deploy (void)
{
  if (((int) net_opts.thread_l + (int) net_opts.thread_r)
      > net_opts.max_worker_threads)
    {
      print_str (
	  "ERROR: net_deploy: requested thread count exceeds 'max_worker_threads' [%d/%d]\n",
	  ((int) net_opts.thread_l + (int) net_opts.thread_r),
	  net_opts.max_worker_threads);
      return -1;
    }

  //_m_tid = getpid();

  /*#ifdef M_ARENA_TEST
   mallopt (M_ARENA_TEST, 1);
   #endif*/
#ifdef M_ARENA_MAX
  mallopt (M_ARENA_MAX, 1);
#endif

  struct sigaction sa_wthrd, sa_mthrd;

  sa_wthrd.sa_handler = sig_handler_null;
  sa_wthrd.sa_flags = SA_RESTART;

  sigfillset (&sa_wthrd.sa_mask);
  //sigaddset(&sa_wthrd.sa_mask, SIGIO);
  //sigaddset(&sa_wthrd.sa_mask, SIGUSR1);

  sigaction (SIGIO, &sa_wthrd, NULL);
  sigaction (SIGURG, &sa_wthrd, NULL);
  sigaction (SIGUSR1, &sa_wthrd, NULL);

  sa_mthrd.sa_handler = net_def_sig_handler;
  sa_mthrd.sa_flags = SA_RESTART;

  sigfillset (&sa_mthrd.sa_mask);
  //sigaddset(&sa_mthrd.sa_mask, SIGUSR2);

  sigaction (SIGUSR2, &sa_mthrd, NULL);

  sigset_t set;

  sigemptyset (&set);
  sigaddset (&set, SIGPIPE);
  sigaddset (&set, SIGURG);
  sigaddset (&set, SIGIO);
  sigaddset (&set, SIGUSR1);
  sigaddset (&set, SIGHUP);

  int sr = pthread_sigmask (SIG_BLOCK, &set, NULL);

  uint32_t in_f = 0;

  if (sr != 0)
    {
      print_str ("ERROR: net_deploy: pthread_sigmask failed: %d\n", sr);
      abort ();
    }

  md_init_le (&_sock_r, (int) net_opts.max_sock);
  md_init_le (&_net_thrd_r, (int) net_opts.max_worker_threads);
  //md_init_le (&_thrd_r_common, 32);
  md_init_le (&tasks_in, MAX_TASKS_GLOBAL);
  md_init_le (&fs_jobs, 1024);

  if (net_opts.flags & F_NETOPT_SSLINIT)
    {
      print_str ("DEBUG: initializing TLS/SSL subsystem..\n");
      ssl_init ();
      in_f |= F_ND_SSL_INIT;
    }

  int r;
  po_thrd task_worker_object;

  if ((r = thread_create (task_worker, 0, NULL, 0, 0,
  F_THRD_NOWPID | F_THRD_NOREG,
			  F_THC_SKIP_IO, NULL, &task_worker_object, NULL)))
    {
      return r;
    }

  if ((r = spawn_threads (net_opts.thread_l, net_worker, 0, &_net_thrd_r,
  THREAD_ROLE_NET_WORKER,
			  SOCKET_OPMODE_LISTENER, 0)))
    {
      print_str ("ERROR: spawn_threads failed [SOCKET_OPMODE_LISTENER]: %d\n",
		 r);
      return 2;
    }
  else
    {
      print_str (
	  "DEBUG: deployed %hu socket worker threads [SOCKET_OPMODE_LISTENER]\n",
	  net_opts.thread_l);
    }

  if ((r = spawn_threads (net_opts.thread_r, net_worker, 0, &_net_thrd_r,
  THREAD_ROLE_NET_WORKER,
			  SOCKET_OPMODE_RECIEVER, 0)))
    {
      print_str ("ERROR: spawn_threads failed [SOCKET_OPMODE_RECIEVER]: %d\n",
		 r);
      return 2;
    }
  else
    {
      print_str (
	  "DEBUG: deployed %hu socket worker threads [SOCKET_OPMODE_RECIEVER]\n",
	  net_opts.thread_r);
    }

  print_str ("DEBUG: waiting for workers to initialize..\n");

  if (net_deploy_wait_for_all_threads (&_net_thrd_r))
    {
      print_str ("D5: all workers online\n");
    }
  else
    {
      goto _t_kill;
    }

  int fail;

  if ((fail = process_ca_requests (&_boot_pca, F_OPSOCK_LISTEN)))
    {
      if ((off_t) fail == _boot_pca.offset)
	{
	  print_str (
	      "WARNING: process_ca_requests: no socket requests succeeded\n");
	  goto _t_kill;
	}
      else
	{
	  print_str (
	      "WARNING: process_ca_requests: not all socket requests were succesfull\n");
	}
    }
  else
    {
      print_str ("DEBUG: deployed %llu listener socket(s)\n",
		 (uint64_t) _boot_pca.offset);
    }

  if (fs_jobs.offset)
    {
      __gfs job = (__gfs ) fs_jobs.first->ptr;

      if (job->id < 1 || job->id > USHRT_MAX)
	{
	  print_str ("ERROR: invalid job id\n");
	  goto _ts_kill;
	}

      if (NULL == job->link || !strlen (job->link))
	{
	  print_str ("ERROR: job [%d] has no path\n", job->id);
	  goto _ts_kill;
	}

      int ret;

      if (!(ret = fs_link_socks_to_job (job, &_sock_r)))
	{
	  print_str ("ERROR: job [%d] defined but no sockets link to it\n",
		     job->id);
	  goto _ts_kill;
	}

      //job->status |= FS_GFS_JOB_LOPEN;

      print_str ("DEBUG: %d sockets linked to job [%d]\n", ret, job->id);

      if ((r = spawn_threads (1, fs_worker, 0, &_net_thrd_r,
      THREAD_ROLE_FS_WORKER,
			      0, 0)))
	{
	  print_str (
	      "ERROR: spawn_threads failed [SOCKET_OPMODE_LISTENER]: %d\n", r);
	  return 2;
	}

      if (!net_deploy_wait_for_all_threads (&_net_thrd_r))
	{
	  print_str ("ERROR: could not spawn fs_worker thread\n");
	  goto _t_kill;
	}
    }

  if (net_opts.flags & F_NETOPT_CHROOT)
    {
      if (chroot (net_opts.chroot) == -1)
	{
	  char err_buf[1024];
	  print_str (
	      "ERROR: netctl_opt_parse: '%s': chroot failed: [%d] [%s]\n",
	      net_opts.chroot,
	      errno,
	      strerror_r (errno, err_buf, sizeof(err_buf)));
	  goto _ts_kill;
	}

      print_str ("NOTICE: chrooted %s\n", net_opts.chroot);
    }

  if (net_opts.flags & F_NETOPT_GID)
    {
      if (setgid (net_opts.gid) == -1)
	{
	  char e_buffer[1024];
	  print_str ("ERROR: setgid failed: %s\n",
		     strerror_r (errno, e_buffer, sizeof(e_buffer)));

	  goto _ts_kill;
	}
      else
	{
	  print_str ("DEBUG: setgid: %u\n", (unsigned int) net_opts.gid);
	}
    }

  if (net_opts.flags & F_NETOPT_UID)
    {
      if (setuid (net_opts.uid) == -1)
	{
	  char e_buffer[1024];
	  print_str ("ERROR: setuid failed: %s\n",
		     strerror_r (errno, e_buffer, sizeof(e_buffer)));

	  goto _ts_kill;
	}
      else
	{
	  print_str ("DEBUG: setuid: %u\n", (unsigned int) net_opts.uid);
	}
    }

  if (net_opts.flags & (F_NETOPT_HUSER | F_NETOPT_HGROUP))
    {
      if (net_opts.flags & F_NETOPT_HUSER)
	{
	  snprintf (G_USER, sizeof(G_USER), "%s", net_opts.user);
	  gfl0 |= F_OPT_SETUID;
	}
      if (net_opts.flags & F_NETOPT_HGROUP)
	{
	  snprintf (G_GROUP, sizeof(G_GROUP), "%s", net_opts.group);
	  gfl0 |= F_OPT_SETGID;
	}

      g_setxid ();
    }

  //htest();

  if ( NULL != ftp_cmd)
    {
      net_ftp_init (ftp_cmd);
    }

  net_pop_rc (NULL, &net_post_init_rc);

  thread_broadcast_sig (&_net_thrd_r, SIGINT);

  if ((fail = process_ca_requests (&_boot_pca, F_OPSOCK_CONNECT)))
    {
      if ((off_t) fail == _boot_pca.offset)
	{
	  print_str (
	      "WARNING: process_ca_requests: no socket requests succeeded\n");
	  goto _t_kill;
	}
      else
	{
	  print_str (
	      "WARNING: process_ca_requests: not all socket requests were succesfull\n");
	}
    }

  while (g_get_gkill ())
    {
      //net_ping_threads();
      sleep (-1);
    }

  _ts_kill: ;

  if (register_count (&_sock_r))
    {
      print_str ("DEBUG: sending F_OPSOCK_TERM to all sockets\n");
      net_nw_ssig_term_r (&_sock_r);
    }

  _t_kill: ;

  print_str ("DEBUG: sending F_THRD_TERM to all worker threads\n");

  thread_broadcast_kill (&_net_thrd_r);

  print_str ("DEBUG: waiting for threads to exit..\n");

  if ((r = thread_join_threads (&_net_thrd_r)))
    {
      print_str ("WARNING: %d threads remaining\n", r);
    }

  thread_send_kill (task_worker_object);

  pthread_join (task_worker_object->pt, NULL);

  md_g_free_l (&_net_thrd_r);
  md_g_free_l (&_sock_r);
  free (pc_a.objects);
  md_g_free_l (&_boot_pca);
  md_g_free_l (&tasks_in);
  md_g_free_l (&fs_jobs);

  if (in_f & F_ND_SSL_INIT)
    {
      print_str ("DEBUG: releasing TLS/SSL resources..\n");
      ssl_cleanup ();
    }

  print_str ("INFO: server shutting down..\n");

  return 0;
}
Esempio n. 8
0
void
splash_update(register_action_e action, const char *message, gpointer client_data)
{
    GtkWidget  *win;
    GtkWidget  *main_lb;
    GtkWidget  *prog_bar;
    GtkWidget  *percentage_lb;
    gfloat     percentage;
    gulong     ul_percentage;
    gchar      tmp[100];
    const char *action_msg;

    static gulong ul_sofar = 0;
    static gulong ul_count = 0;

    static register_action_e last_action = RA_NONE;

    static GTimeVal cur_tv;
    static GTimeVal next_tv = {0, 0};

    win = (GtkWidget *)client_data;

    if (win == NULL) return;

    g_get_current_time(&cur_tv);
    if (last_action == action && cur_tv.tv_sec <= next_tv.tv_sec && cur_tv.tv_usec <= next_tv.tv_usec && ul_sofar < ul_count - 1) {
      /* Only update every splash_register_freq milliseconds */
      ul_sofar++;
      return;
    }
    memcpy(&next_tv, &cur_tv, sizeof(next_tv));
    next_tv.tv_usec += info_update_freq * 1000;
    if (next_tv.tv_usec >= 1000000) {
        next_tv.tv_sec++;
        next_tv.tv_usec -= 1000000;
    }

    if(last_action != action) {
      /* the action has changed */
      switch(action) {
      case RA_DISSECTORS:
	action_msg = "Initializing dissectors ...";
	break;
      case RA_LISTENERS:
	action_msg = "Initializing tap listeners ...";
	break;
      case RA_REGISTER:
	action_msg = "Registering dissector ...";
	break;
      case RA_PLUGIN_REGISTER:
	action_msg = "Registering plugins ...";
	break;
      case RA_PYTHON_REGISTER:
	action_msg = "Registering Python dissectors ...";
	break;
      case RA_HANDOFF:
	action_msg = "Handing off dissector ...";
	break;
      case RA_PLUGIN_HANDOFF:
	action_msg = "Handing off plugins ...";
	break;
      case RA_PYTHON_HANDOFF:
	action_msg = "Handing off Python dissectors ...";
	break;
      case RA_LUA_PLUGINS:
	action_msg = "Loading Lua plugins ...";
	break;
      case RA_PREFERENCES:
	action_msg = "Loading module preferences ...";
	break;
      case RA_CONFIGURATION:
	action_msg = "Loading configuration files ...";
	break;
      default:
	action_msg = "(Unknown action)";;
	break;
      }
      splash_update_label(win, action_msg);
      last_action = action;
    }

    if(ul_count == 0) { /* get the count of dissectors */
      ul_count = register_count() + 6; /* additional 6 for:
					  dissectors, listeners,
					  registering plugins, handingoff plugins,
					  preferences and configuration */
#ifdef HAVE_LUA_5_1
      ul_count++;   /* additional one for lua plugins */
#endif
#ifdef HAVE_PYTHON
      ul_count += 2;   /* additional 2 for python register and handoff */
#endif
    }

    main_lb = g_object_get_data(G_OBJECT(win), "protocol_label");
    /* make_dissector_reg.py changed -
       so we need to strip off the leading elements to get back to the protocol */
    if(message) {
      if(!strncmp(message, "proto_register_", 15))
	message += 15;
      else if(!strncmp(message, "proto_reg_handoff_", 18))
	message += 18;
    }
    gtk_label_set_text(GTK_LABEL(main_lb), message ? message : "");

    ul_sofar++;

    g_assert (ul_sofar <= ul_count);

    percentage = (gfloat)ul_sofar/(gfloat)ul_count;
    ul_percentage = (gulong)(percentage * 100);

    /* update progress bar */
    prog_bar = g_object_get_data(G_OBJECT(win), "progress_bar");
    gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(prog_bar), percentage);

    percentage_lb = g_object_get_data(G_OBJECT(win), "percentage_label");
    g_snprintf(tmp, sizeof(tmp), "%lu%%", ul_percentage);
    gtk_label_set_text((GtkLabel*)percentage_lb, tmp);

    /* Process all pending GUI events before continuing, so that
       the splash screen window gets updated. */
    while (gtk_events_pending()) gtk_main_iteration();

}