コード例 #1
0
ファイル: res.c プロジェクト: 15ramky/pyretic
struct list_res
res_walk_parents (const struct res *out, const struct hs *hs, int in_port,
		  array_t* out_arr)
{
  struct res *curr_res = (struct res*) out;
  struct list_res currq = {0};

  // set up initial result to start inversion
  struct hs int_hs;
  hs_isect_arr (&int_hs, &out->hs, out_arr);
  list_append (&currq, res_extend (out, &int_hs, out->port, true));

  struct res *cur;

  while (curr_res) {
    if (curr_res->rules.cur) {
      for (int i = curr_res->rules.cur - 1; i >= 0; i--) {
	struct list_res nextq = {0};
	struct res_rule r = curr_res->rules.arr[i];
	while ((cur = currq.head)) {
	  list_pop (&currq);
	  struct list_res tmp = rule_inv_apply (r.tf_tf, r.tf_rule, cur, false);
	  list_concat (&nextq, &tmp);
	  res_free (cur);
	} // for each current result from rule inversion
	currq = nextq;
      } // for each rule
    }
    else return currq;

    // set (hs,port) which the inverted (hs,port) results must intersect
    struct res *parent = curr_res->parent;
    struct hs *next_hs = hs_create (curr_res->hs.len);
    int next_port;
    if (parent) {
      hs_copy (next_hs, &parent->hs);
      next_port = parent->port;
    }
    else {
      hs_copy (next_hs, hs);
      next_port = in_port;
    }

    // Intersect the results in `currq` with the target (hs,port)
    struct list_res nextq = {0};
    while ((cur = currq.head)) {
      list_pop (&currq);
      struct hs *new_hs = hs_isect_a (&cur->hs, next_hs);
      if (cur->port == next_port && new_hs)
	list_append (&nextq, res_extend (cur, new_hs, next_port, false));
      else
	res_free (cur);
    }
    currq = nextq;
    curr_res = parent;
  }

  return currq;
}
コード例 #2
0
ファイル: daemon.c プロジェクト: AltSysrq/libchistka
int main(int argc, char** argv) {
  struct sigaction sig = {};

  /* Ensuring that we are in a separate group and session if possible prevents
   * us from being killed by infantcidal hosts.
   */
  setpgid(0,0);
  setsid();

  unlink_at_exit = argv[1];
  atexit(cleanup);

  event_queue = NULL;
  directories_traversed = hs_create();
  hs_defunct_at(directories_traversed, 65536);
  directories_read = hs_create();
  hs_defunct_at(directories_read, 65536);

  /* If a profile is set, read it if possible, then open for writing. */
  profile_open();

  /* Don't die on SIGIO or SIGALRM */
  sig.sa_handler = signal_ignore;
  sigaction(SIGIO, &sig, NULL);
  sigaction(SIGALRM, &sig, NULL);

  /* Close stdin on SIGTERM, causing the program to exit normally. */
  sig.sa_handler = close_stdin;
  sigaction(SIGTERM, &sig, NULL);

  /* Reconfigure stdin to be ASYNC and NONBLOCK */
  if (-1 == fcntl(STDIN_FILENO, F_SETFL, O_ASYNC|O_NONBLOCK))
    perror("fcntl(F_SETFL,O_ASYNC|O_NONBLOCK)");
  if (-1 == fcntl(STDIN_FILENO, F_SETOWN, getpid()))
    perror("fcntl(F_SETOWN)");

  /* Run until we exit due to an unexpected error or the input stream closes. */
  while (1) {
    read_input();
    run_events();
    pause();
  }

  return 0;
}
コード例 #3
0
ファイル: tf.c プロジェクト: 15ramky/pyretic
static bool
port_append_res (struct list_res *res, const struct rule *r,
		 const struct tf *tf, const struct res *in, int32_t ports,
		 bool append, const struct hs *hs, bool inv_remove_deps)
{
  /* Create new result containing headerspace `hs` for each port in `ports`. */
  bool used_hs = false;
  struct hs *new_hs;
  uint32_t n, x;
  const uint32_t *a;
  if (ports > 0) { n = 1; x = ports; a = &x; }
  else {
    const struct ports *p = PORTS (tf, ports);
    n = p->n; a = p->arr;
  }

  for (int i = 0; i < n; i++) {
    if (a[i] == in->port) continue;

    if (inv_remove_deps) {
      /* For inversion, also remove dependencies for each input port of the
	 inverted rule. */
      new_hs = hs_create (hs->len);
      hs_copy (new_hs, hs);
      if (r->deps) deps_diff_inv (new_hs, a[i], DEPS (tf, r->deps), tf);

      if (!hs_compact_m (new_hs, r->mask ? DATA_ARR (r->mask) : NULL)) { hs_destroy(new_hs); continue; }
    }
    else new_hs = (struct hs*) hs;

    // now *new_hs has the latest hs at this port
    struct res *tmp;
    if (! inv_remove_deps) {
      if (used_hs) tmp = res_extend (in, hs, a[i], append);
      else {
	tmp = res_extend (in, NULL, a[i], append);
	tmp->hs = *hs;
	used_hs = true;
      }
    }
    else {
      tmp = res_extend (in, NULL, a[i], append);
      tmp->hs = *new_hs;
    }
    res_rule_add (tmp, tf, r->idx, r);
    list_append (res, tmp);
  }

  return used_hs;
}
コード例 #4
0
ファイル: hs-test.c プロジェクト: 15ramky/pyretic
void
hs_test (void)
{
  array_t *arr;
  struct hs *a = hs_create (1);
  hs_add (a, array_from_str ("0011xx00"));
  hs_add (a, array_from_str ("10100x0x"));
  arr = array_from_str ("10100x01");
  hs_diff (a, arr);
  hs_print (a);
  struct hs *b = hs_copy_a (a);
  hs_print (b);
  hs_free (b);
  free (arr);

  b = hs_create (1);
  hs_add (b, array_from_str ("xxxx1x00"));
  hs_add (b, array_from_str ("xxxxx1x0"));
  hs_print (b);
  hs_isect (b, a);
  hs_print (b);
  hs_free (b);
  hs_free (a);

  a = hs_create (1);
  hs_add (a, array_from_str ("10xxxxxx"));
  hs_add (a, array_from_str ("xxxxxx10"));
  arr = array_from_str ("11111111");
  hs_diff (a, arr);
  hs_print (a);
  hs_cmpl (a);
  hs_print (a);
  hs_free (a);

  a = hs_create (1);
  hs_add (a, array_from_str ("10xxxxxx"));
  hs_add (a, array_from_str ("xxxxxx10"));
  b = hs_create (1);
  hs_add (b, array_from_str ("11111111"));
  hs_minus (a, b);
  hs_print (a);
  hs_free (a);
  hs_free (b);

  a = hs_create (1);
  hs_add (a, array_from_str ("11111111"));
  //hs_add (a, array_from_str ("xxxxxxx1"));
  hs_diff (a, arr);
  hs_print (a);
  hs_comp_diff (a);
  char *s = hs_to_str (a);
  printf ("S: %s\n", s);
  free (s);
  hs_free (a);
  free (arr);
}
コード例 #5
0
ファイル: clip_HS_CREATE.c プロジェクト: amery/clip-angelo
int
clip_HS_CREATE(ClipMachine * ClipMachineMemory)
{
   const char *__PROC__ = "HS_CREATE";

   const char *fname = _clip_parc(ClipMachineMemory, 1);

   int pagesize = _clip_parni(ClipMachineMemory, 2) * 1024;

   int lcase = _clip_parl(ClipMachineMemory, 4);

   int filtset = _clip_parni(ClipMachineMemory, 5);

   HIPER *hs;

   int er;

   CHECKARG1(1, CHARACTER_type_of_ClipVarType);
   CHECKOPT1(2, NUMERIC_type_of_ClipVarType);
   CHECKOPT1(4, LOGICAL_type_of_ClipVarType);
   CHECKOPT1(5, NUMERIC_type_of_ClipVarType);

   if (_clip_parinfo(ClipMachineMemory, 2) == UNDEF_type_of_ClipVarType)
      pagesize = getpagesize();
   if (_clip_parinfo(ClipMachineMemory, 4) == UNDEF_type_of_ClipVarType)
      lcase = 0;
   if (_clip_parinfo(ClipMachineMemory, 5) == UNDEF_type_of_ClipVarType)
      filtset = 1;

   if ((er = hs_create(ClipMachineMemory, fname, pagesize, lcase, filtset, &hs, __PROC__)))
      goto err;
   hs->map = calloc(1, 4);
   _clip_retni(ClipMachineMemory, _clip_store_c_item(ClipMachineMemory, (void *) hs, _C_ITEM_TYPE_HIPER, destroy_hiper));
   return 0;
 err:
   return er;
}
コード例 #6
0
ファイル: upTree.c プロジェクト: ddsnowboard/JavaProjects
struct upTree* ut_create(size_t array_size) {
    struct upTree* out = malloc(sizeof(struct upTree));
    out->hs = hs_create(array_size);
    return out;
}