Example #1
0
static void
do_reload(void)
{
	int e = 0;

	drivers_unload_all();		/* Close all drivers */

	config_clear();
	clear_settings();

	/* Reread command line*/
	CHAIN(e, process_command_line(stored_argc, stored_argv));

	/* Reread config file */
	if (strcmp(configfile, UNSET_STR)==0)
		strncpy(configfile, DEFAULT_CONFIGFILE, sizeof(configfile));
	CHAIN(e, process_configfile(configfile));

	/* Set default values */
	CHAIN(e, (set_default_settings(), 0));

	/* Set reporting values */
	CHAIN(e, set_reporting("LCDd", report_level, report_dest));
	CHAIN(e, (report(RPT_INFO, "Set report level to %d, output to %s", report_level,
			((report_dest == RPT_DEST_SYSLOG) ? "syslog" : "stderr")), 0));

	/* And restart the drivers */
	CHAIN(e, init_drivers());
	CHAIN_END(e, "Critical error while reloading, abort.");
}
Example #2
0
bool ACCEL::begin(){
    filtered.x_axis = 0;
    filtered.y_axis = 0;
    filtered.y_axis = 0;

    // Check ADXL345 REG DEVID
    if (fast_register(REG_DEVID) != 0xE5){
        return false;
    }

    // Enable measurement mode (0b00001000)
    write_register(REG_POWER_CTL, 0x08);

    clear_settings();

    return true;
}
Example #3
0
static void load_library_settings(HWND dialog)
{
    char **overrides = enumerate_values(config_key, keypath("DllOverrides"));
    char **p;
    int sel, count = 0;

    sel = SendDlgItemMessageW(dialog, IDC_DLLS_LIST, LB_GETCURSEL, 0, 0);

    WINE_TRACE("sel=%d\n", sel);

    clear_settings(dialog);
    
    if (!overrides || *overrides == NULL)
    {
        set_controls_from_selection(dialog);
        disable(IDC_DLLS_EDITDLL);
        disable(IDC_DLLS_REMOVEDLL);
        HeapFree(GetProcessHeap(), 0, overrides);
        return;
    }

    enable(IDC_DLLS_EDITDLL);
    enable(IDC_DLLS_REMOVEDLL);
    
    for (p = overrides; *p != NULL; p++)
    {
        int index;
        char *str, *value;
        const char *label;
        struct dll *dll;

        value = get_reg_key(config_key, keypath("DllOverrides"), *p, NULL);

        label = mode_to_label(string_to_mode(value));
        
        str = HeapAlloc(GetProcessHeap(), 0, strlen(*p) + 2 + strlen(label) + 2);
        strcpy(str, *p);
        strcat(str, " (");
        strcat(str, label);
        strcat(str, ")");

        dll = HeapAlloc(GetProcessHeap(), 0, sizeof(struct dll));
        dll->name = *p;
        dll->mode = string_to_mode(value);

        index = SendDlgItemMessageA(dialog, IDC_DLLS_LIST, LB_ADDSTRING, (WPARAM) -1, (LPARAM) str);
        SendDlgItemMessageW(dialog, IDC_DLLS_LIST, LB_SETITEMDATA, index, (LPARAM) dll);

        HeapFree(GetProcessHeap(), 0, str);

        count++;
    }

    HeapFree(GetProcessHeap(), 0, overrides);

    /* restore the previous selection, if possible  */
    if (sel >= count - 1) sel = count - 1;
    else if (sel == -1) sel = 0;

    SendDlgItemMessageW(dialog, IDC_DLLS_LIST, LB_SETCURSEL, sel, 0);

    set_controls_from_selection(dialog);
}
Example #4
0
/**
 * Perform settings self-tests
 *
 */
