Пример #1
0
/* _unix_watch_file(): initialize file
*/
static void
_unix_watch_file(u3_ufil* fil_u, u3_udir* par_u, c3_c* pax_c)
{
    // initialize fil_u

    fil_u->dir = c3n;
    fil_u->dry = c3n;
    fil_u->pax_c = pax_c;
    fil_u->par_u = par_u;
    fil_u->nex_u = NULL;
    fil_u->mug_w = 0;
    fil_u->gum_w = 0;

    if ( par_u ) {
        fil_u->nex_u = par_u->kid_u;
        par_u->kid_u = (u3_unod*) fil_u;
    }

    // stuff fil_u into libuv
    // note that we're doing something tricky here
    // see comment in _unix_fs_event_cb

    c3_w ret_w = uv_fs_event_init(u3L, &fil_u->was_u);
    if (0 != ret_w) {
        uL(fprintf(uH, "file event init: %s\n", uv_strerror(ret_w)));
        c3_assert(0);
    }

    ret_w = uv_fs_event_start(&fil_u->was_u, _unix_fs_event_cb, pax_c, 0);
    if ( 0 != ret_w ) {
        uL(fprintf(uH, "file event start %s: %s\n", fil_u->pax_c, uv_strerror(ret_w)));
        c3_assert(0);
    }
}
Пример #2
0
  u2_weak                                                         //  transfer
  j2_mci(Pt6, ut, tack)(u2_wire wir_r,
                        u2_noun van,                              //  retain
                        u2_noun sut,                              //  retain
                        u2_noun peh,                              //  retain
                        u2_noun mur)                              //  retain
  {
    u2_weak hoc = u2_ds_look(wir_r, van, "tack");

    if ( u2_none == hoc ) {
      c3_assert(!"register tack");
      return u2_none;
    } else {
      u2_weak von = u2_rl_molt(wir_r, van, u2_cv_sam, u2_rx(wir_r, sut), 0);
      u2_weak gat = u2_nk_soft(wir_r, von, hoc);
      u2_weak cor = u2_rl_molt(wir_r, gat, u2_cv_sam_2, u2_rx(wir_r, peh), 
                                           u2_cv_sam_3, u2_rx(wir_r, mur),
                                           0);

      if ( (u2_none == j2_mcj(Pt6, ut, tack)[0].xip) ) {
        u2_noun xip = u2_ds_find(wir_r, cor);
     
        c3_assert(u2_none != xip);
        j2_mcj(Pt6, ut, tack)[0].xip = xip;
      }
      u2_rl_lose(wir_r, gat);
      return cor;
    }
  }
Пример #3
0
/* u2_cn_mink(): logical virtual nock.
*/
u2_noun
u2_cn_mink(u2_noun bus,
           u2_noun fol,
           u2_noun fly)
{
  u2_noun res;
  u2_bean bit;

  bit = u2_tx_sys_bit(u2_Wire, u2_no);
  c3_assert(bit == u2_yes);
  bit = u2_tx_glu_bit(u2_Wire, u2_yes);

  {
    u2_noun lad;

    lad = u2_hevn_at(lad);
    u2_hevn_at(lad) = u2nc(fly, u2k(lad));
    {
      res = _nock_moog(bus, fol);
    }
    c3_assert(lad == u2ft(u2_hevn_at(lad)));

    u2z(u2_hevn_at(lad));
    u2_hevn_at(lad) = lad;
  }

  u2_tx_sys_bit(u2_Wire, u2_yes);
  u2_tx_glu_bit(u2_Wire, bit);

  return res;
}
Пример #4
0
Файл: muk.c Проект: bd/urbit
/* functions
*/
  u3_noun
  u3qc_muk(u3_atom seed,
           u3_atom len,
           u3_atom key)
  {
    c3_w seed_w;
    c3_w len_w;
    c3_y *key_y;
    c3_w out_w;

    c3_assert(u3r_met(5, seed) <= 1);
    c3_assert(u3r_met(0, len)  <= 31);
    c3_assert(u3r_met(3, key)  <= len);

    seed_w = u3r_word(0, seed);
    len_w  = u3r_word(0, len);
    if (len_w > 0) { /* can't u3a_calloc 0 bytes */
      key_y  = u3a_calloc(sizeof(c3_y), len);
    } else {
      key_y = 0;
    }
    u3r_bytes(0, len, key_y, key);

    MurmurHash3_x86_32(key_y, len, seed_w, &out_w);

    u3a_free(key_y);
    return u3i_words(1, &out_w);
  }
