Ejemplo n.º 1
0
int main(int argc, char **argv)
{
  QCoreApplication app(argc, argv);

  if (argc < 2)
  {
    usage(argv[0]);
  }

  g_server = new Server(myCreateUserLookup);

  printf("%s", startupmessage);

  if (!reloadConfig(argc, argv, true)) {
    printf("Error loading config file!\n");
    exit(1);
  }

#ifdef _WIN32
  DWORD v=GetTickCount();
  WDL_RNG_addentropy(&v,sizeof(v));
  v=(DWORD)time(NULL);
  WDL_RNG_addentropy(&v,sizeof(v));
#else
  time_t v=time(NULL);
  WDL_RNG_addentropy(&v,sizeof(v));
  int pid=getpid();
  WDL_RNG_addentropy(&pid,sizeof(pid));

  if (g_config.setuid != -1) setuid(g_config.setuid);

  if (g_config.pidFilename.Get()[0])
  {
    FILE *fp=fopen(g_config.pidFilename.Get(),"w");
    if (fp)
    {
      fprintf(fp,"%d\n",pid);
      fclose(fp);
    }
    else printf("Error opening PID file '%s'\n", g_config.pidFilename.Get());
  }
#endif

  if (g_config.logFilename.Get()[0])
  {
    g_logfp=fopen(g_config.logFilename.Get(),"at");
    if (!g_logfp)
      printf("Error opening log file '%s'\n",g_config.logFilename.Get());
    else
      logText("Opened log. Wahjam Server %s built on %s at %s\n",VERSION,__DATE__,__TIME__);

  }

  logText("Server starting up...\n");

#ifndef _WIN32
  SignalHandler *sigHandler = new SignalHandler(argc, argv);
#endif

  app.exec();

#ifndef _WIN32
  delete sigHandler;
#endif

  logText("Shutting down server\n");

  /* Explicitly delete before closing log */
  delete g_server;

  if (g_logfp)
  {
    fclose(g_logfp);
    g_logfp=0;
  }

	return 0;
}
Ejemplo n.º 2
0
int main(int argc, char **argv)
{
  QCoreApplication app(argc, argv);

  if (argc < 2)
  {
    usage(argv[0]);
  }

  g_server = new Server(myCreateUserLookup);

  printf("%s", startupmessage);

  if (!reloadConfig(argc, argv, true)) {
    printf("Error loading config file!\n");
    exit(1);
  }

#ifdef _WIN32
  DWORD v=GetTickCount();
  WDL_RNG_addentropy(&v,sizeof(v));
  v=(DWORD)time(NULL);
  WDL_RNG_addentropy(&v,sizeof(v));
#else
  time_t v=time(NULL);
  WDL_RNG_addentropy(&v,sizeof(v));
  int pid=getpid();
  WDL_RNG_addentropy(&pid,sizeof(pid));

  if (g_config.setuid != -1) setuid(g_config.setuid);

  if (g_config.pidFilename.Get()[0])
  {
    FILE *fp=fopen(g_config.pidFilename.Get(),"w");
    if (fp)
    {
      fprintf(fp,"%d\n",pid);
      fclose(fp);
    }
    else qWarning("Error opening PID file '%s'", g_config.pidFilename.Get());
  }
#endif

  logInit(g_config.logFilename.Get());

  qDebug("Server starting up...");

#ifndef _WIN32
  SignalHandler *sigHandler = new SignalHandler(argc, argv);
#endif

  app.exec();

#ifndef _WIN32
  delete sigHandler;
#endif

  qDebug("Shutting down server");

  /* Explicitly delete before closing log */
  delete g_server;

	return 0;
}