示例#1
0
int main(int argc, char* argv[]) {

	std::shared_ptr <Base_Daemon_Interface> daemon_ptr = std::make_shared <Daemon> (8080);
	EExitStatus status = daemon_ptr->launch();
	if (status == EExitStatus::EExitStatus_Stop) {
		return EXIT_SUCCESS;
	}

	else if (status == EExitStatus::EExitStatus_Fail) {
		return EXIT_FAILURE;
	}

	std::shared_ptr <Dir_Maintainer> f_manager = std::make_shared <Dir_Maintainer> ();

	f_manager->redirect_streams();

	std::shared_ptr <Base_Log_Formatter> logger_pointer = std::make_shared <Log_Formatter> (f_manager);

	log_with_pid(Const_Strings::start_log, logger_pointer);

	std::shared_ptr <Base_HTTP_Maintainer_Interface> http_maintainer_pointer = std::make_shared <HTTP_Maintainer> (
													logger_pointer);
	std::shared_ptr <Base_Connection_Factory_Interface> conn_factory_pointer = std::make_shared <Connection_Factory> ();


	try {
		std::shared_ptr <Base_Server_Interface> ptr_server = std::make_shared <Server> (logger_pointer,
					http_maintainer_pointer, daemon_ptr, conn_factory_pointer);
		ptr_server->run();

	} catch (std::exception& e) {
		logger_pointer->make_errlog(e.what());
	}

	log_with_pid(Const_Strings::end_log, logger_pointer);

	return EXIT_SUCCESS;
}
示例#2
0
文件: snget.c 项目: liu-chong/sn
int main (int argc, char **argv)
{
   char optdebugbuf[7];
   int n, mark;
   char *cp;

   progname = ((cp = strrchr(argv[0], '/')) ? cp + 1 : argv[0]);

   while ((n = opt_get(argc, argv, "pthcmo")) > -1)
      switch (n)
      {
         case 'd':
            if (++debug < 6)
	    {
               if (!optdebug)
                  strcpy(optdebug = optdebugbuf, "-d");
               else
                  strcat(optdebug, "d");
            }
            break;
         case 'V': version(); _exit(0);
         case 't':
            if (!opt_arg)
               usage();
            LOG("option \"-t %s\" no longer supported", opt_arg);
            break;
         case 'p':
            if (!opt_arg)
               usage();
            concurrency = strtoul(opt_arg, &cp, 10);
            if (concurrency > MAX_CONCURRENCY || concurrency <= 0 || *cp)
               fail(1, "Bad value for concurrency option -p");
            break;
         case 'h':
            if (!opt_arg)
               usage();
            throttlerate = strtoul(opt_arg, &cp, 10);
            if (throttlerate < 0)
               fail(1, "Bad value for throttle option -h");
            break;
         case 'c':
            if (!(optpipelining = opt_arg))
               usage();
            if (strtoul(optpipelining, &cp, 10) < 0 || *cp)
               fail(1, "Bad value for pipeline option -c");
            break;
         case 'm':
            if (!(optmax = opt_arg))
               usage();
            if (strtoul(optmax, &cp, 10) <= 0 || *cp)
               fail(1, "Bad value for max-prime-articles option -m");
            break;
         case 'P':
            optlogpid = TRUE;
            log_with_pid();
            break;
         default:
            usage();
      }
   close(0);
   open("/dev/null", O_RDONLY);
   /* snag 6 and 7 so we can dup onto them */
   if (-1 == dup2(2, 6) || -1 == dup2(2, 7) || -1 == dup2(2, 1))
      fail(2, "Unable to dup standard error:%m");

   parameters(TRUE);
   if (-1 == chdir(snroot))
      fail(2, "chdir(%s):%m", snroot);
   init();
   if (-1 == set_path_var())
      fail(2, "No memory");

   n = 0;
   if (opt_ind == argc)
   {
      DIR *dir;
      struct dirent *dp;
      struct stat st;
      char ch;

      if (!(dir = opendir(".")))
         fail(2, "opendir(%s):%m", snroot);
      while ((dp = readdir(dir)))
         if (is_valid_group(dp->d_name))
            if (-1 == readlink(dp->d_name, &ch, 1)) /* no symlinks */
               if (0 == statf(&st, "%s/.outgoing", dp->d_name))
                  if (S_ISDIR(st.st_mode))
                     if (add(dp->d_name) > -1)   /* NB: add() from get.c */
                        n++;
      closedir(dir);
   }
   else
   {
      debug++;
      for (; opt_ind < argc; opt_ind++)
         if (add(argv[opt_ind]) > -1)
            n++;
      debug--;
   }

   if (n == 0)
      fail(0, "No groups to fetch");

   for (mark = 0; jobs_not_done(); mark++)
   {
      struct timeval tv;
      fd_set rset;
      int max;

      while (sow() == 0)   /* Start some jobs */
         ;
      FD_ZERO(&rset);
      if (throttlerate)
      {
         max = throttle_setfds(&rset);
         if (sigusr)
         {
            sigusr = FALSE;
            LOG("throttling at %d bytes/sec", throttlerate);
         }
      }
      else
         max = -1;
      
      tv.tv_sec = 1;
      tv.tv_usec = 0;
      if (select(max + 1, &rset, NULL, NULL, &tv) > 0)
         if (throttlerate)
            throttle(&rset);
      
      if (sigchld || 1 == mark % 10)
      {
         sigchld = FALSE;
         while (reap() == 0)
            ;
      }
   }
   quit();
   _exit(0);
}
示例#3
0
文件: snntpd.c 项目: liu-chong/sn
int main (int argc, char **argv)
{
   int i;
   char *cp;
   bool greeting;
   int tmo = 600;

   progname = ((cp = strrchr(argv[0], '/')) ? cp + 1 : argv[0]);

   parameters(TRUE);

   greeting = TRUE;
   while ((i = opt_get(argc, argv, "t")) > -1)
      switch (i)
      {
         case 'P': log_with_pid(); break;
         case 'd': debug++; break;
         case 'V': version(); _exit(0);
         case 'S': greeting = FALSE; break;
         case 't':
            if (!opt_arg)
               fail(1, "Need value for \"t\"");
            if ((tmo = strtoul(opt_arg, &cp, 10)) < 0 || *cp)
               fail(1, "Timeout must be positive");
            break;
         default: usage();
      }

   if (opt_ind < argc)
   {
      int pid, lg[2];

      if (-1 == (pid = pipefork(lg)))
         fail(2, "pipe/fork:%m");
      if (0 == pid)
      {
         if (-1 == dup2(lg[0], 0))
            fail(2, "dup:%m");
         dup2(1, 2);
         close(lg[1]);
         execvp(argv[opt_ind], argv + opt_ind);
         LOG("exec(%s):%m", argv[opt_ind]);
         _exit(2);
      }
      close(lg[0]);
      if (-1 == dup2(lg[1], 2))
         fail(2, "dup:%m");
   }

   if (-1 == readln_ready(0, tmo, &input))
      FAIL(2, "readln_ready:%m");

   init();
   set_path_var();
   
   if (greeting)
   {
      args[1] = "READER";
      do_mode();
   }
   
   /* Main loop */

   while (1)
   {
      int nr;

      switch ((nr = args_read(&input)))
      {
         case 0:
            args_write(1, "501 Bad command\r\n");
            continue;
         case -1:
            do_quit(); /* Does not return */
      }
      if (checkservice)
         docheckservice(); /* May not return */
      for (i = 0; i < sizeof (cmds) / sizeof (struct cmd); i++)
      {
         if (strcasecmp(args[0], cmds[i].name))
            continue;
         if (nr < cmds[i].needs_args)
            args_write(1, "501 Bad syntax\r\n");
         else if (cmds[i].needs_group && !currentgroup)
            args_write(1, "412 No group selected\r\n");
         else if (cmds[i].needs_article && -1 == currentserial)
            args_write(1, "420 No article selected\r\n");
         else if (!nr_keys && cmds[i].needs_grouplist && -1 == getallgroups())
            args_write(1, "503 No memory\r\n");
         else
            (*cmds[i].function) ();
         break;
      }
      if (i >= sizeof (cmds) / sizeof (struct cmd))
         args_write(1, "500 unimplemented\r\n");
   }
   /* Not Reached */
}