コード例 #1
0
ファイル: main.c プロジェクト: bschwab/acidblood
int main(int UNUSED(argc), char * UNUSED(argv[]))
{
	if ((botinfo = malloc(sizeof(struct botstruct))) == NULL) {
		fprintf(stderr, "main: Malloc error!\n");
		acid_shutdown(-1);
	}
	
	time(&currtime);
	time(&botinfo->starttime);

	startup();

	if(botinfo->ver == NULL) {
		botinfo->ver = malloc(50) ;
		snprintf(botinfo->ver, 50, "Acidblood %s\n",VERSION) ;
	}

	/* load user data */
	if ((read_user_data()) < 0) {
		fprintf(stderr, "Error reading in user file.\n");
		acid_shutdown(-1);
	}
	
	background() ;

	while (1) {
		
		time(&currtime);

		CheckConfServers() ;
	
		check_connections();
		
		CheckTimers() ;
		
		ReapUserList();

	}
}
コード例 #2
0
ファイル: main.c プロジェクト: ebichu/dd-wrt
/* zeppelin loops here when it is in operational state.  The check
 * against reset variable is probably not needed since select() will
 * return < 0 when a signal interrupts it.
 */
static void main_loop(void)
{
        fd_set rfds, cfds;
        int retval, ret1, ret2, ret3;

        while(!reset) {
                retval = ret1 = ret2 = ret3 = 0;
                FD_ZERO(&rfds);
                conn_get_fds(&rfds);
                FD_ZERO(&cfds);
                conn_get_connecting_fds(&cfds);

                retval = select(FD_SETSIZE, &rfds, &cfds, NULL, NULL);
                diag(COMPONENT, DIAG_DEBUG, "main_loop: select returned %d", retval);
                if (retval < 0) {
                        diag(COMPONENT, DIAG_ERROR, "main_loop: select: %s", strerror(errno));
                        break; /* leave main_loop */
                }
                if (retval == 0) {
                        /* Timeout, funny, since we have no timers */
                        continue;
                }
                if (FD_ISSET(lec_params.kernel->fd, &rfds)) {
                        ret1 = msg_from_kernel();
                        FD_CLR(lec_params.kernel->fd, &rfds);
                }
                ret2 = complete_connections(&cfds);
                ret3 = check_connections(&rfds);
                
                if (ret1 < 0 || ret2 < 0 || ret3 < 0)
                        break; /* leave main_loop */
        }
        
        diag(COMPONENT, DIAG_DEBUG, "exiting main_loop");

        return;
}
コード例 #3
0
ファイル: ident.c プロジェクト: talkers/sensisummink
int main(int argc, char *argv[])
{
#if !defined(NOALARM)
   struct itimerval new_timer, old_timer;
#endif /* !NOALARM */
   struct rlimit rlp;
#if defined(USE_SIGACTION)
   struct sigaction sigact;
#endif
   struct sockaddr_in sadd;

   getrlimit(RLIMIT_NOFILE, &rlp);
   rlp.rlim_cur = rlp.rlim_max;
   setrlimit(RLIMIT_NOFILE, &rlp);

   /* First things first, let the client know we're alive */
   write(1, SERVER_CONNECT_MSG, strlen(SERVER_CONNECT_MSG));

   /* Need this to keep in sync with the client side
    *
    * <start><ident_id><local_port><sin_family><s_addr><sin_port>
    */
   req_size = sizeof(char) + sizeof(ident_identifier) + sizeof(short int)
                + sizeof(sadd.sin_family) + sizeof(sadd.sin_addr.s_addr)
                + sizeof(sadd.sin_port);

   /* Set up signal handling */
#if defined( USE_SIGACTION )
#if defined( USE_SIGEMPTYSET )
  sigemptyset(&(sigact.sa_mask));
#if !defined( FREEBSD ) && !defined( GLIBC )
  sigact.sa_sigaction = 0;
#endif
#else
  sigact.sa_mask = 0;
#if defined ( LINUX )
   sigact.sa_restorer = (void *) 0;
#endif
#endif /* USE_SIGEMPTYSET */
 sigact.sa_handler = catch_sigterm;
 sigaction(SIGTERM, &sigact, (struct sigaction *) 0);
#if !defined ( NOALARM )
  sigact.sa_handler = catch_sigalrm;
  sigaction(SIGALRM, &sigact, (struct sigaction *) 0);
#endif /* !NOALARM */
 sigact.sa_handler = SIG_IGN;
 sigaction(SIGPIPE, &sigact, (struct sigaction *) 0);
#else /* !USE_SIGACTION */
 signal(SIGTERM, catch_sigterm);
#if !defined(NOALARM)
  signal(SIGALRM, catch_sigalrm);
#endif /* !NOALARM */
 signal(SIGPIPE, SIG_IGN);
#endif /* USE_SIGACTION */

#if !defined(NOALARM)
   beats_per_second = 5;
   /* Set up a timer to wake us up now and again */
   new_timer.it_interval.tv_sec = 0;
   new_timer.it_interval.tv_usec = 1000000 / beats_per_second;
   new_timer.it_value.tv_sec = 0;
   new_timer.it_value.tv_usec = new_timer.it_interval.tv_usec;
   if (0 > setitimer(ITIMER_REAL, &new_timer, &old_timer))
   {
      perror("ident");
   }
#endif /* !NOALARM */
#if defined(HAVE_BZERO)
#ifdef SUNOS
    bzero((char *)&idents_in_progress[0], MAX_IDENTS_IN_PROGRESS * sizeof(ident_request));
#elif OSF
    bzero((void *)&idents_in_progress[0], MAX_IDENTS_IN_PROGRESS * sizeof(ident_request));
#else
    bzero(&idents_in_progress[0], MAX_IDENTS_IN_PROGRESS * sizeof(ident_request));
#endif
#else /* !HAVE_BZERO */
   memset(&idents_in_progress[0], 0,
        MAX_IDENTS_IN_PROGRESS * sizeof(ident_request));
#endif /* HAVE_BZERO */
   /* Now enter the main loop */
   status = STATUS_RUNNING;
   while (status != STATUS_SHUTDOWN)
   {
      if (1 == getppid())
      {
      /* If our parent is now PID 1 (init) the talker must have died without
       * killing us, so we have no business still being here
       *
       * time to die...
       */
         exit(0);
      }
      check_requests();
      check_connections();
#if !defined(NOALARM)
      sigpause(0);
#endif /* !NOALARM */
   }

   return 0;
}
コード例 #4
0
ファイル: main.c プロジェクト: borlak/acmud
// MAIN - you can check out any time you like, but you can never leave
int main(int argc, char **argv)
{
	struct timeval time;
	time_t time_slept=0;
	time_t processing_time=0, total_processing_time=0;
	long hotreboot = 0;

	if( argc > 1 )
	{
		if( !is_number(argv[1]) )
		{
			mudlog("Invalid port number!");
			exit(1);
		}
		else if( (port = atoi(argv[1])) <= 1024 )
		{
			mudlog("Port must be above 1024!");
			exit(1);
		}
		if(argc > 2 && !strcmp(argv[2], "hotreboot"))
			hotreboot = 1;
	}

// test stuff
	{
	}


	get_time(&time);
	current_time = time.tv_sec;

	if(!hotreboot)
		create_host(port);
	init_mud(hotreboot);

	while(!mud_shutdown)
	{
		// we want the mud to loop no more than (LOOPS) times a second.. but not to loop
		// (LOOPS) times in 1/10th of a second and then wait for 9/10ths... try to make it even
		if( tick % LOOPS_PER_SECOND == 0 )
		{
			if( time_slept > 1000000 )
			{
				mudlog("time_slept is over a second (%li) and total processing_time this tick (%li)", 
					time_slept, total_processing_time);
//				exit(1);
			}
			else
				mudsleep(1000000 - time_slept);

			time_slept = 0;
			total_processing_time = 0;
		}

		get_time( &time );
		processing_time = time.tv_usec;

		// do all the mud stuff here....
		check_connections();
		mud_update();
		// end mud stuff

		get_time( &time );
		if(time.tv_usec > processing_time)
			processing_time = time.tv_usec - processing_time;
		else
			processing_time = processing_time - time.tv_usec;
		total_processing_time += processing_time;
		current_time = time.tv_sec;
		time_slept += (1000000 / LOOPS_PER_SECOND)-(processing_time);
		tick++;
		mudsleep((1000000 / LOOPS_PER_SECOND)-(processing_time));
	}

	close(host);
	free_mud();
	mudlog("Mud terminated normally.");
	return 1;
}