Пример #5
0
/* u2_term_io_loja(): release console from fprintf.
*/
void
u2_term_io_loja(int x)
{
  u2_utty* uty_u = _term_main();

  if ( uty_u ) {
    if ( uty_u->fid_i > 2 ) {
      //  We *should* in fact, produce some kind of fake FILE* for
      //  non-console terminals.  If we use this interface enough...
      //
      c3_assert(0);
    }
    else {
      if ( u2_yes == u2_Host.ops_u.dem ) {
        fflush(stdout);
      }
      else {
        if ( 0 != tcsetattr(1, TCSADRAIN, &uty_u->raw_u) ) {
          c3_assert(!"loja-tcsetattr");
        }
        if ( -1 == fcntl(1, F_SETFL, uty_u->nob_i) ) {
          c3_assert(!"loja-fcntl");
        }
        if ( 0 != tcsetattr(0, TCSADRAIN, &uty_u->raw_u) ) {
          c3_assert(!"loja-tcsetattr");
        }
        if ( -1 == fcntl(0, F_SETFL, uty_u->nob_i) ) {
          c3_assert(!"loja-fcntl");
        }
        _term_it_refresh_line(uty_u);
      }
    }
  }
}
Пример #6
0
/* unix_load(): load a file.
*/
static u2_noun
_unix_load(c3_c* pax_c)
{
  struct stat buf_u;
  c3_i        fid_i = open(pax_c, O_RDONLY, 0644);
  c3_w        fln_w, red_w;
  c3_y*       pad_y;

  if ( (fid_i < 0) || (fstat(fid_i, &buf_u) < 0) ) {
    // uL(fprintf(uH, "%s: %s\n", pax_c, strerror(errno)));
    c3_assert(0); 
    return 0;
  }
  fln_w = buf_u.st_size;
  pad_y = malloc(buf_u.st_size);

  red_w = read(fid_i, pad_y, fln_w);
  close(fid_i);

  if ( fln_w != red_w ) {
    free(pad_y);
    c3_assert(0);
    return 0;
  }
  else {
    u2_noun pad = u2_ci_bytes(fln_w, (c3_y *)pad_y); 
    free(pad_y);

    return pad;
  }
}
Пример #7
0
/* _http_message_complete(): jhttp callback
*/
static c3_i
_http_message_complete(http_parser* par_u)
{
  u3_hreq* req_u = par_u->data;
  u3_hcon* hon_u = req_u->hon_u;

  c3_assert(req_u == hon_u->ruc_u);
  hon_u->ruc_u = 0;
  // _http_req_dump(req_u);

  // Queue request for response control.
  {
    if ( !hon_u->qer_u ) {
      c3_assert(!(hon_u->req_u));

      hon_u->qer_u = hon_u->req_u = req_u;
    }
    else {
      hon_u->qer_u->nex_u = req_u;
    }
  }

  // Dispatch event request.
  //
  _http_request(req_u);
  return 0;
}
Пример #8
0
/* _box_attach(): attach a box to the free list.
*/
void
_box_attach(u3a_box* box_u)
{
  c3_assert(box_u->siz_w >= (1 + c3_wiseof(u3a_fbox)));
  c3_assert(0 != u3of(u3a_fbox, box_u));

#if 0
  //  For debugging, fill the box with beef.
  {
    c3_w* box_w = (void *)box_u;
    c3_w  i_w;

    for ( i_w = c3_wiseof(u3a_box); (i_w + 1) < box_u->siz_w; i_w++ ) {
      box_w[i_w] = 0xdeadbeef;
    }
  }
#endif

  u3R->all.fre_w += box_u->siz_w;
  {
    c3_w             sel_w = _box_slot(box_u->siz_w);
    u3p(u3a_fbox)  fre_p = u3of(u3a_fbox, box_u);
    u3p(u3a_fbox)* pfr_p = &u3R->all.fre_p[sel_w];
    u3p(u3a_fbox)  nex_p = *pfr_p;

    u3to(u3a_fbox, fre_p)->pre_p = 0;
    u3to(u3a_fbox, fre_p)->nex_p = nex_p;
    if ( u3to(u3a_fbox, fre_p)->nex_p ) {
      u3to(u3a_fbox, u3to(u3a_fbox, fre_p)->nex_p)->pre_p = fre_p;
    }
    (*pfr_p) = fre_p;
  }
}
Пример #9
0
Файл: sist.c Проект: wrmsr/urbit
/* u3_sist_put(): moronic key-value store put.
*/
void
u3_sist_put(const c3_c* key_c, const c3_y* val_y, size_t siz_i)
{
  c3_c ful_c[2048];
  c3_i ret_i;
  c3_i fid_i;

  ret_i = snprintf(ful_c, 2048, "%s/.urb/sis/_%s", u3_Host.dir_c, key_c);
  c3_assert(ret_i < 2048);

  if ( (fid_i = open(ful_c, O_CREAT | O_TRUNC | O_WRONLY, 0600)) < 0 ) {
    uL(fprintf(uH, "sist: could not put %s\n", key_c));
    perror("open");
    u3_lo_bail();
  }
  if ( (ret_i = write(fid_i, val_y, siz_i)) != siz_i ) {
    uL(fprintf(uH, "sist: could not write %s\n", key_c));
    if ( ret_i < 0 ) {
      perror("write");
    }
    u3_lo_bail();
  }
  ret_i = c3_sync(fid_i);
  if ( ret_i < 0 ) {
    perror("sync");
  }
  ret_i = close(fid_i);
  c3_assert(0 == ret_i);
}
Пример #10
0
Файл: sist.c Проект: wrmsr/urbit
/* u3_sist_get(): moronic key-value store get.
*/
void
u3_sist_get(const c3_c* key_c, c3_y* val_y)
{
  c3_c        ful_c[2048];
  c3_i        ret_i;
  c3_i        fid_i;
  struct stat sat_u;

  ret_i = snprintf(ful_c, 2048, "%s/.urb/sis/_%s", u3_Host.dir_c, key_c);
  c3_assert(ret_i < 2048);

  if ( (fid_i = open(ful_c, O_RDONLY)) < 0 ) {
    uL(fprintf(uH, "sist: could not get %s\n", key_c));
    perror("open");
    u3_lo_bail();
  }
  if ( (ret_i = fstat(fid_i, &sat_u)) < 0 ) {
    uL(fprintf(uH, "sist: could not stat %s\n", key_c));
    perror("fstat");
    u3_lo_bail();
  }
  if ( (ret_i = read(fid_i, val_y, sat_u.st_size)) != sat_u.st_size ) {
    uL(fprintf(uH, "sist: could not read %s\n", key_c));
    if ( ret_i < 0 ) {
      perror("read");
    }
    u3_lo_bail();
  }
  ret_i = close(fid_i);
  c3_assert(0 == ret_i);
}
Пример #11
0
Файл: sist.c Проект: wrmsr/urbit
/* u3_sist_has(): moronic key-value store existence check.
*/
ssize_t
u3_sist_has(const c3_c* key_c)
{
  c3_c        ful_c[2048];
  c3_i        ret_i;
  struct stat sat_u;

  ret_i = snprintf(ful_c, 2048, "%s/.urb/sis/_%s", u3_Host.dir_c, key_c);
  c3_assert(ret_i < 2048);

  if ( (ret_i = stat(ful_c, &sat_u)) < 0 ) {
    if ( errno == ENOENT ) {
      return -1;
    }
    else {
      uL(fprintf(uH, "sist: could not stat %s\n", key_c));
      perror("stat");
      u3_lo_bail();
    }
  }
  else {
    return sat_u.st_size;
  }
  c3_assert(!"not reached");
}
Пример #12
0
/* u2_term_io_hija(): hijack console for fprintf, returning FILE*.
*/
FILE*
u2_term_io_hija(void)
{
  u2_utty* uty_u = _term_main();

  if ( uty_u ) {
    if ( uty_u->fid_i > 2 ) {
      //  We *should* in fact, produce some kind of fake FILE* for
      //  non-console terminals.  If we use this interface enough...
      //
      c3_assert(0);
    }
    else {
      if ( u2_no == u2_Host.ops_u.dem ) {
        if ( 0 != tcsetattr(1, TCSADRAIN, &uty_u->bak_u) ) {
          c3_assert(!"hija-tcsetattr");
        }
        if ( -1 == fcntl(1, F_SETFL, uty_u->cug_i) ) {
          c3_assert(!"hija-fcntl");
        }
        if ( 0 != tcsetattr(0, TCSADRAIN, &uty_u->bak_u) ) {
          c3_assert(!"hija-tcsetattr");
        }
        if ( -1 == fcntl(0, F_SETFL, uty_u->cug_i) ) {
          c3_assert(!"hija-fcntl");
        }
        write(uty_u->fid_i, "\r", 1);
        write(uty_u->fid_i, uty_u->ufo_u.out.el_y,
                            strlen((c3_c*) uty_u->ufo_u.out.el_y));
      }
      return stdout;
    }
  }
  else return stdout;
}
Пример #13
0
  u2_weak                                                         //  transfer
  j2_mci(Pt6, ut, bust)(u2_wire wir_r,
                        u2_noun van,                              //  retain
                        u2_noun sut,                              //  retain 
                        u2_noun dib)                              //  retain
  {
    u2_weak hoc = u2_ds_look(wir_r, van, "bust");

    if ( u2_none == hoc ) {
      c3_assert(!"register bust");
      return u2_none;
    } else {
      u2_weak von = u2_rl_molt(wir_r, van, u2_cw_sam, u2_rx(wir_r, sut), 0);
      u2_weak gat = u2_nk_soft(wir_r, von, hoc);
      u2_weak cor = u2_rl_molt(wir_r, gat, u2_cw_sam, u2_rx(wir_r, dib), 0);

      if ( (u2_none == j2_mcj(Pt6, ut, bust)[0].xip) ) {
        u2_noun xip = u2_ds_find(wir_r, cor);
     
        c3_assert(u2_none != xip);
        j2_mcj(Pt6, ut, bust)[0].xip = xip;
      }
      u2_rl_lose(wir_r, gat);
      return cor;
    }
  }
