Exemple #1
0
config_t* parse_config(const char* config_file)
{
    config_t* config = calloc(1, sizeof(config_t));
    if(!config)
        return NULL;

    FILE* f = fopen(config_file, "r");
    if(!f)
    {
        free_config(config);
        return NULL;
    }

    char buf[BUFSIZE];
    while(fgets(buf, BUFSIZE, f))
    {
        if(*buf == '#' || *buf == '\n' || !*buf) continue;
        if(-1 == add_config_entry(config, buf))
        {
            /* FIXME */
            fprintf(stderr, "Unable to parse config line: %s\n", buf);
        }
    }

    if(EOF == fclose(f))
    {
        free_config(config);
        return NULL;
    }

    return config;
}
Exemple #2
0
bool CIRConfig::readConfig() {

	//========================================
	CSingleLock lock(&CS_global_remotes,TRUE);
	FILE *file;
	//========================================

	if(remoteConfig=="" || (file=_tfopen(remoteConfig,_T("r")))==nullptr)	
		return false;

	if(global_remotes!=nullptr) {
		free_config(global_remotes);
		global_remotes = nullptr;
	}
	
	USES_CONVERSION;
	global_remotes = read_config(file,T2A(remoteConfig.GetBuffer()));

	fclose(file);

	if(global_remotes==(struct ir_remote *)-1)
	{
		global_remotes=nullptr;
		WL_DEBUG("read_config returned -1\n");
		return false;
	}

	/* ??? bad input causes codes to be null, but no */
	/* error is returned from read_config. */
	struct ir_remote *sr;
	for(sr=global_remotes;sr!=nullptr;sr=sr->next)
	{
		if(sr->codes==nullptr)
		{
			WL_DEBUG("read_config returned remote with null codes\n");
			free_config(global_remotes);
			global_remotes = nullptr;

			return false;
		}
	}

	if(global_remotes==nullptr)
	{
		WL_DEBUG("read_config returned null\n");
		return false;
	}

	return true;
}
Exemple #3
0
void bar_teardown(struct bar *bar) {
	if (bar->config) {
		free_config(bar->config);
	}

	if (bar->outputs) {
		free_outputs(bar->outputs);
	}

	if (bar->status) {
		free_status_line(bar->status);
	}

	/* close sockets/pipes */
	if (bar->status_read_fd) {
		close(bar->status_read_fd);
	}

	if (bar->ipc_socketfd) {
		close(bar->ipc_socketfd);
	}

	if (bar->ipc_event_socketfd) {
		close(bar->ipc_event_socketfd);
	}

	/* terminate status command process */
	terminate_status_command(bar->status_command_pid);
}
Exemple #4
0
/* copies a configuration from src to tgt */
void copy_config(struct pref_struct *tgt, const struct pref_struct *src)
{
  if (tgt == src)
	return;

  /* first, reset old data */
  free_config(tgt);

  /* then copy */
  tgt->name_res=src->name_res;
  tgt->diagram_only = src->diagram_only;
  tgt->group_unk = src->group_unk;
  tgt->stationary = src->stationary;
  tgt->node_radius_multiplier = src->node_radius_multiplier;
  tgt->link_node_ratio = src->link_node_ratio;
  tgt->size_mode = src->size_mode;
  tgt->node_size_variable = src->node_size_variable;
  tgt->filter=g_strdup(src->filter);
  tgt->text_color=g_strdup(src->text_color);
  tgt->fontname=g_strdup(src->fontname);
  tgt->center_node=g_strdup(src->center_node);
  tgt->stack_level = src->stack_level;
  tgt->colors = g_strdupv(src->colors);

  tgt->proto_timeout_time = src->proto_timeout_time;     
  tgt->gui_node_timeout_time = src->gui_node_timeout_time;
  tgt->node_timeout_time = src->node_timeout_time;
  tgt->proto_node_timeout_time = src->proto_node_timeout_time;
  tgt->gui_link_timeout_time = src->gui_link_timeout_time;
  tgt->link_timeout_time = src->link_timeout_time;
  tgt->proto_link_timeout_time = src->proto_link_timeout_time;

  tgt->refresh_period = src->refresh_period;
  tgt->averaging_time = src->averaging_time;
}
Exemple #5
0
bool am_load_config() {
    free_config();
    am_engine *eng = am_init_engine(true, 0, NULL);
    if (eng == NULL) return false;
    // remove globals metatable, so we can set conf options as globals
    lua_getglobal(eng->L, "_G");
    lua_pushnil(eng->L);
    lua_setmetatable(eng->L, -2);
    lua_pop(eng->L, 1);
    int len;
    char *errmsg;
    void *data = am_read_resource("conf.lua", &len, &errmsg);
    if (data == NULL) {
        // assume conf.lua doesn't exist
        free(errmsg);
    } else {
        bool res = am_run_script(eng->L, (char*)data, len, "conf.lua");
        free(data);
        if (!res) {
            return false;
        }
    }
    read_string_setting(eng->L, "title", &am_conf_app_title, "Untitled");
    read_string_setting(eng->L, "shortname", &am_conf_app_shortname, am_conf_app_title);
    read_string_setting(eng->L, "org", &am_conf_app_org, "Unknown");
    read_string_setting(eng->L, "appid", &am_conf_app_id, "null");
    read_string_setting(eng->L, "version", &am_conf_app_version, "0.0.0");
    am_destroy_engine(eng);
    return true;
}
Exemple #6
0
void slave_main(int sock, struct sockaddr *addr) {
    char addrstr[INET_ADDRSTRLEN];
    struct sockaddr_in *addr_in = (struct sockaddr_in *)addr;
    uint32_t msgtype;
    struct strbuf msg = STRBUF_INIT;

    if (addr->sa_family != AF_INET)
        fatal("unsupported address family %d", addr->sa_family);

    if (!inet_ntop(AF_INET, &addr_in->sin_addr, addrstr, sizeof(addrstr)))
        fatalpe("inet_ntop");

    notice("accepted connection from %s", addrstr);

    setup_slave_sigs();

    while (!terminate) {
        if (ceo_receive_message(sock, &msg, &msgtype))
            break;
        handle_one_message(sock, &msg, msgtype);
    }

    notice("connection closed by peer %s", addrstr);

    strbuf_release(&msg);

    /* stuff allocated by dmaster */
    free_gss();
    free_config();
    free_fqdn();
    free_ops();
    free(prog);
}
Exemple #7
0
struct gq_config *process_rcfile_XML(int error_context, const char *filename)
{
    xmlSAXHandler *handler = g_malloc0(sizeof(xmlSAXHandler));
    int rc;
    struct parser_comm comm;

