Exemplo n.º 1
0
Arquivo: main.c Projeto: hossbeast/fab
static xapi xmain_jump()
{
  enter;

  fatal(xmain);

finally:
  if(XAPI_UNWINDING)
  {
#if DEBUG || DEVEL || XAPI
    xapi_infos("name", "fab");
    xapi_infof("pgid", "%ld", (long)getpgid(0));
    xapi_infof("pid", "%ld", (long)getpid());
    xapi_infof("tid", "%ld", (long)gettid());

    fatal(logger_trace_full, L_ERROR, XAPI_TRACE_COLORIZE);
#else
    fatal(logger_trace_pithy, L_ERROR, XAPI_TRACE_COLORIZE);
#endif

    xmain_exit = XAPI_ERRVAL;
    xapi_calltree_unwind();
  }
coda;
}
Exemplo n.º 2
0
static xapi fi()
{
  enter;

  fail(TEST_ERROR_ONE);

finally:
  xapi_infof("foo", "%d", 42);
  xapi_infof("bar", "%d", 27);
coda;
}
Exemplo n.º 3
0
API xapi xopenats(int * fd, int flags, int dirfd, const char * path)
{
  enter;

  if(fd && (*fd = openat(dirfd, path, flags)) == -1)
    tfail(perrtab_KERNEL, errno);

  else if(!fd && openat(dirfd, path, flags) == -1)
    tfail(perrtab_KERNEL, errno);

finally:
  xapi_infof("dirfd", "%d", dirfd);
  xapi_infof("path", "%s", path);
coda;
}
Exemplo n.º 4
0
API xapi xrealloc(void* target, size_t es, size_t ec, size_t oec)
{
  enter;

  if(policy)
  {
    fatal(policy->realloc, policy, target, es, ec, oec);
  }
  else
  {
    void** t = ((void**)target);
    void * mem = 0;
    if((mem = realloc(*t, es * ec)) == 0)
      tfail(perrtab_KERNEL, errno);
    *t = mem;

    if(es * ec)
    {
      if(*t)
      {
        if(((ssize_t)ec - (ssize_t)oec) > 0)
          memset(((char*)*t) + (oec * es), 0, ((ssize_t)ec - (ssize_t)oec) * es);
      }
      else
      {
        tfail(perrtab_KERNEL, errno);
      }
    }
  }

finally :
  xapi_infof("size", "%zu", es * ec);
coda;
}
Exemplo n.º 5
0
static xapi delta(int num)
{
  enter;

  delta_live++;
  fail(TEST_ERROR_ONE);

finally:
  xapi_infof("num", "%d", num);
coda;
}
Exemplo n.º 6
0
/// inotify_add_watch
//
// SUMMARY
//  proxy for inotify_add_watch
//
API xapi xinotify_add_watch(int * wd, int id, const char *path, uint32_t mask)
{
  enter;

  int rv;
  if((rv = inotify_add_watch(id, path, mask)) < 0)
    tfail(perrtab_KERNEL, errno);

  *wd = rv;

finally:
  xapi_infos("path", path);
  xapi_infof("id", "%d", id);
coda;
}
Exemplo n.º 7
0
API xapi uxopenat_modes(int * fd, int flags, mode_t mode, int dirfd, const char * path)
{
  enter;

  if((*fd = openat(dirfd, path, flags, mode)) == -1)
  {
    if(errno != ENOENT && errno != EEXIST)
      tfail(perrtab_KERNEL, errno);

    *fd = -1;
  }

finally:
  xapi_infof("path", "%s", path);
coda;
}
Exemplo n.º 8
0
API xapi uxgetgrgid_r(gid_t gid, struct group * grp, char * buf, size_t buflen, struct group ** result)
{
  enter;

  if(getgrgid_r(gid, grp, buf, buflen, result) == 0)
  {
    // possibly found, check *result
  }
  else if(errno == ENOENT || errno == ESRCH || errno == EBADF || errno == EPERM)
  {
    *result = 0;  // gid not found
  }
  else
  {
    tfail(perrtab_KERNEL, errno);
  }

finally :
  xapi_infof("gid", "%zu", gid);
coda;
}
Exemplo n.º 9
0
API xapi xmalloc(void* target, size_t size)
{
  enter;

  void * mem = 0;

  if(policy)
  {
    fatal(policy->malloc, policy, target, size);
  }
  else if((mem = calloc(size, 1)) == 0)
  {
    tfail(perrtab_KERNEL, errno);
  }
  else
  {
    *(void**)target = mem;
  }

finally :
  xapi_infof("size", "%zu", size);
coda;
}
Exemplo n.º 10
0
int main(int argc, char** argv, char ** envp)
{
  enter;

  xapi R = 0;
  char space[512];
  char * fabw_path = 0;
  const command * cmd = 0;

  memblk * mb = 0;
  fab_client * client = 0;
  fab_request * request = 0;

  int fd = -1;
  size_t tracesz = 0;

  // libraries
  fatal(fab_load);
  fatal(logger_load);
  fatal(valyria_load);
  fatal(narrator_load);
  fatal(xlinux_load);

  xapi_errtab_register(perrtab_MAIN);

  // logging
  fatal(logging_setup);
  fatal(logger_arguments_setup, envp);
  fatal(logger_finalize);

  // modules
  fatal(params_setup);
  fatal(params_report);
  fatal(sigbank_setup, "fab");

  // parse cmdline arguments
  fatal(args_parse, &cmd);
  fatal(args_report, cmd);

  // ensure fabd can write to my stdout/stderr
  fatal(xfchmod, 1, 0777);
  fatal(xfchmod, 2, 0777);

#if DEVEL
  snprintf(space, sizeof(space), "%s/../fabw/fabw.devel", g_params.exedir);
  fabw_path = space;
#endif

  fatal(fab_client_create, &client, ".", XQUOTE(FABIPCDIR), fabw_path);

#if DEBUG || DEVEL
  logs(L_IPC, "started");
#endif

#if 0
  // possibly kill the existing fabd instance, if any
  if(changed credentials)
    fatal(client_terminate);
#endif

  fatal(fab_client_prepare, client);
  fatal(fab_client_launchp, client);

  fatal(memblk_mk, &mb);
  fatal(args_collate, cmd, mb, &request);
  fatal(fab_client_make_request, client, mb, request);

finally:
#if DEBUG || DEVEL
  if(log_would(L_IPC))
  {
    xapi_infos("name", "fab");
    xapi_infof("pid", "%ld", (long)getpid());
    if(client)
      xapi_infos("hash", fab_client_gethash(client));
  }
#endif

  if(XAPI_UNWINDING)
  {
    if(XAPI_ERRVAL == FAB_FABDEXIT || XAPI_ERRVAL == FAB_UNSUCCESS)
    {
      // on orderly shutdown fabd has already backtraced to our stdout
    }
    else
    {
#if DEBUG || DEVEL || XAPI
      tracesz = xapi_trace_full(space, sizeof(space));
#else
      tracesz = xapi_trace_pithy(space, sizeof(space));
#endif

      xlogw(L_ERROR, L_RED, space, tracesz);
    }

    if(XAPI_ERRVAL == MAIN_BADARGS)
    {
      fatal(args_usage, cmd, 0, 0);
    }
  }

  // locals
  fatal(ixclose, &fd);
  fatal(fab_client_dispose, &client);
  memblk_free(mb);

  // module teardown
  sigbank_teardown();
  params_teardown();
  fatal(build_command_cleanup);

  // libraries
  fatal(fab_unload);
  fatal(logger_unload);
  fatal(valyria_unload);
  fatal(narrator_unload);
  fatal(xlinux_unload);

conclude(&R);
  xapi_teardown();

  return !!R;
}