Пример #14
0
/* _unix_watch_dir(): initialize directory
*/
static void
_unix_watch_dir(u3_udir* dir_u, u3_udir* par_u, c3_c* pax_c)
{
    // initialize dir_u

    dir_u->dir = c3y;
    dir_u->dry = c3n;
    dir_u->pax_c = pax_c;
    dir_u->par_u = par_u;
    dir_u->nex_u = NULL;
    dir_u->kid_u = NULL;

    if ( par_u ) {
        dir_u->nex_u = par_u->kid_u;
        par_u->kid_u = (u3_unod*) dir_u;
    }

    // stuff dir_u into libuv
    // note that we're doing something tricky here
    // see comment in _unix_fs_event_cb

    c3_w ret_w = uv_fs_event_init(u3L, &dir_u->was_u);
    if (0 != ret_w) {
        uL(fprintf(uH, "directory event init: %s\n", uv_strerror(ret_w)));
        c3_assert(0);
    }

    ret_w = uv_fs_event_start(&dir_u->was_u, _unix_fs_event_cb, pax_c, 0);
    if (0 != ret_w) {
        uL(fprintf(uH, "directory event start: %s\n", uv_strerror(ret_w)));
        c3_assert(0);
    }
}
Пример #15
0
  u2_weak                                                         //  transfer
  j2_mci(Pt6, ut, fink)(u2_wire wir_r,
                        u2_noun van,                              //  retain
                        u2_noun sut,                              //  retain 
                        u2_noun dep,                              //  retain
                        u2_noun way,                              //  retain
                        u2_noun cog)                              //  retain
  {
    u2_weak hoc = u2_ds_look(wir_r, van, "fink");

    if ( u2_none == hoc ) {
      c3_assert(!"register fink");
      return u2_none;
    } else {
      u2_weak von = u2_rl_molt(wir_r, van, u2_cv_sam, u2_rx(wir_r, sut), 0);
      u2_weak gat = u2_nk_soft(wir_r, von, hoc);
      u2_weak cor = u2_rl_molt(wir_r, gat, 
                                      u2_cv_sam_2, u2_rx(wir_r, dep), 
                                      u2_cv_sam_6, u2_rx(wir_r, way), 
                                      u2_cv_sam_7, u2_rx(wir_r, cog), 
                                      0);

      if ( (u2_none == j2_mcj(Pt6, ut, fink)[0].xip) ) {
        u2_noun xip = u2_ds_find(wir_r, cor);
     
        c3_assert(u2_none != xip);
        j2_mcj(Pt6, ut, fink)[0].xip = xip;
      }
      u2_rl_lose(wir_r, gat);
      return cor;
    }
  }
  u2_bean
  j2_mci(Pt6, ut, park)(u2_wire wir_r,
                        u2_noun van,                              //  retain
                        u2_noun sut,                              //  retain
                        u2_noun way,                              //  retain
                        u2_noun axe)                              //  retain
  {
    u2_weak hoc = u2_ds_look(wir_r, van, "park");

    if ( u2_none == hoc ) {
      c3_assert(!"register park");
      return u2_none;
    } else {
      u2_weak von = u2_rl_molt(wir_r, van, u2_cv_sam, u2_rx(wir_r, sut), 0);
      u2_weak gat = u2_nk_soft(wir_r, von, hoc);
      u2_weak cor = u2_rl_molt(wir_r, gat,
                                      u2_cv_sam_2, u2_rx(wir_r, way),
                                      u2_cv_sam_3, u2_rx(wir_r, axe),
                                      0);

      if ( (u2_none == j2_mcj(Pt6, ut, park)[0].xip) ) {
        u2_noun xip = u2_ds_find(wir_r, cor);

        c3_assert(u2_none != xip);
        j2_mcj(Pt6, ut, park)[0].xip = xip;
      }
      u2_rl_lose(wir_r, gat);
      return cor;
    }
  }