    comm.error_context = error_context;
    comm.result = NULL;

    handler->error	= (errorSAXFunc) XMLerrorHandler;
    handler->fatalError	= (fatalErrorSAXFunc) XMLfatalErrorHandler;
    handler->warning	= (warningSAXFunc) XMLwarningHandler;

    dot_gq_upgrade_hack(error_context, filename);
    rc = XMLparse(config_tags, handler, &comm, filename);

    g_free(handler);
    if (rc != 0) {
	if (comm.result) {
	    free_config(comm.result);
	}
	comm.result = NULL;
    }

    return comm.result;
}
Exemple #8
0
/*
  Creates global config structure from config entry at plugin startup
*/
int
acct_policy_load_config_startup( Slapi_PBlock* pb, void* plugin_id ) {
	acctPluginCfg *newcfg;
	Slapi_Entry *config_entry = NULL;
	Slapi_DN *config_sdn = NULL;
	int rc;

	/* Retrieve the config entry */
	config_sdn = slapi_sdn_new_normdn_byref( PLUGIN_CONFIG_DN );
	rc = slapi_search_internal_get_entry( config_sdn, NULL, &config_entry,
		plugin_id);
	slapi_sdn_free( &config_sdn );

	if( rc != LDAP_SUCCESS || config_entry == NULL ) {
		slapi_log_err(SLAPI_LOG_ERR, PLUGIN_NAME,
			"acct_policy_load_config_startup - Failed to retrieve configuration entry %s: %d\n",
			PLUGIN_CONFIG_DN, rc );
		return( -1 );
	}
	config_wr_lock();
	free_config();
	newcfg = get_config();
	rc = acct_policy_entry2config( config_entry, newcfg );
	config_unlock();

	slapi_entry_free( config_entry );

	return( rc );
}
Exemple #9
0
int main(int argc, char *argv[])
{
    char *conffile = NULL;
    int request_kill = 0, show_message = 0;
    
    if (!read_parameters(argc, argv, &conffile, &request_kill, &show_message)) {
	print_usage(argv[0]);
	return 1;
    }
    
    /* read the config file; conffile = NULL means use the default. */
    if (!read_config(conffile))
	return 1; /* error reading the config file */
    setup_defaults();
    
    if (request_kill) {
	kill_server();
	return 0;
    }
    
    if (show_message) {
	signal_message();
	return 0;
    }
    
    setup_signals();
    
    /* Init files and directories.
     * Start logging last, so that the log is only created if startup succeeds. */
    if (!init_workdir() ||
	!init_database() ||
	!check_database() ||
	!begin_logging())
	return 1;
    
    if (!settings.nodaemon) {
    	if (daemon(0, 0) == -1) {
	    settings.nodaemon = TRUE;
	    log_msg("could not detach from terminal: %s", strerror(errno));
	    return 1;
	}
	if (!create_pidfile())
	    return 1;
    }

    /* give this process and its children their own process group id for kill() */
    setpgid(0, 0);
    report_startup();
    
    runserver();
        
    /* shutdown */
    remove_pidfile();
    end_logging();
    close_database();
    remove_unix_socket();
    free_config();
    
    return 0;
}
Exemple #10
0
/*
 * Read the configuration files. Implemented as a signal handler so that
 * receipt of SIGHUP will cause configuration to be re-read when the
 * trap daemon is running detatched from the console.
 *
 */
