Пример #1
0
static xapi test_nofatal()
{
  enter;

  char space[2048];
  size_t z;

  fatal(beta_xapi);

finally:
  // ensure that the trace contains the function name
  z = xapi_trace_full(space, sizeof(space));
  assertf(strstr(space, "function=gamma_xapi"), "expected function, actual trace\n**\n%.*s\n**\n", (int)z, space);

  z = xapi_trace_pithy(space, sizeof(space));
  assertf(strstr(space, "function=gamma_xapi"), "expected function, actual trace\n**\n%.*s\n**\n", (int)z, space);
coda;
}
Пример #2
0
/// test_substack_1_skip
//
// SUMMARY
//  verify infos are skipped in a substack rooted at frame 1
//
static xapi test_substack_1_skip()
{
  enter;

#if XAPI_STACKTRACE
  char space[4096];
  size_t z;
#endif

  fatal(theta);

finally:
#if XAPI_STACKTRACE
  z = xapi_trace_pithy(space, sizeof(space));
  assertf(strstr(space, "foo=42"), "expected foo=42, actual trace\n**\n%.*s\n**\n", (int)z, space);
  assertf(!strstr(space, "bar"), "expected !bar, actual trace\n**\n%.*s\n**\n", (int)z, space);
#endif
coda;
}
Пример #3
0
/// test_basic
//
// SUMMARY
//  verify infos from other frames are present
//
static xapi test_basic()
{
  enter;

#if XAPI_STACKTRACE
  char space[4096];
  size_t z;
#endif

  fatal(beta);

finally:
#if XAPI_STACKTRACE
  z = xapi_trace_pithy(space, sizeof(space));
  assertf(strstr(space, "foo=42"), "expected foo=42, actual trace\n**\n%.*s\n**\n", (int)z, space);
  assertf(strstr(space, "bar=27"), "expected bar=27, actual trace\n**\n%.*s\n**\n", (int)z, space);
#endif
coda;
}
Пример #4
0
/// test_masking
//
// SUMMARY
//  verify that infos from lower frames mask infos in higher frames with the same key
//
static xapi test_masking()
{
  enter;

#if XAPI_STACKTRACE
  char space[4096];
  size_t z;
#endif

  fatal(epsilon);

finally:
#if XAPI_STACKTRACE
  xapi_infos("foo", "87");

  z = xapi_trace_pithy(space, sizeof(space));
  assertf(strstr(space, "foo=42"), "expected foo=42, actual trace\n**\n%.*s\n**\n", (int)z, space);
  assertf(!strstr(space, "foo=87"), "expected !foo=87, actual trace\n**\n%.*s\n**\n", (int)z, space);
#endif
coda;
}
Пример #5
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;
}