Пример #17
0
  u2_weak                                                         //  produce
  j2_mci(Pt6, ut, mint)(u2_wire wir_r,
                        u2_noun van,                              //  retain
                        u2_noun sut,                              //  retain 
                        u2_noun gol,                              //  retain
                        u2_noun gen)                              //  retain
  {
    u2_weak hoc = u2_ds_look(wir_r, van, "mint");

    if ( u2_none == hoc ) {
      c3_assert(!"register mint");
      return u2_none;
    } else {
      u2_weak von = u2_rl_molt(wir_r, van, u2_cw_sam, u2_rx(wir_r, sut), 0);
      u2_weak gat = u2_nk_soft(wir_r, von, hoc);
      u2_weak cor = u2_rl_molt(wir_r, gat, 
                                      u2_cw_sam_2, u2_rx(wir_r, gol), 
                                      u2_cw_sam_3, u2_rx(wir_r, gen), 
                                      0);

      if ( (u2_none == j2_mcj(Pt6, ut, mint)[0].xip) ) {
        u2_noun xip = u2_ds_find(wir_r, cor);
     
        c3_assert(u2_none != xip);
        j2_mcj(Pt6, ut, mint)[0].xip = xip;
      }
      u2_rl_lose(wir_r, gat);
      return cor;
    }
  }