void
trapd_update_config(void)
{
    free_config();
    vacm_standard_views(0,0,NULL,NULL);
    read_configs();
}
Exemple #11
0
int main(int argc, char *argv[]) {
    prog = xstrdup(basename(argv[0]));
    init_log(prog, LOG_PID, LOG_AUTHPRIV, 0);

    configure();

    if (setenv("KRB5CCNAME", "MEMORY:adduser", 1))
        fatalpe("setenv");

    ceo_krb5_init();
    ceo_krb5_auth(ldap_admin_principal);
    ceo_ldap_init();
    ceo_kadm_init();

    cmd_adduser();

    ceo_kadm_cleanup();
    ceo_ldap_cleanup();
    ceo_krb5_deauth();
    ceo_krb5_cleanup();

    free_config();
    free(prog);

    return 0;
}
Exemple #12
0
int
main(int argc, char **argv) {
    struct Config *config = NULL;
    const char *config_file = "/etc/sniproxy.conf";
    int background_flag = 1;
    pid_t pid;
    int opt;

    while ((opt = getopt(argc, argv, "fc:")) != -1) {
        switch (opt) {
            case 'c':
                config_file = optarg;
                break;
            case 'f': /* foreground */
                background_flag = 0;
                break;
            default:
                usage();
                exit(EXIT_FAILURE);
        }
    }

    config = init_config(config_file);
    if (config == NULL) {
        fprintf(stderr, "Unable to load %s\n", config_file);
        return 1;
    }

    init_server(config);

    if (background_flag) {
        pid = daemonize(config->user ? config->user : DEFAULT_USERNAME);

        if (pid != 0 && config->pidfile != NULL) {
            /* parent */
            write_pidfile(config->pidfile, pid);
            free_config(config);
            return 0;
        }
    }

    run_server();

    free_config(config);

    return 0;
}
void
update_config(void)
{
    snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
                        SNMPD_CALLBACK_PRE_UPDATE_CONFIG, NULL);
    free_config();
    read_configs();
}
Exemple #14
0
void config_reset(void) {
    free_config();
    free_nrmesssages();
    free_spells();
    free_buildingtypes();
    free_shiptypes();
    free_races();
    free_spellbooks();
}
Exemple #15
0
/*
 * Read the configuration files. Implemented as a signal handler so that
 * receipt of SIGHUP will cause configuration to be re-read when the
 * trap daemon is running detatched from the console.
 *
 */