static void settings_test_exec ( void ) {

	/* Register test settings block */
	ok ( register_settings ( &test_settings, NULL, "test" ) == 0 );

	/* "string" setting type */
	storef_ok ( &test_settings, &test_string_setting, "hello",
		    RAW ( 'h', 'e', 'l', 'l', 'o' ) );
	fetchf_ok ( &test_settings, &test_string_setting,
		    RAW ( 'w', 'o', 'r', 'l', 'd' ), "world" );

	/* "uristring" setting type */
	storef_ok ( &test_settings, &test_uristring_setting, "hello%20world",
		    RAW ( 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l',
			  'd' ) );
	fetchf_ok ( &test_settings, &test_uristring_setting,
		    RAW ( 1, 2, 3, 4, 5 ), "%01%02%03%04%05" );

	/* "ipv4" setting type */
	storef_ok ( &test_settings, &test_ipv4_setting, "192.168.0.1",
		    RAW ( 192, 168, 0, 1 ) );
	fetchf_ok ( &test_settings, &test_ipv4_setting,
		    RAW ( 212, 13, 204, 60 ), "212.13.204.60" );

	/* Integer setting types */
	storef_ok ( &test_settings, &test_int8_setting,
		    "54", RAW ( 54 ) );
	storef_ok ( &test_settings, &test_int8_setting,
		    "0x7f", RAW ( 0x7f ) );
	storef_ok ( &test_settings, &test_int8_setting,
		    "0x1234", RAW ( 0x34 ) );
	storef_ok ( &test_settings, &test_int8_setting,
		    "-32", RAW ( -32 ) );
	fetchf_ok ( &test_settings, &test_int8_setting,
		    RAW ( -9 ), "-9" );
	fetchf_ok ( &test_settings, &test_int8_setting,
		    RAW ( 106 ), "106" );
	storef_ok ( &test_settings, &test_uint8_setting,
		    "129", RAW ( 129 ) );
	storef_ok ( &test_settings, &test_uint8_setting,
		    "0x3421", RAW ( 0x21 ) );
	fetchf_ok ( &test_settings, &test_uint8_setting,
		    RAW ( 0x54 ), "0x54" );
	storef_ok ( &test_settings, &test_int16_setting,
		    "29483", RAW ( 0x73, 0x2b ) );
	fetchf_ok ( &test_settings, &test_int16_setting,
		    RAW ( 0x82, 0x14 ), "-32236" );
	fetchf_ok ( &test_settings, &test_int16_setting,
		    RAW ( 0x12, 0x78 ), "4728" );
	storef_ok ( &test_settings, &test_uint16_setting,
		    "48727", RAW ( 0xbe, 0x57 ) );
	fetchf_ok ( &test_settings, &test_uint16_setting,
		    RAW ( 0x9a, 0x24 ), "0x9a24" );
	storef_ok ( &test_settings, &test_int32_setting,
		    "2901274", RAW ( 0x00, 0x2c, 0x45, 0x1a ) );
	fetchf_ok ( &test_settings, &test_int32_setting,
		    RAW ( 0xff, 0x34, 0x2d, 0xaf ), "-13357649" );
	fetchf_ok ( &test_settings, &test_int32_setting,
		    RAW ( 0x01, 0x00, 0x34, 0xab ), "16790699" );
	storef_ok ( &test_settings, &test_uint32_setting,
		    "0xb598d21", RAW ( 0x0b, 0x59, 0x8d, 0x21 ) );
	fetchf_ok ( &test_settings, &test_uint32_setting,
		    RAW ( 0xf2, 0x37, 0xb2, 0x18 ), "0xf237b218" );

	/* "hex" setting type */
	storef_ok ( &test_settings, &test_hex_setting,
		    ":", RAW ( 0x00, 0x00 ) );
	storef_ok ( &test_settings, &test_hex_setting,
		    "1:2:", RAW ( 0x01, 0x02, 0x00 ) );
	storef_ok ( &test_settings, &test_hex_setting,
		    "08:12:f5:22:90:1b:4b:47:a8:30:cb:4d:67:4c:d6:76",
		    RAW ( 0x08, 0x12, 0xf5, 0x22, 0x90, 0x1b, 0x4b, 0x47, 0xa8,
			  0x30, 0xcb, 0x4d, 0x67, 0x4c, 0xd6, 0x76 ) );
	fetchf_ok ( &test_settings, &test_hex_setting,
		    RAW ( 0x62, 0xd9, 0xd4, 0xc4, 0x7e, 0x3b, 0x41, 0x46, 0x91,
			  0xc6, 0xfd, 0x0c, 0xbf ),
		    "62:d9:d4:c4:7e:3b:41:46:91:c6:fd:0c:bf" );

	/* "hexhyp" setting type */
	storef_ok ( &test_settings, &test_hexhyp_setting,
		    "11-33-22", RAW ( 0x11, 0x33, 0x22 ) );
	fetchf_ok ( &test_settings, &test_hexhyp_setting,
		    RAW ( 0x9f, 0xe5, 0x6d, 0xfb, 0x24, 0x3a, 0x4c, 0xbb, 0xa9,
			  0x09, 0x6c, 0x66, 0x13, 0xc1, 0xa8, 0xec, 0x27 ),
		    "9f-e5-6d-fb-24-3a-4c-bb-a9-09-6c-66-13-c1-a8-ec-27" );

	/* "uuid" setting type (no store capability) */
	fetchf_ok ( &test_settings, &test_uuid_setting,
		    RAW ( 0x1a, 0x6a, 0x74, 0x9d, 0x0e, 0xda, 0x46, 0x1a,0xa8,
			  0x7a, 0x7c, 0xfe, 0x4f, 0xca, 0x4a, 0x57 ),
		    "1a6a749d-0eda-461a-a87a-7cfe4fca4a57" );

	/* Clear and unregister test settings block */
	clear_settings ( &test_settings );
	unregister_settings ( &test_settings );
}
Example #5
0
/**
 * Perform settings self-tests
 *
 */
