Exemple #1
0
static xapi xmain()
{
  enter;

#if DEVEL
  char space[512];
#endif
  char * fabw_path = 0;
  const command * cmd = 0;

  memblk * mb = 0;
  fab_client * client = 0;
  fab_request * request = 0;
  int fd = -1;

#if DEBUG || DEVEL
  // this check is omitted in DEBUG/DEVEL mode because valgrind requires non-setgid and non-setuid executables
#else
  // this executable MUST BE OWNED by fabsys:fabsys and have u+s and g+s permissions
  if(strcmp(g_euid_name, "fabsys") || strcmp(g_egid_name, "fabsys"))
  {
    xapi_info_pushf("real", "r:%s/%d:%s/%d", g_ruid_name, g_ruid, g_rgid_name, g_rgid);
    xapi_info_pushf("effective", "e:%s/%d:%s/%d", g_euid_name, g_euid, g_egid_name, g_egid);
    fail(MAIN_EXEPERMS);
  }
#endif

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

  // 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 0
  // 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(XAPI_UNWINDING)
  {
    if(XAPI_ERRVAL == FAB_NODAEMON)
    {
#if DEBUG || DEVEL
      // fabd exited - check for a coredump
#endif
    }
    else if(XAPI_ERRVAL == MAIN_BADARGS || XAPI_ERRVAL == MAIN_NOCOMMAND)
    {
      fatal(args_usage, cmd, 1, 1);
    }
  }

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

  // module teardown
  fatal(build_command_cleanup);
coda;
}
Exemple #2
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;
}