void
trapd_update_config(void)
{
    free_config();
#ifdef USING_MIBII_VACM_CONF_MODULE
    vacm_standard_views(0,0,NULL,NULL);
#endif
    read_configs();
}
//---------------------------------------------------------
//
// 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);
	}
}
Exemple #17
0
void terminate()
{

	log_terminate();
	irc_terminate();
	markov_terminate();
	free_config();

	curl_global_cleanup();
}
Exemple #18
0
void sig_hup(int s)
{
	unsigned short dodb = 0;

	if (rundaemon) { syslog(LOG_INFO, "Received SIGHUP, reloading."); }
	if (DBhandle)
	{
		db_deinit();
		dodb = 1;
	}
	if (selectedconf && (selectedconf[0] != 0))
	{
		free_config(my_conf);
		my_conf = read_config(selectedconf);
		if (!my_conf)
		{
			if (rundaemon) { syslog(LOG_CRIT, "Could not read config file \"%s\" which was previously loaded.  Failing.", selectedconf); }
			else { fprintf(stdout, "Could not read config file \"%s\" which was previously loaded.  Failing.\n", selectedconf); }
			exit(1);
		}
	}
	if (dodb)
	{
		if (!db_init())
		{
			if (dlvl(1) && DBhandle)
			{
				if (rundaemon) { syslog(LOG_CRIT, "Database connection failed: %s", mysql_error(DBhandle)); }
				else { fprintf(stdout, "Database connection failed: %s\n", mysql_error(DBhandle)); }
				db_deinit();
			}
			else if (dlvl(1))
			{
				if (rundaemon) { syslog(LOG_CRIT, "Database connection failed: UNKNOWN"); }
				else { fprintf(stdout, "Database connection failed: UNKNOWN\n"); }
			}

			free_config(my_conf);
			exit(0);
		}
	}
}
int main(void)
{
    setlocale(LC_CTYPE, "");

    const char *config_file = "avm-motion-trigger.conf";
    struct config c = get_config(config_file);

    char *session_id = session_start(c.avm.hostname, c.avm.username,
            c.avm.password);

    size_t max_ains = 32;
    char* ains[max_ains];

    int found = switches_list(c.avm.hostname, session_id, ains, max_ains);

    if (0 == found) {
        printf(" * No switches found!\n");
    } else {
        for(short i = 0; i < found; i++) {

            char *name = switch_name(c.avm.hostname, session_id, ains[i]);

            printf("    * Found: %s\n", ains[i]);
            printf("        * Name: %s\n", name);

            if (SWITCH_PRESENT == switch_present(c.avm.hostname,
                        session_id, ains[i])) {
                printf("        * Present: yes (connected)\n");
            } else {
                printf("        * Present: no (not connected)\n");
            }

            if (SWITCH_STATE_ON == switch_state(c.avm.hostname,
                        session_id, ains[i])) {
                printf("        * State: on\n");
            } else {
                printf("        * State: off\n");
            }

            if (i < found-1) {
                printf("\n");
            }

            free(name);
            free(ains[i]);
        }
    }

    session_end(c.avm.hostname, session_id);
    free_config(&c);

    return 0;
}
Exemple #20
0
// Signal handler to free everything before terminating 
void signal_handler(int sig) {
	//if (sig != 0) {}//get rid of unused variable warning
	
	if (sig == SIGINT) {
		free_config();
		exit(0);
	} else if (sig == SIGHUP) {
		bol_reconfigure = true;
	} else if (sig == SIGCHLD) {
		while (waitpid(-1, NULL, WNOHANG) > 0);
	}
}
void print_version(int exit_code)
{
    utlog(LOG_NOTICE, "avm-motion-trigger, avm-motion-triggerd version %s (%s)\n",
            VERSION, MACHTYPE);
    utlog(LOG_NOTICE, "Copyright (C) 2015 Hermann Mayer\n");
    utlog(LOG_NOTICE, "License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\n");
    utlog(LOG_NOTICE, "\n");
    utlog(LOG_NOTICE, "This is free software; you are free to change and redistribute it.\n");
    utlog(LOG_NOTICE, "There is NO WARRANTY, to the extent permitted by law.\n");
    free_config(&conf);
    exit(exit_code);
}
Exemple #22
0
int free_state( STATE **free_start )
{
    STATE *ptr;
    ptr = *free_start;
    
    while ( *free_start != NULL )
    {
        ptr = *free_start;
        free_config(&(ptr->config_set));      
        *free_start = (*free_start)->next;
        free(ptr);
    }
}
Exemple #23
0
CIRConfig::~CIRConfig()
{
	WL_DEBUG("~CIRConfig\n");
		
	CSingleLock lock(&CS_global_remotes,TRUE);

	if(global_remotes!=nullptr) {
		free_config(global_remotes);
		global_remotes = nullptr;
	}
	
	WL_DEBUG("~CIRConfig done\n");
}
Exemple #24
0
int
acct_policy_close( Slapi_PBlock *pb )
{
	int rc = 0;

	slapi_destroy_rwlock(config_rwlock);
	config_rwlock = NULL;
	slapi_sdn_free(&_PluginDN);
	slapi_sdn_free(&_ConfigAreaDN);
	free_config();

	return rc;
}
Exemple #25
0
int main(int argc, char **argv)
{
    struct Config conf;
    struct Options opts;

    if (parse_args(argc, argv, &opts)) {
        return -1;
    }

    if (read_config(&conf)) {
        free_config(&conf);
        return -1;
    }

    while (optind < argc) {
printf("generating code from %s to %s\n", argv[optind], opts.outfile);

        struct TestFile *tf = generate_code(argv[optind], opts.outfile, &conf);
        if (tf) {
            if (opts.just_output_fortran) goto pass;
printf("building test for %s\n", opts.outfile);
            build_test(tf, &conf);

            if (opts.stop_after_build) goto pass;
printf("running test %s\n", tf->exe);
            run_test(tf->exe);

 pass:
            close_testfile(tf);
        } // XXX what does it mean if tf == NULL?

        optind++;
    }

    free_config(&conf);

    return 0;
}
Exemple #26
0
static void
hide_pref_dialog(void)
{
  /* purge temporary */
  free_config(tmp_pref);
  g_free(tmp_pref);
  tmp_pref = NULL;

  /* reset flags */
  colors_changed = FALSE;

  /* hide dialog */
  gtk_widget_hide (diag_pref);
}
Exemple #27
0
void game_over()
{
    if (config.inpacket == 0) {
        expire_all_dns_records();
        print_pdns_stats();
        if (config.handle != NULL) pcap_close(config.handle);
        config.handle = NULL;
        end_all_sessions();
        free_config();
        olog("\n[*] passivedns ended.\n");
        exit(0);
    }
    config.intr_flag |= INTERRUPT_END;
}
Exemple #28
0
bool am_load_config() {
    free_config();
    am_engine *eng = am_init_engine(true, 0, NULL);
    if (eng == NULL) return false;
    // remove globals metatable, so we can set conf options as globals
    lua_getglobal(eng->L, "_G");
    lua_pushnil(eng->L);
    lua_setmetatable(eng->L, -2);
    lua_pop(eng->L, 1);
    int len;
    char *errmsg;
    void *data = am_read_resource("conf.lua", &len, &errmsg);
    if (data == NULL) {
        // assume conf.lua doesn't exist
        free(errmsg);
    } else {
        bool res = am_run_script(eng->L, (char*)data, len, "conf.lua");
        free(data);
        if (!res) {
            am_destroy_engine(eng);
            return false;
        }
    }
    read_string_setting(eng->L, "title", &am_conf_app_title, "Untitled");
    read_string_setting(eng->L, "author", &am_conf_app_author, "Unknown");
    read_string_setting(eng->L, "shortname", &am_conf_app_shortname, am_conf_app_title);
    read_string_setting(eng->L, "appid", &am_conf_app_id, "null");
    read_string_setting(eng->L, "version", &am_conf_app_version, "0.0.0");
    read_string_setting(eng->L, "display_name", &am_conf_app_display_name, am_conf_app_title);
    read_string_setting(eng->L, "dev_region", &am_conf_app_dev_region, "en");
    read_string_setting(eng->L, "supported_languages", &am_conf_app_supported_languages, "en");
    const char *orientation_str = NULL;
    read_string_setting(eng->L, "orientation", &orientation_str, "any");
    if (strcmp(orientation_str, "any") == 0) {
        am_conf_app_display_orientation = AM_DISPLAY_ORIENTATION_ANY;
    } else if (strcmp(orientation_str, "portrait") == 0) {
        am_conf_app_display_orientation = AM_DISPLAY_ORIENTATION_PORTRAIT;
    } else if (strcmp(orientation_str, "landscape") == 0) {
        am_conf_app_display_orientation = AM_DISPLAY_ORIENTATION_LANDSCAPE;
    } else {
        fprintf(stderr, "Invalid orientation in conf.lua: %s\n", orientation_str);
        am_destroy_engine(eng);
        return false;
    }
    read_string_setting(eng->L, "icon", &am_conf_app_icon, NULL);
    read_string_setting(eng->L, "launch_image", &am_conf_app_launch_image, NULL);
    am_destroy_engine(eng);
    return true;
}
Exemple #29
0
int main() {
    struct Config *config;

    config = init_config("../sniproxy.conf");
    if (config == NULL) {
        fprintf(stderr, "Failed to parse config\n");
        return 1;
    }

    print_config(stdout, config);

    free_config(config);

    return 0;
}
Exemple #30
0
/****************************************************
Remove an entry from the DB
******************************************************/
void entry_remove(char * filename)
{
	config_t * old_config;

	wlog(LOGDEBUG,"Removing entry : %s",filename);
	/* Clean-up old anim if any */
	SDL_LockMutex(entry_mutex);
	old_config = (config_t*)list_find(entry_list,filename);
	if( old_config ) {
		free_config(old_config);
	}

	list_update(&entry_list,filename,NULL);

	SDL_UnlockMutex(entry_mutex);
}