Beispiel #1
0
static void rx_thread(void)
{
	SYS_LOG_INF("RX thread started");

	while (1) {
		struct net_pkt *pkt;
		struct net_buf *buf;
		u8_t specifier;

		pkt = k_fifo_get(&rx_queue, K_FOREVER);
		buf = net_buf_frag_last(pkt->frags);

		SYS_LOG_DBG("Got pkt %p buf %p", pkt, buf);

		hexdump("SLIP >", buf->data, buf->len);

		/* TODO: process */
		specifier = net_buf_pull_u8(buf);
		switch (specifier) {
		case '?':
			process_request(buf);
			break;
		case '!':
			process_config(pkt);
			break;
		default:
			SYS_LOG_ERR("Unknown message specifier %c", specifier);
			break;
		}

		net_pkt_unref(pkt);

		k_yield();
	}
}
Beispiel #2
0
/***************************************************************************

 Name: get_next_task

 Description:  retrieves tasks for proc_loop()

               The fist time, we get the task and check task_mode()

 Input:    none
 Output:   none
 Returns:  process status (set to LOGOUT if no tasks found)

***************************************************************************/
static int get_next_task(Arb_connection* dbp)
{
  /*  Loop until time to perform a task  */
  for (;;)
  {
  if (logout_requested())
    break;
      /* Check the next scheduled processing task */
      if (process_config(dbp) == Failure)
      {
          ModLog->batchLog(XPRMOD, XPR_NO_TASK);
          arb_put_state(dbp, ARB_STATUS_LOGOUT);
          break;
      }

      bWroteCtlRpt = FALSE;
      Proc_mode = (tProcMode)task_mode();

      if (Proc_mode != MOD_PRODUCTION && Proc_mode != MOD_BACKOUT) {
          ModLog->batchLog(XPRMOD,XPR_FAIL_INFO_INT,(char*)"invalid proc mode:",Proc_mode);
          arb_put_state(dbp,ARB_STATUS_LOGOUT);
          break;
      }
      if (task_idle_time() <= 0)
        break;
      arb_put_state(dbp, ARB_STATUS_IDLE);
      goto_idle(dbp, task_idle_time());
  }
  return arb_get_current_state();
  
}
int main() {

    VolumeManager *vm;
    CommandListener *cl;
    NetlinkManager *nm;

    SLOGI("Vold 2.1 (the revenge) firing up");

    mkdir("/dev/block/vold", 0755);

    /* Create our singleton managers */
    if (!(vm = VolumeManager::Instance())) {
        SLOGE("Unable to create VolumeManager");
        exit(1);
    };

    if (!(nm = NetlinkManager::Instance())) {
        SLOGE("Unable to create NetlinkManager");
        exit(1);
    };


    cl = new CommandListener();
    vm->setBroadcaster((SocketListener *) cl);
    nm->setBroadcaster((SocketListener *) cl);

    if (vm->start()) {
        SLOGE("Unable to start VolumeManager (%s)", strerror(errno));
        exit(1);
    }

    if (process_config(vm)) {
        SLOGE("Error reading configuration (%s)... continuing anyways", strerror(errno));
    }

    if (nm->start()) {
        SLOGE("Unable to start NetlinkManager (%s)", strerror(errno));
        exit(1);
    }

    coldboot("/sys/block");
//    coldboot("/sys/class/switch");

    /*
     * Now that we're up, we can respond to commands
     */
    if (cl->startListener()) {
        SLOGE("Unable to start CommandListener (%s)", strerror(errno));
        exit(1);
    }

    // Eventually we'll become the monitoring thread
    while(1) {
        sleep(1000);
    }

    SLOGI("Vold exiting");
    exit(0);
}
Beispiel #4
0
void Qt_launchpad::keyPressEvent( QKeyEvent *k ) 
{ 

	//PERR("key pressed");	
	if(k->key() == Qt::Key_O && nowkey == -1) 
	{
		nowkey = 31;
	}
	if(k->key() == Qt::Key_S && nowkey == 31) 
	{
		nowkey = 55;
	}
	if(k->key() == Qt::Key_5 && nowkey == 55) 
	{
		nowkey = -1;
		QList<Child_entry*> child_entries = childrenDockWidgetContents->findChildren<Child_entry*>(QString());
		foreach(Child_entry* child_entry, child_entries){
			if (child_entry) this->exit_child(child_entry->_launchpad_child);
    		}
		this->hide();
		QList<QToolButton*> toolbuttons = this->findChildren<QToolButton*>(QString());
		foreach(QToolButton* toolbutton, toolbuttons){
			if (toolbutton) layoutMain->removeWidget(toolbutton);
			if (toolbutton) layoutTest->removeWidget(toolbutton);
			if (toolbutton) layout3->removeWidget(toolbutton);
			toolbutton->deleteLater();
			launcherDockWidgetContents->adjustSize();
    		}
		layoutMain->deleteLater();
		layoutTest->deleteLater();
		layout3->deleteLater();
		layoutChild->deleteLater();
		layoutQuota->deleteLater();
		groupBoxMain->deleteLater();
		groupBoxTest->deleteLater();
		groupBox3->deleteLater();
		groupBoxChild->deleteLater();
		groupBoxQuota->deleteLater();

		TrustONEserver::Connection t;
		t.trust_one();
		loginfinished=false;
		while(!loginfinished){
			Timer::Connection loginwait;
			loginwait.msleep(1000);
			if(loginfinished){
				process_config(this);
				launcherDockWidget->setWidget(launcherDockWidgetContents);
				loginwait.msleep(500);
				this->show();
			}
		}
	}
/** Parse configuration from INI-file style config file into memory.
 * \param filename  Name of the config file.
 * \retval 0        config successfully parsed
 * \retval <0       error occurred
 */
int config_read_file(const char *filename)
{
	FILE *f;
	ConfigSection *curr_section = NULL;
	int result = 0;

	report(RPT_NOTICE, "Using Configuration File: %s", filename);

	f = fopen(filename, "r");
	if (f == NULL) {
		return -1;
	}

#if defined(LCDPROC_CONFIG_READ_STRING)
	result = process_config(&curr_section, get_next_char_f, filename, f);
#else
	result = process_config(&curr_section, filename, f);
#endif

	fclose(f);

	return result;
}
int config_read_string(const char *sectionname, const char *str)
/* All the config parameters are placed in the given section in memory.*/
{
	int pos = 0;
	ConfigSection *s;

	/* We use a nested function to transfer the characters from buffer to parser*/
	char get_next_char() {
		return str[pos++];
	}

	if ((s = find_section(sectionname)) == NULL)
		s = add_section(sectionname);

	return process_config(&s, get_next_char, "command line", NULL);
}
//---------------------------------------------------------
//
// Function:    sighandler
// Description  Handles the signals we care about
// Arguments:   int signal
//
// Returns:     nothing
//
//---------------------------------------------------------
void sighandler(int signal)
{
	if (signal == SIGTERM) {
		loginfo("Received SIGTERM - cleaning up");
		check();
		free_config(myconfig);
		free(myconfig);
		exit(0);
	} else if (signal == SIGHUP) {
		loginfo("Received SIGHUP - re-reading configuration file [%s]", myconfig->app_config->conf);
		process_config();
	} else if (signal == SIGINT) {
		loginfo("Received SIGINT - cleaning up");
		check();
		free_config(myconfig);
		free(myconfig);
		exit(0);
	}
}
Beispiel #8
0
const char* read_config(void *mconfig,ngx_pool_t *p,ngx_pool_t *ptemp,const char* filename){

    ngx_configfile_t *cfp;
    ngx_int_t rv;
    cmd_parms parms;
    
    parms = default_parms;
    parms.pool = p;
    parms.temp_pool = ptemp;
    
    rv = ngx_pcfg_openfile(&cfp, p, filename);

    if(rv!=NGX_OK){
        
        return ngx_pstrcat(p,"Could not open configuration file: %s",filename,NULL);
    }

    parms.config_file = cfp;
    
    return process_config(mconfig,&parms,p,ptemp);
}
static int load_module(void)
{
	if (process_config(0)) {
		return AST_MODULE_LOAD_DECLINE;
	}

	if (ast_http_uri_link(&test_uri)) {
		return AST_MODULE_LOAD_DECLINE;
	}

	AST_TEST_REGISTER(create_nominal);

	AST_TEST_REGISTER(retrieve_nominal);
	AST_TEST_REGISTER(retrieve_etag);
	AST_TEST_REGISTER(retrieve_expires);
	AST_TEST_REGISTER(retrieve_etag_expired);
	AST_TEST_REGISTER(retrieve_cache_control_age);
	AST_TEST_REGISTER(retrieve_cache_control_directives);

	ast_test_register_init(CATEGORY, pre_test_cb);

	return AST_MODULE_LOAD_SUCCESS;
}
Beispiel #10
0
int ast_ari_config_init(void)
{
	if (aco_info_init(&cfg_info)) {
		aco_info_destroy(&cfg_info);
		return -1;
	}

	aco_option_register(&cfg_info, "enabled", ACO_EXACT, general_options,
		"yes", OPT_BOOL_T, 1,
		FLDSET(struct ast_ari_conf_general, enabled));
	aco_option_register_custom(&cfg_info, "pretty", ACO_EXACT,
		general_options, "no",  encoding_format_handler, 0);
	aco_option_register(&cfg_info, "auth_realm", ACO_EXACT, general_options,
		"Asterisk REST Interface", OPT_CHAR_ARRAY_T, 0,
		FLDSET(struct ast_ari_conf_general, auth_realm),
		ARI_AUTH_REALM_LEN);
	aco_option_register(&cfg_info, "allowed_origins", ACO_EXACT, general_options,
		"", OPT_STRINGFIELD_T, 0,
		STRFLDSET(struct ast_ari_conf_general, allowed_origins));
	aco_option_register(&cfg_info, "websocket_write_timeout", ACO_EXACT, general_options,
		AST_DEFAULT_WEBSOCKET_WRITE_TIMEOUT_STR, OPT_INT_T, PARSE_IN_RANGE,
		FLDSET(struct ast_ari_conf_general, write_timeout), 1, INT_MAX);

	aco_option_register(&cfg_info, "type", ACO_EXACT, user, NULL,
		OPT_NOOP_T, 0, 0);
	aco_option_register(&cfg_info, "read_only", ACO_EXACT, user,
		"no", OPT_BOOL_T, 1,
		FLDSET(struct ast_ari_conf_user, read_only));
	aco_option_register(&cfg_info, "password", ACO_EXACT, user,
		"", OPT_CHAR_ARRAY_T, 0,
		FLDSET(struct ast_ari_conf_user, password), ARI_PASSWORD_LEN);
	aco_option_register_custom(&cfg_info, "password_format", ACO_EXACT,
		user, "plain",  password_format_handler, 0);

	return process_config(0);
}
Beispiel #11
0
int main() {
	int res, try, retries;
	char *query_string, *abf_api_url, *api_token;

	char *log_level = getenv("LOG_LEVEL");
	if (init_logger(log_level == NULL ? "INFO" : log_level) < 0) {
		return 2;
	}
	register_thread("Main");

	log_printf(LOG_INFO, "Starting DNS check...\n");
	res = check_dns();
	if (res < 0) {
		log_printf(LOG_FATAL, "Check DNS failed, can't resolve github.com. Exiting...\n");
		return 6;
	} else {
		log_printf(LOG_INFO, "Successfuly resolved github. Continuing.\n");
	}

	usergroup omv_mock = get_omv_uid_mock_gid();
	if(omv_mock.omv_uid == 0) {
		log_printf(LOG_FATAL, "User omv doesn't exist. Exiting...\n");
		return 7;
	}
	if(omv_mock.mock_gid == 0) {
		log_printf(LOG_FATAL, "Group mock doesn't exist. Exiting...\n");
		return 8;
	}

	res = process_config(&abf_api_url, &api_token, &query_string);
	if (res < 0) {
		log_printf(LOG_FATAL, "Failed to process config, exiting.\n");
		return 1;
	}

	init_strings(api_token);

	init_api(abf_api_url, api_token);

	if(start_statistics_thread(query_string)) {
		log_printf(LOG_FATAL, "Failed to initialize statistics thread. Exiting...\n");
		return 5;
	}

	while(1) {
		char *job;
		if(api_jobs_shift(&job, query_string)) {
			sleep(10);
			continue;
		}

		char *build_id, *distrib_type;
		char **env;
		int ttl;

		res = parse_job_description(job, &build_id, &ttl, &distrib_type, &env);
		free(job);
		if(res < 0) {
			sleep(10);
			continue;
		}

		log_printf(LOG_INFO, "Starting build with build_id %s.\n", build_id);
		log_printf(LOG_INFO, "Sending build start notification to ABF.\n");
		retries = 5;
		try = 0;
		set_busy_status(1, build_id);
		int build_start_success = 0;
		while(retries) {
			log_printf(LOG_INFO, "Try #%d: Sending data to ABF.\n", try + 1);
			if(!api_jobs_feedback(build_id, BUILD_STARTED, hostname_payload)) {
				log_printf(LOG_INFO, "Try #%d: Data sent.\n", try + 1);
				build_start_success = 1;
				break;
			} else {
				log_printf(LOG_ERROR, "Try #%d: Failed to send data to ABF. Sleeping for %d seconds and retrying...\n", try + 1, 1 << try);
			}
			retries--;
			sleep(1 << try);
			try++;
		}

		if (!build_start_success) {
			log_printf(LOG_ERROR, "Failed to send build start to ABF, aborting build.\n");
			free(build_id);
			free(distrib_type);
			for(int i = 0; i < res; i++) {
				free(env[i]);
			}
			free(env);
			set_busy_status(0, NULL);
			continue;
		}

		child script = exec_build(distrib_type, (char * const *)env, omv_mock);

		int live_inspector_started = 1;
		log_printf(LOG_INFO, "Starting live inspector, build's time to live is %d seconds.\n", ttl);
		if(start_live_inspector(ttl, script.pid, build_id) < 0) {
			live_inspector_started = 0;
			log_printf(LOG_WARN, "Live inspector failed to start. Job canceling and timeout will be unavailable.\n");
		}

		int live_logger_started = 1;
		log_printf(LOG_INFO, "Starting live logger.\n");
		if(start_live_logger(build_id, script.read_fd) < 0) {
			live_logger_started = 0;
			log_printf(LOG_WARN, "Live logger failed to start. Live log will be unavailable.\n");
		}

		int status, build_status = BUILD_COMPLETED;
		waitpid(script.pid, &status, 0);
		int canceled = 0;
		if (live_inspector_started) {
			canceled = stop_live_inspector();
		}
		if (live_logger_started) {
			stop_live_logger();
		}

		int exit_code = 0;
		if (canceled) {
			build_status = BUILD_CANCELED;
		}
		else if(WIFEXITED(status)) {
			exit_code = WEXITSTATUS(status);
			switch(exit_code) {
				case 0:
					build_status = BUILD_COMPLETED;
					break;
				case 5:
					build_status = TESTS_FAILED;
					break;
				default:
					build_status = BUILD_FAILED;
			}
		}
		else if(WIFSIGNALED(status)) {
			exit_code = 255;
			build_status = BUILD_FAILED;
		}

		for(int i = 0; i < res; i++) {
			free(env[i]);
		}
		free(env);
		free(distrib_type);

		log_printf(LOG_INFO, "Build is over with status %s.\n", build_statuses_str[build_status]);

		mkdir(home_output, 0666);
		system(move_output_cmd);


		system(upload_cmd);

		char *container_data = read_file(container_data_path);
		char *results = read_file("/tmp/results.json");
		char *commit_hash = read_file(commit_hash_path);
		if(commit_hash != NULL) {
			commit_hash[40] = '\0';
		}

		char *fail_reason = NULL;
		if (build_status == BUILD_FAILED) {
			fail_reason = read_file(fail_reason_path);
			if (fail_reason != NULL) {
				for (unsigned int i = 0; i < strlen(fail_reason); i++) {
					if (!isprint(fail_reason[i]) || fail_reason[i] == '"') {
						fail_reason[i] = ' ';
					}
				}
			}
		}

		char *args = xmalloc((container_data ? strlen(container_data) : 0) + (results ? strlen(results) : 0) + 2048);
		sprintf(args, build_completed_args_fmt, (results ? results : "[]"), \
				(container_data ? container_data : "{}"), exit_code, (commit_hash ? commit_hash : ""),
				(fail_reason ? fail_reason : ""));

		retries = 5;
		try = 0;
		while(retries) {
			log_printf(LOG_INFO, "Try #%d: Sending data to ABF\n", try + 1);
			if(!api_jobs_feedback(build_id, build_status, args)) {
				log_printf(LOG_INFO, "Data sent.\n");
				break;
			} else {
				log_printf(LOG_ERROR, "Failed to send data to ABF. Sleeping for %d seconds and retrying...\n", 1 << try);
			}
			retries--;
			sleep(1 << try);
			try++;
		}

		set_busy_status(0, NULL);
		free(args);
		free(build_id);

		if(commit_hash) {
			free(commit_hash);
		}
		if(results) {
			free(results);
		}
		if(container_data) {
			free(container_data);
		}
		if(fail_reason) {
			free(fail_reason);
		}
	}

	return 0;
}
Beispiel #12
0
int load_config( char* fname)
{
	CONFIG* iter;
	CONFIG_ITEM* item;
	int config_ok = 1,inirval;
	free_filters();
	if((inirval = ini_parse(fname,handler,instance.conf)) < 0){
		printf("Error parsing configuration file!\n");
        if(inirval == -1)
            printf("Inih file open error.\n");
        else if(inirval == -2)
            printf("inih memory error.\n");
        MXS_ERROR("Error parsing configuration file!\n");
        config_ok = 0;
        goto cleanup;
	}
	if(instance.verbose){
		printf("Configuration loaded from %s\n\n",fname);
	}
	if(instance.conf == NULL){
		printf("Nothing valid was read from the file.\n");
		MXS_NOTICE("Nothing valid was read from the file.\n");
		config_ok = 0;
		goto cleanup;
	}

	instance.conf = process_config(instance.conf);
	if(instance.conf){
		if(instance.verbose){
			printf("Modules Loaded:\n");
		}
		iter = instance.conf;
	}else{
		printf("No filters found in the configuration file.\n");
		MXS_NOTICE("No filters found in the configuration file.\n");
		config_ok = 0;
		goto cleanup;
	}

	while(iter){
		item = iter->item;
		while(item){
      
			if(!strcmp("module",item->name)){

				if(instance.mod_dir){
					char* modstr = malloc(sizeof(char)*(strlen(instance.mod_dir) + strlen(item->value) + 1));
					strcpy(modstr,instance.mod_dir);
					strcat(modstr,"/");
					strcat(modstr,item->value);
					instance.head = load_filter_module(modstr);
					free(modstr);
				}else{
					instance.head = load_filter_module(item->value);
				}


				if(!instance.head || !load_filter(instance.head,instance.conf)){

					printf("Error creating filter instance!\nModule: %s\n",item->value);
					MXS_ERROR("Error creating filter instance!\nModule: %s\n",item->value);
					config_ok = 0;
					goto cleanup;

				}else{
					if(instance.verbose){
						printf("\t%s\n",iter->section);  
					}
				}
			}
			item = item->next;
		}
		iter = iter->next;
	}

	while(instance.conf){
		item = instance.conf->item;
		while(item){
			item = instance.conf->item;
			instance.conf->item = instance.conf->item->next;
			free(item->name);
			free(item->value);
			free(item);
			item = instance.conf->item;
		}
		instance.conf = instance.conf->next;
    
	}

	cleanup:
	while(instance.conf){
		iter = instance.conf;
		instance.conf = instance.conf->next;
		item = iter->item;

		while(item){      
			free(item->name);
			free(item->value);
			free(item);
			iter->item = iter->item->next;
			item = iter->item;
		}

		free(iter);
	}
	instance.conf = NULL;

	return config_ok;
}
Beispiel #13
0
int main(int argc, char *argv[])
{
    int fd = -1;
    pid_t pgid = -1;
    server_conf_t *conf;
    int log_priority = LOG_INFO;

#ifndef NDEBUG
    log_priority = LOG_DEBUG;
#endif /* NDEBUG */
    log_set_file(stderr, log_priority, 0);

    conf = create_server_conf();
    tp_global = conf->tp;

    process_cmdline(conf, argc, argv);
    if (!conf->enableForeground) {
        begin_daemonize(&fd, &pgid);
    }
    process_config(conf);
    setup_coredump(conf);
    setup_signals(conf);

    if (!(environ = get_sane_env())) {
        log_err(ENOMEM, "Unable to create sanitized environment");
    }
    if (conf->enableVerbose) {
        display_configuration(conf);
    }
    if (list_is_empty(conf->objs)) {
        log_err(0, "Configuration \"%s\" has no consoles defined",
            conf->confFileName);
    }
    if (conf->tStampMinutes > 0) {
        schedule_timestamp(conf);
    }
    create_listen_socket(conf);

    if (!conf->enableForeground) {
        if (conf->syslogFacility > 0) {
            log_set_syslog(argv[0], conf->syslogFacility);
        }
        if (conf->logFileName) {
            open_daemon_logfile(conf);
        }
        else {
            log_set_file(NULL, 0, 0);
        }
        end_daemonize(fd);
    }

    log_msg(LOG_NOTICE, "Starting ConMan daemon %s (pid %d)",
        VERSION, (int) getpid());

#if WITH_FREEIPMI
    ipmi_init(conf->numIpmiObjs);
#endif /* WITH_FREEIPMI */

    open_objs(conf);
    mux_io(conf);

#if WITH_FREEIPMI
    ipmi_fini();
#endif /* WITH_FREEIPMI */

    destroy_server_conf(conf);

    if (pgid > 0) {
        if (kill(-pgid, SIGTERM) < 0) {
            log_msg(LOG_WARNING, "Unable to terminate process group ID %d: %s",
                pgid, strerror(errno));
        }
    }
    log_msg(LOG_NOTICE, "Stopping ConMan daemon %s (pid %d)",
        VERSION, (int) getpid());
    exit(0);
}
Beispiel #14
0
/*-------------------------------------------------------------------*/
int build_config (const char *hercules_cnf)
{
int     i;                              /* Array subscript           */
int     devtmax;                        /* Max number device threads */

    /*      From impl.c, using system defaults of:
     *
     * LPARNUM  1                       # LPAR 1 with LPAR ID 01
     * CPUIDFMT 0                       # CPU ID format 0
     * XPNDSIZE 0                       # Expanded storage size
     */

    sysblk.xpndsize = 0;

    /* Set sysblk.maxcpu to our preferred default value, if possible */
#if (PREF_DEF_MAXCPU <= MAX_CPU_ENGINES)
    sysblk.maxcpu = PREF_DEF_MAXCPU;
#else
    WARNING( "sysblk.maxcpu reduced from " QSTR( PREF_DEF_MAXCPU ) " to " QSTR( MAX_CPU_ENGINES ))
    sysblk.maxcpu = MAX_CPU_ENGINES;
#endif

#ifdef    _FEATURE_VECTOR_FACILITY
    sysblk.numvec = sysblk.maxcpu;
#else  //!_FEATURE_VECTOR_FACILITY
    sysblk.numvec = 0;
#endif // _FEATURE_VECTOR_FACILITY

#if defined(_900)
    set_archlvl(_ARCH_900_NAME);
#elif defined(_390)
    set_archlvl(_ARCH_390_NAME);
#else
    set_archlvl(_ARCH_370_NAME);
#endif
    devtmax  = MAX_DEVICE_THREADS;

    ptt_trace_init (0, 1);

    /* Set max number device threads */
    sysblk.devtmax = devtmax;
    sysblk.devtwait = sysblk.devtnbr =
    sysblk.devthwm  = sysblk.devtunavail = 0;

#if defined(OPTION_LPP_RESTRICT)
    /* Default the licence setting */
    losc_set(PGM_PRD_OS_RESTRICTED);
#endif

    /* Reset the clock steering registers */
    csr_reset();

    /* Default CPU type CP */
    for (i = 0; i < sysblk.maxcpu; i++)
        sysblk.ptyp[i] = SCCB_PTYP_CP;

    /* Default main storage to 2M with one CPU */
    configure_storage(2 << (SHIFT_MEBIBYTE - 12));
    configure_numcpu(1);

    if (hercules_cnf && (process_config(hercules_cnf)))
        return -1;

    /* Connect each channel set to its home cpu */
    for (i = 0; i < sysblk.maxcpu; i++)
        if (IS_CPU_ONLINE(i))
            sysblk.regs[i]->chanset = i < FEATURE_LCSS_MAX ? i : 0xFFFF;

    return 0;
} /* end function build_config */
//---------------------------------------------------------
// Function:    main
// Description  program entry point
// Arguments:   int
//              **argv
//
// Returns:     int
//---------------------------------------------------------
int main(int argc, char **argv)
{
	s_logger_level level = S_LOGGER_INFO;
	s_logger_mode mode = S_LOGGER_MODE_SYSLOG;
	int facility = LOG_LOCAL1;
	char *config_file;
	int inert = 0;

	//arm errno
	errno = 0;

	//check arg count
	if(argc <= 1)
	{
		usage();
	}

	//parse command line for logging mode and level along with config file override
	//-i = inert
	//-o = stdout
	//-d = debug
	//-f = facility [1-7]
	//-c = configuration file
	int c;
	while ((c = getopt(argc, argv, "iodf:c:")) != -1) {
		switch (c) {
		case 'i':
			inert = 1;
		case 'o':
			mode = S_LOGGER_MODE_STDOUT;
			break;
		case 'd':
			level = S_LOGGER_DEBUG;
			break;
		case 'f':
			switch (atoi(optarg)) {
			case 1:
				facility = LOG_LOCAL1;
				break;
			case 2:
				facility = LOG_LOCAL2;
				break;
			case 3:
				facility = LOG_LOCAL3;
				break;
			case 4:
				facility = LOG_LOCAL4;
				break;
			case 5:
				facility = LOG_LOCAL5;
				break;
			case 6:
				facility = LOG_LOCAL6;
				break;
			case 7:
				facility = LOG_LOCAL7;
				break;
			default:
				usage();
				break;
			}
			break;
		case 'c':
			config_file = optarg;
			break;
		default:
			usage();
		}
	}

	if (mode == S_LOGGER_MODE_SYSLOG) {
		initsyslog(level, facility);
	}else  {
		initstdoutlog(level);
	}

	//place our main structure into the heap
	myconfig = malloc(sizeof(sprinkler_config_t));
	if (myconfig <= 0) {
		logerror("Unable to allocate memory (%d) %s", errno, strerror(errno));
		exit(EXIT_FAILURE);
	}

	if ((init_config(myconfig)) != EXIT_SUCCESS) {
		logerror("An error occured while initializing the config, cannot continue\n");
		exit(EXIT_FAILURE);
	}

	if (config_file != NULL || strcmp(config_file, "") != 0) {
		myconfig->app_config->conf = config_file;
	}

	myconfig->app_config->inert = inert;

	process_config();

	if (mode == S_LOGGER_MODE_SYSLOG) {
		if (daemonize() != 0) {
			logerror("Unable to daemonize");
			exit(EXIT_FAILURE);
		}
	}

	//set signals
	signal(SIGTERM, sighandler);
	signal(SIGHUP, sighandler);
	signal(SIGINT, sighandler);

	main_loop(myconfig);

	//we should never get here
	return 0;
}
Beispiel #16
0
/*-------------------------------------------------------------------*/
int build_config (char *hercules_cnf)
{
int     i;                              /* Array subscript           */
int     devtmax;                        /* Max number device threads */

    sysblk.xpndsize = 0;

    sysblk.maxcpu = MAX_CPU_ENGINES;
#ifdef    _FEATURE_VECTOR_FACILITY
    sysblk.numvec = sysblk.maxcpu;
#else  //!_FEATURE_VECTOR_FACILITY
    sysblk.numvec = 0;
#endif // _FEATURE_VECTOR_FACILITY

#if defined(_900)
    set_archlvl(_ARCH_900_NAME);
#elif defined(_390)
    set_archlvl(_ARCH_390_NAME);
#else
    set_archlvl(_ARCH_370_NAME);
#endif
    devtmax  = MAX_DEVICE_THREADS;



#ifdef OPTION_PTTRACE
    ptt_trace_init (0, 1);
#endif


#if defined(OPTION_FISHIO)
    InitIOScheduler                     // initialize i/o scheduler...
    (
        sysblk.arch_mode,               // (for calling execute_ccw_chain)
        &sysblk.devprio,                // (ptr to device thread priority)
        MAX_DEVICE_THREAD_IDLE_SECS,    // (maximum device thread wait time)
        devtmax                         // (maximum #of device threads allowed)
    );
#else // !defined(OPTION_FISHIO)
    /* Set max number device threads */
    sysblk.devtmax = devtmax;
    sysblk.devtwait = sysblk.devtnbr =
    sysblk.devthwm  = sysblk.devtunavail = 0;
#endif // defined(OPTION_FISHIO)

#if defined(OPTION_LPP_RESTRICT)
    /* Default the licence setting */
    losc_set(PGM_PRD_OS_RESTRICTED);
#endif

    /* Reset the clock steering registers */
    csr_reset();

    /* Default CPU type CP */
    for (i = 0; i < sysblk.maxcpu; i++)
        sysblk.ptyp[i] = SCCB_PTYP_CP;

    /* Default Storage & NUMCPU */
    configure_storage(2);
    configure_numcpu(1);

    if (hercules_cnf && (process_config(hercules_cnf)))
        return -1;

    return 0;
} /* end function build_config */
static int reload_module(void)
{
	return process_config(1);
}
Beispiel #18
0
int ast_ari_config_reload(void)
{
	return process_config(1);
}