Пример #18
0
Файл: unix.c Проект: esaul/urbit
/* _unix_dir_watch(): instantiate directory tracker.
*/
static void
_unix_dir_watch(u2_udir* dir_u, u2_udir* par_u, c3_c* pax_c)
{
  // (1) build data structure
  //
  dir_u->yes = u2_yes;
  dir_u->dry = u2_no;
  dir_u->pax_c = pax_c;
  dir_u->par_u = par_u;
  dir_u->dis_u = 0;
  dir_u->fil_u = 0;
  dir_u->nex_u = 0;


  // (2) stuff data structure into libuv
  //
  c3_w ret_w = uv_fs_event_init(u2L, &dir_u->was_u );
  if (0 != ret_w){
    uL(fprintf(uH, "event init: %s\n", uv_strerror(ret_w)));
    c3_assert(0);
  }

  // note that we're doing something tricky here; see comment in _unix_fs_event_cb
  //
  ret_w = uv_fs_event_start(&dir_u->was_u,
                           _unix_fs_event_cb,
                           pax_c,
                           0);
  if (0 != ret_w){
    uL(fprintf(uH, "event start: %s\n", uv_strerror(ret_w)));
    c3_assert(0);
  }

}
Пример #19
0
  u2_weak                                                         //  transfer
  j2_mci(Pt6, ut, cull)(u2_wire wir_r,
                        u2_noun van,                              //  retain
                        u2_noun sut,                              //  retain 
                        u2_flag pol,                              //  retain
                        u2_atom axe,                              //  retain
                        u2_noun ref)                              //  retain
  {
    u2_weak hoc = u2_ds_look(wir_r, van, "cull");

    if ( u2_none == hoc ) {
      c3_assert(!"register cull");
      return u2_none;
    } else {
      u2_weak von = u2_rl_molt(wir_r, van, u2_cw_sam, u2_rx(wir_r, sut), 0);
      u2_weak gat = u2_nk_soft(wir_r, von, hoc);
      u2_weak cor = u2_rl_molt(wir_r, gat, 
                                      u2_cw_sam_2, pol,
                                      u2_cw_sam_6, u2_rx(wir_r, axe), 
                                      u2_cw_sam_7, u2_rx(wir_r, ref), 
                                      0);

      if ( (u2_none == j2_mcj(Pt6, ut, cull)[0].xip) ) {
        u2_noun xip = u2_ds_find(wir_r, cor);
     
        c3_assert(u2_none != xip);
        j2_mcj(Pt6, ut, cull)[0].xip = xip;
      }
      u2_rl_lose(wir_r, gat);
      return cor;
    }
  }
