예제 #1
0
static void load_setup(starter_config_t *cfg, config_parsed_t *cfgp)
{
	kw_list_t *kw;

	DBG2(DBG_APP, "Loading config setup");

	for (kw = cfgp->config_setup; kw; kw = kw->next)
	{
		bool assigned = FALSE;

		kw_token_t token = kw->entry->token;

		if ((int)token < KW_SETUP_FIRST || token > KW_SETUP_LAST)
		{
			DBG1(DBG_APP, "# unsupported keyword '%s' in config setup",
				 kw->entry->name);
			cfg->err++;
			continue;
		}

		if (is_deprecated(token, kw, ""))
		{
			cfg->non_fatal_err++;
			continue;
		}

		if (!assign_arg(token, KW_SETUP_FIRST, kw, (char *)cfg, &assigned))
		{
			DBG1(DBG_APP, "  bad argument value in config setup");
			cfg->err++;
			continue;
		}
	}

	/* verify the executables are actually available */
#ifdef START_CHARON
	cfg->setup.charonstart = cfg->setup.charonstart &&
							 daemon_exists(daemon_name, cmd);
#else
	cfg->setup.charonstart = FALSE;
#endif
}
예제 #2
0
/*
 * Main function of picl daemon
 */
int
main(int argc, char **argv)
{
	struct	sigaction	act;
	int			c;
	sigset_t		ublk;


	(void) setlocale(LC_ALL, "");
	(void) textdomain(TEXT_DOMAIN);

	if (getuid() != 0) {
		syslog(LOG_CRIT, MUST_BE_ROOT);
		return (0);
	}

	(void) rwlock_init(&init_lk, USYNC_THREAD, NULL);
	doreinit = 0;
	logflag = 1;
	dos_req_limit = DOS_PICL_REQUESTS_LIMIT;
	sliding_interval_ms = SLIDING_INTERVAL_MILLISECONDS;
	dos_ms = DOS_SLEEPTIME_MS;
	verbose_level = 0;

	/*
	 * parse arguments
	 */
	while ((c = getopt(argc, argv, "is:t:l:r:v:d:")) != EOF) {
		switch (c) {
		case 'd':
			dos_ms = strtol(optarg, (char **)NULL, 0);
			break;
		case 'i':
			logflag = 0;
			break;
		case 's':
			sliding_interval_ms = strtoll(optarg, (char **)NULL, 0);
			break;
		case 't':
			dos_req_limit = strtol(optarg, (char **)NULL, 0);
			break;
		case 'v':
			verbose_level = strtol(optarg, (char **)NULL, 0);
			logflag = 0;
			break;
		default:
			break;
		}
	}

	orig_time = gethrtime();

	/*
	 * is there a daemon already running?
	 */

	if (daemon_exists()) {
		syslog(LOG_CRIT, DAEMON_RUNNING);
		exit(1);
	}

	/*
	 * Mask off/block SIGALRM signal so that the environmental plug-in
	 * (piclenvd) can use it to simulate sleep() without being affected
	 * by time being set back. No other PICL plug-in should use SIGALRM
	 * or alarm() for now.
	 */
	(void) sigemptyset(&ublk);
	(void) sigaddset(&ublk, SIGALRM);
	(void) sigprocmask(SIG_BLOCK, &ublk, NULL);

	/*
	 * Ignore SIGHUP until all the initialization is done.
	 */
	act.sa_handler = SIG_IGN;
	(void) sigemptyset(&act.sa_mask);
	act.sa_flags = 0;
	if (sigaction(SIGHUP, &act, NULL) == -1)
		syslog(LOG_ERR, SIGACT_FAILED, strsignal(SIGHUP),
		    strerror(errno));

	if (logflag != 0) {	/* daemonize */
		pid_t pid;

		pid = fork();
		if (pid < 0)
			exit(1);
		if (pid > 0)
			/* parent */
			exit(0);

		/* child */
		if (chdir("/") == -1) {
			syslog(LOG_CRIT, CD_ROOT_FAILED);
			exit(1);
		}

		(void) setsid();
		closefrom(0);
		(void) open("/dev/null", O_RDWR, 0);
		(void) dup2(STDIN_FILENO, STDOUT_FILENO);
		(void) dup2(STDIN_FILENO, STDERR_FILENO);
		openlog(PICLD, LOG_PID, LOG_DAEMON);
	}

	/*
	 * Initialize the PICL Tree
	 */
	if (xptree_initialize(NULL) != PICL_SUCCESS) {
		syslog(LOG_CRIT, INIT_FAILED);
		exit(1);
	}

	if (setup_door()) {
		syslog(LOG_CRIT, DOOR_FAILED);
		exit(1);
	}

	/*
	 * setup signal handlers for post-init
	 */
	act.sa_sigaction = hup_handler;
	(void) sigemptyset(&act.sa_mask);
	act.sa_flags = SA_SIGINFO;
	if (sigaction(SIGHUP, &act, NULL) == -1)
		syslog(LOG_ERR, SIGACT_FAILED, strsignal(SIGHUP),
		    strerror(errno));

	/*
	 * wait for requests
	 */
	for (;;) {
		(void) pause();
		if (doreinit) {
			/*
			 * Block SIGHUP during reinitialization.
			 * Also mask off/block SIGALRM signal so that the
			 * environmental plug-in (piclenvd) can use it to
			 * simulate sleep() without being affected by time
			 * being set back. No ohter PICL plug-in should use
			 * SIGALRM or alarm() for now.
			 */
			(void) sigemptyset(&ublk);
			(void) sigaddset(&ublk, SIGHUP);
			(void) sigaddset(&ublk, SIGALRM);
			(void) sigprocmask(SIG_BLOCK, &ublk, NULL);
			(void) sigdelset(&ublk, SIGALRM);
			doreinit = 0;
			(void) rw_wrlock(&init_lk);
			xptree_destroy();
			(void) xptree_reinitialize();
			(void) rw_unlock(&init_lk);
			(void) sigprocmask(SIG_UNBLOCK, &ublk, NULL);
		}
	}
}