static void settings_test_exec ( void ) {

	/* Register test settings block */
	ok ( register_settings ( &test_settings, NULL, "test" ) == 0 );

	/* "string" setting type */
	storef_ok ( &test_settings, &test_string_setting, "hello",
		    RAW ( 'h', 'e', 'l', 'l', 'o' ) );
	fetchf_ok ( &test_settings, &test_string_setting,
		    RAW ( 'w', 'o', 'r', 'l', 'd' ), "world" );

	/* "ipv4" setting type */
	storef_ok ( &test_settings, &test_ipv4_setting, "192.168.0.1",
		    RAW ( 192, 168, 0, 1 ) );
	fetchf_ok ( &test_settings, &test_ipv4_setting,
		    RAW ( 212, 13, 204, 60 ), "212.13.204.60" );

	/* "ipv6" setting type */
	storef_ok ( &test_settings, &test_ipv6_setting,
		    "2001:ba8:0:1d4::6950:5845",
		    RAW ( 0x20, 0x01, 0x0b, 0xa8, 0x00, 0x00, 0x01, 0xd4,
			  0x00, 0x00, 0x00, 0x00, 0x69, 0x50, 0x58, 0x45 ) );
	fetchf_ok ( &test_settings, &test_ipv6_setting,
		    RAW ( 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
			  0x02, 0x0c, 0x29, 0xff, 0xfe, 0xc5, 0x39, 0xa1 ),
		    "fe80::20c:29ff:fec5:39a1" );

	/* Integer setting types (as formatted strings) */
	storef_ok ( &test_settings, &test_int8_setting,
		    "54", RAW ( 54 ) );
	storef_ok ( &test_settings, &test_int8_setting,
		    "0x7f", RAW ( 0x7f ) );
	storef_ok ( &test_settings, &test_int8_setting,
		    "0x1234", RAW ( 0x34 ) );
	storef_ok ( &test_settings, &test_int8_setting,
		    "-32", RAW ( -32 ) );
	fetchf_ok ( &test_settings, &test_int8_setting,
		    RAW ( -9 ), "-9" );
	fetchf_ok ( &test_settings, &test_int8_setting,
		    RAW ( 106 ), "106" );
	storef_ok ( &test_settings, &test_uint8_setting,
		    "129", RAW ( 129 ) );
	storef_ok ( &test_settings, &test_uint8_setting,
		    "0x3421", RAW ( 0x21 ) );
	fetchf_ok ( &test_settings, &test_uint8_setting,
		    RAW ( 0x54 ), "0x54" );
	storef_ok ( &test_settings, &test_int16_setting,
		    "29483", RAW ( 0x73, 0x2b ) );
	fetchf_ok ( &test_settings, &test_int16_setting,
		    RAW ( 0x82, 0x14 ), "-32236" );
	fetchf_ok ( &test_settings, &test_int16_setting,
		    RAW ( 0x12, 0x78 ), "4728" );
	storef_ok ( &test_settings, &test_uint16_setting,
		    "48727", RAW ( 0xbe, 0x57 ) );
	fetchf_ok ( &test_settings, &test_uint16_setting,
		    RAW ( 0x9a, 0x24 ), "0x9a24" );
	storef_ok ( &test_settings, &test_int32_setting,
		    "2901274", RAW ( 0x00, 0x2c, 0x45, 0x1a ) );
	fetchf_ok ( &test_settings, &test_int32_setting,
		    RAW ( 0xff, 0x34, 0x2d, 0xaf ), "-13357649" );
	fetchf_ok ( &test_settings, &test_int32_setting,
		    RAW ( 0x01, 0x00, 0x34, 0xab ), "16790699" );
	storef_ok ( &test_settings, &test_uint32_setting,
		    "0xb598d21", RAW ( 0x0b, 0x59, 0x8d, 0x21 ) );
	fetchf_ok ( &test_settings, &test_uint32_setting,
		    RAW ( 0xf2, 0x37, 0xb2, 0x18 ), "0xf237b218" );

	/* Integer setting types (as numeric values) */
	storen_ok ( &test_settings, &test_int8_setting,
		    72, RAW ( 72 ) );
	storen_ok ( &test_settings, &test_int8_setting,
		    0xabcd, RAW ( 0xcd ) );
	fetchn_ok ( &test_settings, &test_int8_setting,
		    RAW ( 0xfe ), -2 );
	storen_ok ( &test_settings, &test_uint8_setting,
		    84, RAW ( 84 ) );
	fetchn_ok ( &test_settings, &test_uint8_setting,
		    RAW ( 0xfe ), 0xfe );
	storen_ok ( &test_settings, &test_int16_setting,
		    0x87bd, RAW ( 0x87, 0xbd ) );
	fetchn_ok ( &test_settings, &test_int16_setting,
		    RAW ( 0x3d, 0x14 ), 0x3d14 );
	fetchn_ok ( &test_settings, &test_int16_setting,
		    RAW ( 0x80 ), -128 );
	storen_ok ( &test_settings, &test_uint16_setting,
		    1, RAW ( 0x00, 0x01 ) );
	fetchn_ok ( &test_settings, &test_uint16_setting,
		    RAW ( 0xbd, 0x87 ), 0xbd87 );
	fetchn_ok ( &test_settings, &test_uint16_setting,
		    RAW ( 0x80 ), 0x0080 );
	storen_ok ( &test_settings, &test_int32_setting,
		    0x0812bfd2, RAW ( 0x08, 0x12, 0xbf, 0xd2 ) );
	fetchn_ok ( &test_settings, &test_int32_setting,
		    RAW ( 0x43, 0x87, 0x91, 0xb4 ), 0x438791b4 );
	fetchn_ok ( &test_settings, &test_int32_setting,
		    RAW ( 0xff, 0xff, 0xfe ), -2 );
	storen_ok ( &test_settings, &test_uint32_setting,
		    0xb5927ab8, RAW ( 0xb5, 0x92, 0x7a, 0xb8 ) );
	fetchn_ok ( &test_settings, &test_uint32_setting,
		    RAW ( 0x98, 0xab, 0x41, 0x81 ), 0x98ab4181 );
	fetchn_ok ( &test_settings, &test_uint32_setting,
		    RAW ( 0xff, 0xff, 0xfe ), 0x00fffffe );
	fetchn_ok ( &test_settings, &test_uint32_setting,
		    RAW ( 0, 0, 0, 0x12, 0x34, 0x56, 0x78 ), 0x12345678 );
	fetchn_ok ( &test_settings, &test_int32_setting,
		    RAW ( 0, 0, 0, 0x12, 0x34, 0x56, 0x78 ), 0x12345678 );
	fetchn_ok ( &test_settings, &test_int32_setting,
		    RAW ( 0xff, 0xff, 0x87, 0x65, 0x43, 0x21 ), -0x789abcdf );

	/* "hex" setting type */
	storef_ok ( &test_settings, &test_hex_setting,
		    "08:12:f5:22:90:1b:4b:47:a8:30:cb:4d:67:4c:d6:76",
		    RAW ( 0x08, 0x12, 0xf5, 0x22, 0x90, 0x1b, 0x4b, 0x47, 0xa8,
			  0x30, 0xcb, 0x4d, 0x67, 0x4c, 0xd6, 0x76 ) );
	fetchf_ok ( &test_settings, &test_hex_setting,
		    RAW ( 0x62, 0xd9, 0xd4, 0xc4, 0x7e, 0x3b, 0x41, 0x46, 0x91,
			  0xc6, 0xfd, 0x0c, 0xbf ),
		    "62:d9:d4:c4:7e:3b:41:46:91:c6:fd:0c:bf" );

	/* "hexhyp" setting type */
	storef_ok ( &test_settings, &test_hexhyp_setting,
		    "11-33-22", RAW ( 0x11, 0x33, 0x22 ) );
	fetchf_ok ( &test_settings, &test_hexhyp_setting,
		    RAW ( 0x9f, 0xe5, 0x6d, 0xfb, 0x24, 0x3a, 0x4c, 0xbb, 0xa9,
			  0x09, 0x6c, 0x66, 0x13, 0xc1, 0xa8, 0xec, 0x27 ),
		    "9f-e5-6d-fb-24-3a-4c-bb-a9-09-6c-66-13-c1-a8-ec-27" );

	/* "hexraw" setting type */
	storef_ok ( &test_settings, &test_hexraw_setting,
		    "012345abcdef", RAW ( 0x01, 0x23, 0x45, 0xab, 0xcd, 0xef ));
	fetchf_ok ( &test_settings, &test_hexraw_setting,
		    RAW ( 0x9e, 0x4b, 0x6e, 0xef, 0x36, 0xb6, 0x46, 0xfe, 0x8f,
			  0x17, 0x06, 0x39, 0x6b, 0xf4, 0x48, 0x4e ),
		    "9e4b6eef36b646fe8f1706396bf4484e" );

	/* "uuid" setting type (no store capability) */
	fetchf_ok ( &test_settings, &test_uuid_setting,
		    RAW ( 0x1a, 0x6a, 0x74, 0x9d, 0x0e, 0xda, 0x46, 0x1a,0xa8,
			  0x7a, 0x7c, 0xfe, 0x4f, 0xca, 0x4a, 0x57 ),
		    "1a6a749d-0eda-461a-a87a-7cfe4fca4a57" );

	/* "busdevfn" setting type (no store capability) */
	fetchf_ok ( &test_settings, &test_busdevfn_setting,
		    RAW ( 0x03, 0x45 ), "03:08.5" );

	/* Clear and unregister test settings block */
	clear_settings ( &test_settings );
	unregister_settings ( &test_settings );
}
Example #6
0
int
main(int argc, char **argv)
{
	int e = 0;
	pid_t parent_pid = 0;

	stored_argc = argc;
	stored_argv = argv;

	/*
	 * Settings in order of preference:
	 *
	 * 1: Settings specified in command line options...
	 * 2: Settings specified in configuration file...
	 * 3: Default settings
	 *
	 * Because of this, and because one option (-c) specifies where
	 * the configuration file is, things are done in this order:
	 *
	 * 1. Read and set options.
	 * 2. Read configuration file; if option is read in configuration
	 *    file and not already set, then set it.
	 * 3. Having read configuration file, if parameter is not set,
	 *    set it to the default value.
	 *
	 * It is for this reason that the default values are **NOT** set
	 * in the variable declaration...
	 */

	/* Report that server is starting (report will be delayed) */
	report(RPT_NOTICE, "LCDd version %s starting", version);
	report(RPT_INFO, "Built on %s, protocol version %s, API version %s",
		build_date, protocol_version, api_version);

	clear_settings();

	/* Read command line*/
	CHAIN(e, process_command_line(argc, argv));

	/* Read config file
	 * If config file was not given on command line use default */
	if (strcmp(configfile, UNSET_STR) == 0)
		strncpy(configfile, DEFAULT_CONFIGFILE, sizeof(configfile));
	CHAIN(e, process_configfile(configfile));

	/* Set default values*/
	set_default_settings();

	/* Set reporting settings (will also flush delayed reports) */
	set_reporting("LCDd", report_level, report_dest);
	report(RPT_INFO, "Set report level to %d, output to %s", report_level,
			((report_dest == RPT_DEST_SYSLOG) ? "syslog" : "stderr"));
	CHAIN_END(e, "Critical error while processing settings, abort.");

	/* Now, go into daemon mode (if we should)...
	 * We wait for the child to report it is running OK. This mechanism
	 * is used because forking after starting the drivers causes the
	 * child to loose the (LPT) port access. */
	if (!foreground_mode) {
		report(RPT_INFO, "Server forking to background");
		CHAIN(e, parent_pid = daemonize());
	} else {
		output_GPL_notice();
		report(RPT_INFO, "Server running in foreground");
	}
	install_signal_handlers(!foreground_mode);
		/* Only catch SIGHUP if not in foreground mode */

	/* Startup the subparts of the server */
	CHAIN(e, sock_init(bind_addr, bind_port));
	CHAIN(e, screenlist_init());
	CHAIN(e, init_drivers());
	CHAIN(e, clients_init());
	CHAIN(e, input_init());
	CHAIN(e, menuscreens_init());
	CHAIN(e, server_screen_init());
	CHAIN_END(e, "Critical error while initializing, abort.");
	if (!foreground_mode) {
		/* Tell to parent that startup went OK. */
		wave_to_parent(parent_pid);
	}
	drop_privs(user); /* This can't be done before, because sending a
			signal to a process of a different user will fail */

	do_mainloop();
	/* This loop never stops; we'll get out only with a signal...*/

	return 0;
}
Example #7
0
void set_settings_file(const char *file)
{
	int f, index = 0, count = 0;
	char c, quote;
	struct string value;
	clear_settings();
	strcpy(settings_file, file);
	make_string(&value);
	if ((f = open(settings_file, O_RDONLY)) == -1)
	{
		perror("set_settings_file.open");
		return;
	}
	while (read(f, &c, 1) == 1)
	{
		switch (c)
		{
			case '#': /* comment line */
				while (read(f, &c, 1) == 1 && c != '\n'); /* skip it */
				break;
			case '\'':
			case '"':
				quote = c;
				while (read(f, &c, 1) == 1 && c != quote)
				{
					append_string_char(&value, c);
				}
				break;
			case '\\':
				if (read(f, &c, 1) == 1)
				{
					append_string_char(&value, c);
				}
				break;
			case ' ':
			case '\t':
			case '\n':
				/* printf("%s\n", value.str); */
				if (strlen(value.str) != 0)
				{
					if (index == 0)
					{
						variables = (char ***)realloc(variables, (count + 2) * sizeof(char **));
						if (variables == NULL)
						{
							perror("set_settings_file.realloc");
							exit(EXIT_FAILURE);
						}
						variables[count + 1] = NULL;
						variables[count] = (char **)realloc(variables[count], 2 * sizeof(char *));
						if (variables[count] == NULL)
						{
							perror("set_settings_file.realloc");
							exit(EXIT_FAILURE);
						}
						variables[count][0] = variables[count][1] = NULL;
						variables[count][0] = (char *)realloc(variables[count][0], (strlen(value.str) + 1) * sizeof(char));
						if (variables[count][0] == NULL)
						{
							perror("set_settings_file.realloc");
							exit(EXIT_FAILURE);
						}
						strcpy(variables[count][0], value.str);
						/* printf("%s = ", variables[count][0]); */
					}
					else
					{
						variables[count][1] = (char *)realloc(variables[count][1], (strlen(value.str) + 1) * sizeof(char));
						if (variables[count][1] == NULL)
						{
							perror("set_settings_file.realloc");
							exit(EXIT_FAILURE);
						}
						strcpy(variables[count][1], value.str);
						/* printf("%s\n", variables[count][1]); */
						++count;
					}
					index = 1 - index;
					clear_string(&value);
				}
				break;
			default:
				append_string_char(&value, c);
		}
	}
	free_string(&value);
}
Example #8
0
void free_settings()
{
	clear_settings();
	free(variables);
}