Пример #20
0
/* u2_unix_acquire(): acquire a lockfile, killing anything that holds it.
*/
void
u2_unix_acquire(c3_c* pax_c)
{
  c3_c* paf_c = _unix_down(pax_c, ".vere.lock");
  c3_w pid_w;
  FILE* loq_u;

  if ( NULL != (loq_u = fopen(paf_c, "r")) ) {
    if ( 1 != fscanf(loq_u, "%u", &pid_w) ) {
      uL(fprintf(uH, "lockfile %s is corrupt!\n", paf_c));
      kill(getpid(), SIGTERM);
      sleep(1); c3_assert(0);
    }
    else {
      c3_w i_w;

      if ( -1 != kill(pid_w, SIGTERM) ) {
        uL(fprintf(uH, "unix: stopping process %d, live in %s...\n", 
                        pid_w, pax_c));

        for ( i_w = 0; i_w < 16; i_w++ ) {
          sleep(1);
          if ( -1 == kill(pid_w, SIGTERM) ) {
            break;
          }
        }
        if ( 16 == i_w ) {
          for ( i_w = 0; i_w < 16; i_w++ ) {
            if ( -1 == kill(pid_w, SIGKILL) ) {
              break;
            }
            sleep(1);
          }
        }
        if ( 16 == i_w ) {
          uL(fprintf(uH, "process %d seems unkillable!\n", pid_w));
          c3_assert(0);
        }
      }
      uL(fprintf(uH, "unix: stopped old process %u\n", pid_w));
    }
    fclose(loq_u);
    unlink(paf_c);
  }

  loq_u = fopen(paf_c, "w");
  fprintf(loq_u, "%u\n", getpid());

  {
    c3_i fid_i = fileno(loq_u);
#if defined(U2_OS_linux)
    fdatasync(fid_i);
#else
    fcntl(fid_i, F_FULLFSYNC); 
#endif
  }
  fclose(loq_u);
}
Пример #21
0
/* _unix_sync_change(): sync single change to unix
*/
static void
_unix_sync_change(u3_udir* dir_u, u3_noun pax, u3_noun mim)
{
    c3_assert( c3y == dir_u->dir );

    if ( c3n == u3du(pax) ) {
        if ( u3_nul == pax ) {
            uL(fprintf(uH,"can't sync out file as top-level, strange\r\n"));
        }
        else {
            uL(fprintf(uH,"sync out: bad path\r\n"));
        }
        u3z(pax);
        u3z(mim);
        return;
    }
    else if ( c3n == u3du(u3t(pax)) ) {
        uL(fprintf(uH,"can't sync out file as top-level, strangely\r\n"));
        u3z(pax);
        u3z(mim);
    }
    else {
        u3_noun i_pax = u3h(pax);
        u3_noun t_pax = u3t(pax);
        u3_noun it_pax = u3h(t_pax);
        u3_noun tt_pax = u3t(t_pax);

        if ( u3_nul == tt_pax ) {
            _unix_sync_file(dir_u, u3k(i_pax), u3k(it_pax), mim);
        }
        else {
            c3_c* nam_c = u3r_string(i_pax);
            c3_w pax_w = strlen(dir_u->pax_c);
            u3_unod* nod_u;

            for ( nod_u = dir_u->kid_u;
                    ( nod_u &&
                      ( c3n == nod_u->dir ||
                        0 != strcmp(nod_u->pax_c + pax_w + 1, nam_c) ) );
                    nod_u = nod_u->nex_u )
            { }

            if ( !nod_u ) {
                nod_u = c3_malloc(sizeof(u3_udir));
                _unix_create_dir((u3_udir*) nod_u, dir_u, u3k(i_pax));
            }

            if ( c3n == nod_u->dir ) {
                uL(fprintf(uH,
                           "weird, we got a file when we weren't expecting to\r\n"));
                c3_assert(0);
            }

            _unix_sync_change((u3_udir*) nod_u, u3k(t_pax), mim);
        }
    }
    u3z(pax);
}
Пример #22
0
/* u2_sh_look():
**
**   Produce hook formula from core, or u2_none.
*/
u2_weak
u2_sh_look(u2_wire     wir_r,
           u2_noun     cor,
           const c3_c* tam_c)
{
  u2_ray  bas_r = u2_wire_bas_r(wir_r); 
  u2_noun bat   = u2_t(cor);
  u2_noun fol;

  if ( u2_none != (fol = u2_ch_find_mixt(u2_bask_hag_r(bas_r), tam_c, bat)) ) {
    return fol;
  } else {
    u2_noun xip = u2_sh_find(wir_r, cor);

    if ( u2_none == xip ) {
      return u2_none;
    } 
    else {
      u2_axis axe_w = _1;

      while ( 1 ) {
        fol = u2_sh_cook(wir_r, xip, tam_c);

        if ( u2_none == fol ) {
          u2_noun pet = u2_t(u2_t(xip));

          if ( _0 == pet ) {
            return u2_none;
          }
          else {
            u2_axis pax = u2_h(pet);

            c3_assert(u2_fly_is_cat(pax));
            c3_assert((u2_ax_dep(axe_w) + u2_ax_dep(pax)) <= 30);

            axe_w = u2_ax_peg(axe_w, pax);
            xip = u2_t(pet);
            continue;
          }
        }
        else {
          fol = u2_rl_take(bas_r, fol);

          if ( _1 != axe_w ) {
            /* XX: suboptimal; use comb:lily.
            */
            fol = u2_rt(bas_r, u2_nock_flac,
                               u2_rc(bas_r, u2_nock_frag, axe_w),
                               fol);
          }
          fol = u2_ch_save_mixt(bas_r, u2_bask_hag_r(bas_r), tam_c, bat, fol);

          return fol;
        }
      }
    }
  }
}
Пример #23
0
static void
_raft_rnam_free(u2_rnam* nam_u)
{
  if ( nam_u ) {
    c3_assert(0 == nam_u->ron_u);
    c3_assert(0 == nam_u->nex_u);
    free(nam_u->str_c);
    free(nam_u->nam_c);
    free(nam_u->por_c);
  }
  free(nam_u);
}
Пример #24
0
/* _nock_pray_mool(): load from namespace, in virtual mode.
*/
static u2_noun
_nock_pray_mool(u2_noun gof, u2_kode *pon)                        //  transfer
{
    u2_noun lad = u2_hevn_at(lad);

    c3_assert(u2_yes == u2du(lad));
    c3_assert(0 == *pon);
    {
        u2_noun i_lad = u2fh(lad);
        u2_noun t_lad = u2ft(lad);
        u2_noun pro;
        u2_noun hoe;

        u2_hevn_at(lad) = t_lad;
        if ( 0 != (hoe = u2_cm_trap()) ) {
            u2_cm_done();

            return u2_cm_bail(u2k(u2h(hoe)));
        }
        else {
            if ( u2_nul == t_lad ) {
                pro = u2_cn_mung(u2k(i_lad), u2k(gof));
            } else {
                pro = _nock_molg(u2k(i_lad), u2k(gof), pon);
            }
            u2_cm_done();

            c3_assert(t_lad == u2_hevn_at(lad));
            u2_hevn_at(lad) = lad;

            if ( 0 != *pon ) {
                u2z(gof);

                return pro;
            } else {
                if ( u2_no == u2du(pro) ) {
                    *pon = 1;
                    u2z(pro);
                    return u2nc(gof, u2_nul);
                }
                else {
                    u2_noun res = u2k(u2t(pro));

                    u2z(gof);
                    u2z(pro);
                    return res;
                }
            }
        }
    }
}
Пример #25
0
Файл: unix.c Проект: esaul/urbit
/* _unix_file_watch(): create file tracker (from filesystem)
*/
static void
_unix_file_watch(u2_ufil* fil_u,
                 u2_udir* dir_u,
                 c3_c*    pax_c,
                 mpz_t    mod_mp)
{
  // (1) build data structure
  //
  fil_u->non = u2_no;
  fil_u->dry = u2_no;
  fil_u->pax_c = pax_c;
  {
    c3_c* dot_c = strrchr(pax_c, '.');
    c3_c* fas_c = strrchr(pax_c, '/');

    fil_u->dot_c = dot_c ? (fas_c ? ((dot_c > fas_c) ? dot_c : 0)
                            : dot_c)
      : 0;
  }
  fil_u->par_u = dir_u;
  mpz_init_set(fil_u->mod_mp, mod_mp);
  fil_u->nex_u = 0;

  c3_assert(!fil_u->dot_c || (fil_u->dot_c > fil_u->pax_c));


  // (2) stuff data structure into libuv
  //
  c3_w ret_w = uv_fs_event_init(u2L,          // loop
                                &fil_u->was_u // uv_fs_event_t 
                                );
  if (0 != ret_w){
    uL(fprintf(uH, "event init: %s\n", strerror(ret_w)));
    c3_assert(0);
  }

  // note that we're doing something tricky here; see comment in _unix_fs_event_cb
  //
  ret_w = uv_fs_event_start(&fil_u->was_u,     // uv_fs_event_t
                            _unix_fs_event_cb, // callback
                            pax_c,             // dir as strings
                            0);                // flags
  if (0 != ret_w){
    uL(fprintf(uH, "event start: %s\n", strerror(ret_w)));
    c3_assert(0);
  }

}
Пример #26
0
Файл: shax.c Проект: urbit/urbit
  u3_noun
  u3qe_shal(u3_atom a,
            u3_atom b)
  {
    c3_assert(_(u3a_is_cat(a)));
    c3_y* fat_y = u3a_malloc(a + 1);

    u3r_bytes(0, a, fat_y, b);
    {
      c3_y dig_y[64];
#if defined(U3_OS_osx)
      CC_SHA512_CTX ctx_h;

      CC_SHA512_Init(&ctx_h);
      CC_SHA512_Update(&ctx_h, fat_y, a);
      CC_SHA512_Final(dig_y, &ctx_h);
#else
      SHA512_CTX ctx_h;

      SHA512_Init(&ctx_h);
      SHA512_Update(&ctx_h, fat_y, a);
      SHA512_Final(dig_y, &ctx_h);
#endif
      u3a_free(fat_y);
      return u3i_bytes(64, dig_y);
    }
  }
