示例#1
0
文件: bbot.c 项目: shurizzle/bbot
int
main ()
{
    int i;
    pthread_t * tid_srvs;
    names * nm;
    ircserver * srvs, * srv;

    nm = load_names ("configs.xml");
    srvs = load_servers ("configs.xml", nm);
    srv = srvs;
    
    load_lib ("/usr/lib/libbbot.so");
    load_module ("modules/pong.so");

    tid_srvs = (pthread_t *) alloca (servlen (srvs) * sizeof (pthread_t));
    for (i = 0; i < servlen (srvs); i++)
    {
        pthread_create (&tid_srvs[i], NULL, new_server, (void *) srv);
        srv = srv->next;
    }
    for (i = 0; i < servlen (srvs); i++)
        pthread_join (tid_srvs[i], NULL);

    return 0;
}
示例#2
0
int main(int argc, char **argv)
{
	int i, cur;

	tgetopt(argc, argv);

	if ( toptset('h') )
	{
		printf(usage, argv[0]);
		exit(0);
	}

	if ( toptset('c') ) 
		config_file = toptargs('c');

	syslog_open("updategroups", LOG_PID, LOG_NEWS);

	if ( (master = memmap(sizeof(MASTER))) == NULL )
		die("Can't allocate master memory");

	if ( (groups = memmap(sizeof(ACTIVE) * MAX_GROUPS)) == NULL )
		die("Can't allocate groups memory");

	loadconfig();
	load_servers();

	cur = -1;
	for (i=master->numservers-2; i>=0; i-- )
		if ( (master->lservers[i])->Level != cur )
		{
			cur = (master->lservers[i])->Level;
			update_server( master->lservers[i] );
		}

	write_active();
	write_newsgroups();

	memunmap(master, sizeof(MASTER));
	memunmap(groups, sizeof(ACTIVE) * MAX_GROUPS);

	syslog_close();

	exit(0);
}
示例#3
0
/* This is the daemon's main work - listen for connections and spawn.  */
static void run_daemon (void) 
{
	pid_t pid;
	fd_set serverfds;
	fd_set sslrds;
	int maxfd;

	loadconfig ();
	init_sockets (&serverfds, &sslrds, &maxfd);
	if (cfg.EnableSSL) 
	    ssl_init();

	curl_global_init(CURL_GLOBAL_ALL);
	curl = curl_easy_init();
	if ( !curl ) {
		syslog(LOG_ERR, "curlGetURL: cant initialize curl!");
		return;
	}

	if (! test_only) {
		writepidfile ();

		if (getuid () == 0) {
			struct passwd *pwent;
			if ((pwent = getpwnam (cfg.RunAsUser)) == NULL)
				die ("Unknown user %s, check configuration", cfg.RunAsUser);

			if (setuid (pwent->pw_uid))
				die ("Cant setuid %s", cfg.RunAsUser);
		}
		errno = 0;
	}

	daemon_chdir ();

	load_servers();
	loadactive();
	loadoverviewfmt();
	load_access_conf();
	load_statsfile();
//	init_cache();

	master->serverstart = time (NULL);
	master->nrforks = 0;

#if defined(_SC_NPROCESSORS_ONLN)
	master->numcores = sysconf(_SC_NPROCESSORS_ONLN);
	info("Found %d CPU cores", master->numcores);
#else
	info("No CPU core binding support");
#endif

	if ((master->semid = semlock_init (MASTER_SEMKEY)) == -1) 
		die ("semlock_init: semget failed: %m");

	if (test_only) {
		info ("Startup Test Successfull, Exiting..");
		syslog_close ();
		exit (0);
	}

	info ("NNTP Server Starting..");

	if (!opt_stay) {
		syslog_close ();

		pid = init_daemon (serverfds);

		syslog_open ("nntpswitchd", LOG_PID, LOG_NEWS);

		if (pid < 0) die ("Can't fork");

		/* 2nd time, with the right pid, as user news */
		writepidfile ();
	}

	// start the timer process for statistics
	if ( cfg.StatsFilePeriod > 0 )
		timerpid = run_timer_loop();

	info("Server running new pid %d uid %d euid %d timerpid %d"
			, (int)getpid(), (int)getuid(), (int)geteuid(), (int)timerpid);

	setproctitle("nntpswitchd: waiting for connections");

	daemon_select_loop (serverfds, sslrds, maxfd);
}