/* u2_cf_flat_save(): save `som` as `mod` at `pas`.
*/
u2_bean
u2_cf_flat_save(u2_noun mod,
                u2_noun pas,
                u2_noun som)
{
  c3_assert(c3__atom == mod);
  {
    c3_c*       pas_c = u2_cr_string(pas);
    c3_i    fid_i;
    c3_w    fln_w;
    c3_y*   fil_y;

    fid_i = open(pas_c, O_WRONLY | O_CREAT, 0666);
    free(pas_c);
    u2_cz(pas);

    if ( fid_i < 0 ) {
      perror(pas_c);
      u2_cz(som);
      return u2_no;
    }

    fln_w = u2_met(3, som);
    fil_y = c3_malloc(fln_w);
    u2_cr_bytes(0, fln_w, fil_y, som);
    u2_cz(som);

    if ( fln_w != write(fid_i, fil_y, fln_w) ) {
      return u2_no;
    }
    close(fid_i);

    return u2_yes;
  }
}
Пример #28
0
Файл: test.c Проект: Gunga/urbit
static void
_test_hash(void)
{
  u3_cm_dump();
  {
    u3_ch_root* har_u = u3_ch_new();
    c3_w        i_w;
    c3_w        max_w = (1 << 20);

    for ( i_w = 0; i_w < max_w; i_w++ ) {
      u3_noun key = u3nc(0, i_w);

      u3_ch_put(har_u, key, (i_w + 1));
      u3z(key);
    }
    for ( i_w = 0; i_w < max_w; i_w++ ) {
      u3_noun key = u3nc(0, i_w);
      u3_noun val = u3_ch_get(har_u, key);

      if ( val != (i_w + 1) ) {
        if ( u3_none == val ) {
          printf("at %d, nothing\n", i_w);
        }
        else printf("at %d, oddly, is %d\n", i_w, val);
        c3_assert(0);
      }
      u3z(key);
    }
    u3_ch_free(har_u);
  }
  u3_cm_dump();
}
Пример #29
0
/* _nock_pray_cool(): load from namespace, in kernel mode.
*/
static u2_noun
_nock_pray_cool(u2_noun gof)                                      //  transfer
{
    //  This should just exit - but for various reasons, all historical,
    //  we could be actually minking here.  Therefore we have to respect
    //  the mink if it exists.
    //
    u2_noun lad = u2_hevn_at(lad);

    if ( u2_nul == lad ) {
        return u2_cm_bowl(u2nc(c3__need, u2nc(gof, u2_nul)));
    }
    else {
        u2_kode pon = 0;
        u2_noun mog = _nock_pray_mool(gof, &pon);

        if ( 0 == pon ) {
            return mog;
        }
        else if ( 1 == pon ) {
            return u2_cm_bowl(u2nc(c3__need, mog));
        }
        else if ( 2 == pon ) {
            return u2_cm_bowl(u2nc(c3__exit, mog));
        }
        else {
            c3_assert(0);
            return 0;
        }
    }
}
Пример #30
0
static void
_tel_event(_te_nvt* nvt, _te_evt* evt)
{
  u3_utel* tel_u;
  c3_assert(0 < telnet_get_userdata(nvt, (void**)&tel_u));
  switch (evt->type)
  {
    case TELNET_EV_DATA:
    {
      _te_dvt* dv = (_te_dvt*)evt;
      _term_suck((u3_utty*)tel_u, dv->data, dv->length);
      break;
    }

    case TELNET_EV_SEND:
    {
      _te_svt* sv = (_te_svt*)evt;
      _term_it_write_bytes((u3_utty*)tel_u, sv->length, sv->data);
      break;
    }
    default:
    {
      break;
    }
  }
}