Exemple #1
0
/*
 * Test set_config_option
 */
void
test__set_config_option(void **state) 
{
	build_guc_variables();

	bool ret;
	ret = set_config_option("password_encryption", "off", PGC_POSTMASTER, PGC_S_SESSION, false, false);
	assert_true(ret);
	ret = set_config_option("gp_disable_catalog_access_on_segment", "on", PGC_POSTMASTER, PGC_S_SESSION, false, false);
	assert_true(ret);
}
Exemple #2
0
/* set_curcfg(text) */
Datum
tsa_set_curcfg_byname(PG_FUNCTION_ARGS)
{
	text	   *arg0 = PG_GETARG_TEXT_P(0);
	char	   *name;

	name = TextPGetCString(arg0);

	set_config_option("default_text_search_config", name,
					  PGC_USERSET,
					  PGC_S_SESSION,
					  GUC_ACTION_SET,
					  true);

	PG_RETURN_VOID();
}
Exemple #3
0
/* set_curcfg(int) */
Datum
tsa_set_curcfg(PG_FUNCTION_ARGS)
{
	Oid			arg0 = PG_GETARG_OID(0);
	char	   *name;

	name = DatumGetCString(DirectFunctionCall1(regconfigout,
											   ObjectIdGetDatum(arg0)));

	set_config_option("default_text_search_config", name,
					  PGC_USERSET,
					  PGC_S_SESSION,
					  GUC_ACTION_SET,
					  true);

	PG_RETURN_VOID();
}
Exemple #4
0
// read configuration file and save optons to config
bool read_config_file(config_options *config)
{
	char* option;
	char* value;
	FILE* fh;
	
	option = (char*) calloc(100, sizeof(char));
	value  = (char*) calloc(100, sizeof(char));

	if(config->config_file == NULL)
		fh = fopen(CONFIG_FILE, "r");
	else
		fh = fopen(config->config_file, "r");

	if(fh == NULL)
		return false;
	
	char *line;
	line = (char*) calloc(100, sizeof(char));

	while (!feof(fh)) {
		
		//fgets(line, 99, fh);

		//this is an unsave way of doing this
		//TODO: find a better way
		fscanf(fh, "%s = %s", option, value);

		set_config_option(config, option, value);
	}


	//fgets(fh);
	fclose(fh);

	return true;
}
void Utils::initConfigOptions(char *configdir, char *cachedir, bool quiet)
{
    if (configdir) _configBase = configdir;
    if (cachedir) _cacheBase = cachedir;

    std::string file = getConfigFile(LOCAL_CONFIG);

    if (!quiet)
    {
        cInfo() << "Using config path: " << getConfigFile("");
        cInfo() << "Using cache path: " << getCacheFile("");
    }

    if (!ecore_file_can_write(getConfigFile("").c_str()))
        throw (std::runtime_error("config path is not writable"));
    if (!ecore_file_can_write(getCacheFile("").c_str()))
        throw (std::runtime_error("cache path is not writable"));

    if (!fileExists(file))
    {
        //create a defaut config
        std::ofstream conf(file.c_str(), std::ofstream::out);
        conf << "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" << std::endl;
        conf << "<calaos:config xmlns:calaos=\"http://www.calaos.fr\">" << std::endl;
        conf << "<calaos:option name=\"fw_version\" value=\"0\" />" << std::endl;
        conf << "</calaos:config>" << std::endl;
        conf.close();

        set_config_option("fw_target", "calaos_tss");
        set_config_option("fw_version", "0");
        set_config_option("show_cursor", "true");
        set_config_option("use_ntp", "true");
        set_config_option("device_type", "calaos_server");
        set_config_option("dpms_enable", "false");
        set_config_option("smtp_server", "");
        set_config_option("cn_user", "user");
        set_config_option("cn_pass", "pass");
        set_config_option("longitude", "2.322235");
        set_config_option("latitude", "48.864715");

        if (!quiet)
            std::cout << "WARNING: no local_config.xml found, generating default config with username: \"user\" and password: \"pass\"" << std::endl;
    }
}
int main(void)
{
	static uint8_t ret = 0;
	uint8_t i = 0;
	uint8_t ibuf[16] = {0};
	static uint8_t test_pattern[PATTERN_TEST_LENGTH];
	sensor_data_t sensor_data;
	twi_master_options_t opt;

	irq_initialize_vectors();

	sysclk_init();

	/* Initialize the board.
	 * The board-specific conf_board.h file contains the configuration of
	 * the board initialization.
	 */
	board_init();
	gfx_mono_init();
	ioport_set_pin_high(NHD_C12832A1Z_BACKLIGHT);
	gfx_mono_draw_string("Reading....\r\n", 0, 0, &sysfont);
	gfx_mono_generic_draw_filled_rect(0, 8, 128, 8, GFX_PIXEL_CLR);

	/* configure the pins connected to LEDs as output and set their default
	 * initial state to low (LEDs off).
	 */
	ioport_configure_pin(LED_LOW, IOPORT_DIR_OUTPUT);
	ioport_configure_pin(LED_HIGH, IOPORT_DIR_OUTPUT);
	ioport_configure_pin(LED_CRIT, IOPORT_DIR_OUTPUT);
	ioport_configure_pin(LED_NORM, IOPORT_DIR_OUTPUT);

	ioport_set_pin_low(LED_LOW);
	ioport_set_pin_low(LED_HIGH);
	ioport_set_pin_low(LED_CRIT);
	ioport_set_pin_low(LED_NORM);

	/* Configure the ALERT/EVENT pin which is
	 * routed to pin 2 of J2 on A3BU Xplained
	 * This pin can be used for polling or interrupt
	 */
	ioport_configure_pin(EVENT_PIN, IOPORT_DIR_INPUT);

	attach_device(EXAMPLE_TS_DEVICE_ADDR, EXAMPLE_TS_DEVICE);
	opt.chip = EXAMPLE_TS_DEVICE_ADDR;
	opt.speed = TWI_SPEED;

	/* Initialize TWI driver with options */
	twi_master_setup(TWI_MODULE, &opt);

	sensor_data.config_reg.value = 0;
	/* Set configuration register to 12-bis resolution */
	sensor_data.config_reg.option.RES  = AT30TS7_RES12;

	if (write_config(sensor_data.config_reg.value) != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Set the polarity of ALERT/EVENT pin to low */

	if (set_config_option(&sensor_data, AT30TS_POL, AT30TS7_POL_ACTIVE_LOW) !=
	TWI_SUCCESS) {
	test_fail_indication();
	}

	/* Read the configuration register */
	if (read_config(&sensor_data) != TWI_SUCCESS) {
		test_fail_indication();
	}

#if defined _AT30TS00_ || defined _AT30TSE002B_
	/* Set t_high limit register to +75.0000C */
	if (write_tcrit(pos, 75, 0000) != TWI_SUCCESS) {
		test_fail_indication();
	}
#endif

	/* Set t_high limit register to +50.7500C */
	if (write_temperature_high(pos, 50, 7500) != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Set t_low limit register to -25.2500C */

	/*
	 * if (write_temperature_low(neg, 25, 2500)!= TWI_SUCCESS) {
	 * test_fail_indication();
	 * }
	 */

	/* Set t_low limit register to +35.5000C */
	if (write_temperature_low(pos, 35, 5000) != TWI_SUCCESS) {
		test_fail_indication();
	}

#if defined _AT30TS00_ || defined _AT30TSE002B_
	/* Read t_crit register register */
	if (read_tcrit(&sensor_data) != TWI_SUCCESS) {
		test_fail_indication();
	}
#endif

	/* Read t_high limit register */
	if (read_temperature_high(&sensor_data) != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Read t_low register register */
	if (read_temperature_low(&sensor_data) != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Non volatile register functionality */
#if defined _AT30TS750_  || defined _AT30TSE752_ || \
	defined _AT30TSE754_ || defined _AT30TSE758_

	/* Copy volatile registers to nonvolatile registers
	 * vol configuration register  -> nonvol configuration register
	 * vol t_high register -> nonvol t_high register
	 * vol t_low  register -> nonvol t_low register
	 */
        ret = ts75_copy_vol_nonvol_register();
	if (ret != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Read the nonvol configuration register */
	if (read_nvconfig(&sensor_data) != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Read the nonvol t_high register */
	if (read_nvthigh(&sensor_data) != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Read the nonvol t_low register */
	if (read_nvtlow(&sensor_data) != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Clear vol configuration register */
	if (write_config(0x0000) != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Read the vol configuration register */
	if (read_config(&sensor_data) != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Copy nonvolatile registers to volatile registers */
	if (ts75_copy_nonvol_vol_register() != TWI_SUCCESS) {
		test_fail_indication();
	}

	/* Read the configuration register */
	if (read_config(&sensor_data) != TWI_SUCCESS) {
		test_fail_indication();
	}
#endif
        /* To avoid 'variable unused' warning */
        test_pattern[0] = ibuf[0];
        ibuf[0] = test_pattern[0];

	/* EEPROM Test */
#if defined _AT30TSE002B_  || defined _AT30TSE752_ || \
	defined _AT30TSE754_   || defined _AT30TSE758_

	/* Generate Test Pattern */
	for (i = 0; i < PATTERN_TEST_LENGTH; i++) {
		test_pattern[i] = 0x41 + i; // 'ABCD...'
	}

	/* Perform a write access & check write result */
	if ((ret = ts_write_memory(EE_TEST_ADDR, PATTERN_TEST_LENGTH,
	(void *)test_pattern)) != TWI_SUCCESS) {
		gfx_mono_draw_string("EE Write Failed ", 0, 24, &sysfont);
		test_fail_indication();
	}

	/* Allow time for EEPROM to settle */
	delay_ms(5);
	/* Clear test_pattern */
	memset(ibuf, 0, sizeof(ibuf));

	/* Perform a read access & check read result */
	if (ts_read_eeprom(EE_TEST_ADDR, PATTERN_TEST_LENGTH,
			ibuf) != TWI_SUCCESS) {
		gfx_mono_draw_string("EE Read Failed ", 0, 24, &sysfont);
		test_fail_indication();
	}

	/* Check received data against sent data */
	for (i = 0; i < PATTERN_TEST_LENGTH; i++) {
		if (ibuf[i] != test_pattern[i]) {
			gfx_mono_draw_string("EE Read mismatch ", 0, 24,
				&sysfont);
			test_fail_indication();
		}
	}

	gfx_mono_draw_string("EE Write/Read OK", 0, 24, &sysfont);
	gfx_mono_draw_string((char const*)ibuf, 0, 16, &sysfont);
#endif
	/*
	 * Temperature reading contained in struct,i.e.
	 * temperature register value = 0x3240 (+50.25C), AT30TSE758 device
	 * sensor_data.temperature.itemp = 50 //!< integer part
	 * sensor_data.temperature.ftemp = 2500 //!< fractional part
	 * sensor_data.temperature.sign = 0 //!< sign (pos(+) = 0, neg(-) = 1)
	 * sensor_data.temperature.raw_value = 0x324 //!< raw data
	 */

	char senseData[50] = {0};
	while (1) {
		/* Read temperature */
		read_temperature(&sensor_data);
		sprintf(senseData, "%d.%04d DegC",
					sensor_data.temperature.itemp,
						sensor_data.temperature.ftemp);
		gfx_mono_draw_string(senseData, 0, 8, &sysfont);
		ioport_set_pin_low(LED_NORM);
		delay_ms(200);
		ioport_set_pin_high(LED_NORM);
		delay_ms(200);
	}
}
Exemple #7
0
/* ----------
 * main
 * ----------
 */
int
main(int argc, char *const argv[])
{
	char	   *cp1;
	char	   *cp2;
	int			c;
	int			errors = 0;
	extern int	optind;
	extern char *optarg;


#ifdef WIN32
	WSADATA		wsaData;
	int			err;
#endif


#ifdef WIN32
	if (argc >= 2 && !strcmp(argv[1], "-service"))
	{
		win32_servicestart();
		exit(0);
	}
	if (argc >= 2 && !strcmp(argv[1], "-subservice"))
	{
		win32_isservice = 1;
		argc--;
		argv++;
	}
	if (argc >= 2 && argc <= 4 && (
								   !strcmp(argv[1], "-regservice") ||
								   !strcmp(argv[1], "-unregservice") ||
								   !strcmp(argv[1], "-addengine") ||
								   !strcmp(argv[1], "-delengine") ||
								   !strcmp(argv[1], "-listengines")))
	{
		win32_serviceconfig(argc, argv);
	}
#endif

	InitializeConfOptions();

	while ((c = getopt(argc, argv, "f:a:d:s:t:g:c:p:o:q:r:l:x:hv?")) != EOF)
	{
		switch (c)
		{
			case '?':
				Usage(argv);
			case 'q':
				set_config_option("quit_sync_provider", optarg);
				break;

			case 'r':
				set_config_option("quit_sync_finalsync", optarg);
				break;

			case 'f':
				ProcessConfigFile(optarg);
				break;

			case 'a':
				set_config_option("archive_dir", optarg);
				break;

			case 'd':
				set_config_option("log_level", optarg);
				break;

			case 's':
				set_config_option("sync_interval", optarg);
				break;

			case 't':
				set_config_option("sync_interval_timeout", optarg);
				break;

			case 'g':
				set_config_option("sync_group_maxsize", optarg);
				break;

			case 'c':
				set_config_option("vac_frequency", optarg);
				break;

			case 'p':
				set_config_option("pid_file", optarg);
				break;

			case 'o':
				set_config_option("desired_sync_time", optarg);
				break;

			case 'l':
				set_config_option("lag_interval", optarg);
				break;

			case 'h':
				errors++;
				break;

			case 'v':
				printf("slon version %s\n", SLONY_I_VERSION_STRING);
				exit(0);
				break;

			case 'x':
				set_config_option("command_on_logarchive", optarg);
				break;

			default:
				fprintf(stderr, "unknown option '%c'\n", c);
				errors++;
				break;
		}
	}

	/*
	 * Make sure the sync interval timeout isn't too small.
	 */
	if (sync_interval_timeout != 0 && sync_interval_timeout <= sync_interval)
		sync_interval_timeout = sync_interval * 2;

	/*
	 * Remember the cluster name and build the properly quoted namespace
	 * identifier
	 */
	slon_pid = getpid();
#ifndef WIN32
	if (pthread_mutex_init(&slon_watchdog_lock, NULL) < 0)
	{
		slon_log(SLON_FATAL, "slon: pthread_mutex_init() - %s\n",
				 strerror(errno));
		exit(-1);
	}
	slon_watchdog_pid = slon_pid;
	slon_worker_pid = -1;
#endif
	main_argv = argv;

	if ((char *) argv[optind])
	{
		set_config_option("cluster_name", (char *) argv[optind]);
		set_config_option("conn_info", (char *) argv[++optind]);
	}

	if (rtcfg_cluster_name != NULL)
	{
		rtcfg_namespace = malloc(strlen(rtcfg_cluster_name) * 2 + 4);
		cp2 = rtcfg_namespace;
		*cp2++ = '"';
		*cp2++ = '_';
		for (cp1 = (char *) rtcfg_cluster_name; *cp1; cp1++)
		{
			if (*cp1 == '"')
				*cp2++ = '"';
			*cp2++ = *cp1;
		}
		*cp2++ = '"';
		*cp2 = '\0';
	}
	else
	{
		errors++;
	}

	slon_log(SLON_CONFIG, "main: slon version %s starting up\n",
			 SLONY_I_VERSION_STRING);

	/*
	 * Remember the connection information for the local node.
	 */
	if (rtcfg_conninfo == NULL)
	{
		errors++;
	}

	if (errors != 0)
	{
		Usage(argv);
	}

#ifdef WIN32

	/*
	 * Startup the network subsystem, in case our libpq doesn't
	 */
	err = WSAStartup(MAKEWORD(1, 1), &wsaData);
	if (err != 0)
	{
		slon_log(SLON_FATAL, "main: Cannot start the network subsystem - %d\n", err);
		exit(-1);
	}
#endif

	if (pid_file)
	{
		FILE	   *pidfile;

		pidfile = fopen(pid_file, "w");
		if (pidfile)
		{
			fprintf(pidfile, "%d\n", slon_pid);
			fclose(pidfile);
		}
		else
		{
			slon_log(SLON_FATAL, "Cannot open pid_file \"%s\"\n", pid_file);
			exit(-1);
		}
	}

	/*
	 * Create the pipe used to kick the workers scheduler thread
	 */
	if (pgpipe(sched_wakeuppipe) < 0)
	{
		slon_log(SLON_FATAL, "slon: sched_wakeuppipe create failed -(%d) %s\n", errno, strerror(errno));
		slon_exit(-1);
	}

	if (!PQisthreadsafe())
	{
		slon_log(SLON_FATAL, "slon: libpq was not compiled with thread safety enabled (normally: --enable-thread-safety).  slon is a multithreaded application requiring thread-safe libpq\n");
		slon_exit(-1);
	}

	if (!PQisthreadsafe())
	{
		slon_log(SLON_FATAL, "slon: libpq was not compiled with --enable-thread-safety. Slony-I requires a thread enabled libpq\n");
		slon_exit(-1);
	}

	/*
	 * There is no watchdog process on win32. We delegate restarting and other
	 * such tasks to the Service Control Manager. And win32 doesn't support
	 * signals, so we don't need to catch them...
	 */
#ifndef WIN32
	SlonWatchdog();
#else
	SlonMain();
#endif
	exit(0);
}
Exemple #8
0
Datum
_Slony_I_logTrigger(PG_FUNCTION_ARGS)
{
	TransactionId newXid = GetTopTransactionId();
	Slony_I_ClusterStatus *cs;
	TriggerData *tg;
	Datum		argv[4];
	text	   *cmdtype = NULL;
	int			rc;
	Name		cluster_name;
	int32		tab_id;
	char	   *attkind;
	int			attkind_idx;
	int			cmddata_need;

	/*
	 * Don't do any logging if the current session role isn't Origin.
	 */
	if (SessionReplicationRole != SESSION_REPLICATION_ROLE_ORIGIN)
		return PointerGetDatum(NULL);

	/*
	 * Get the trigger call context
	 */
	if (!CALLED_AS_TRIGGER(fcinfo))
		elog(ERROR, "Slony-I: logTrigger() not called as trigger");
	tg = (TriggerData *) (fcinfo->context);

	/*
	 * Check all logTrigger() calling conventions
	 */
	if (!TRIGGER_FIRED_AFTER(tg->tg_event))
		elog(ERROR, "Slony-I: logTrigger() must be fired AFTER");
	if (!TRIGGER_FIRED_FOR_ROW(tg->tg_event))
		elog(ERROR, "Slony-I: logTrigger() must be fired FOR EACH ROW");
	if (tg->tg_trigger->tgnargs != 3)
		elog(ERROR, "Slony-I: logTrigger() must be defined with 3 args");

	/*
	 * Connect to the SPI manager
	 */
	if ((rc = SPI_connect()) < 0)
		elog(ERROR, "Slony-I: SPI_connect() failed in createEvent()");

	/*
	 * Get all the trigger arguments
	 */
	cluster_name = DatumGetName(DirectFunctionCall1(namein,
								CStringGetDatum(tg->tg_trigger->tgargs[0])));
	tab_id = strtol(tg->tg_trigger->tgargs[1], NULL, 10);
	attkind = tg->tg_trigger->tgargs[2];

	/*
	 * Get or create the cluster status information and make sure it has the
	 * SPI plans that we need here.
	 */
	cs = getClusterStatus(cluster_name, PLAN_INSERT_LOG);

	/*
	 * Do the following only once per transaction.
	 */
	if (!TransactionIdEquals(cs->currentXid, newXid))
	{
		int32		log_status;
		bool isnull;

		/*
		 * Determine the currently active log table
		 */
		if (SPI_execp(cs->plan_get_logstatus, NULL, NULL, 0) < 0)
			elog(ERROR, "Slony-I: cannot determine log status");
		if (SPI_processed != 1)
			elog(ERROR, "Slony-I: cannot determine log status");

		log_status = DatumGetInt32(SPI_getbinval(SPI_tuptable->vals[0],
											SPI_tuptable->tupdesc, 1, &isnull));
		SPI_freetuptable(SPI_tuptable);

		switch (log_status)
		{
			case 0:
			case 2:
				cs->plan_active_log = cs->plan_insert_log_1;
				break;

			case 1:
			case 3:
				cs->plan_active_log = cs->plan_insert_log_2;
				break;

			default:
				elog(ERROR, "Slony-I: illegal log status %d", log_status);
				break;
		}

		cs->currentXid = newXid;
	}

	/*
	 * Determine cmdtype and cmddata depending on the command type
	 */
	if (TRIGGER_FIRED_BY_INSERT(tg->tg_event))
	{
		HeapTuple	new_row = tg->tg_trigtuple;
		TupleDesc	tupdesc = tg->tg_relation->rd_att;
		char	   *col_ident;
		char	   *col_value;

		int			len_ident;
		int			len_value;
		int			i;
		int			need_comma = false;
		char	   *OldDateStyle;
		char	   *cp = VARDATA(cs->cmddata_buf);

		/*
		 * INSERT
		 *
		 * cmdtype = 'I' cmddata = ("col" [, ...]) values ('value' [, ...])
		 */
		cmdtype = cs->cmdtype_I;

		/*
		 * Specify all the columns
		 */
		*cp++ = '(';
		for (i = 0; i < tg->tg_relation->rd_att->natts; i++)
		{
			/*
			 * Skip dropped columns
			 */
			if (tupdesc->attrs[i]->attisdropped)
				continue;

			col_ident = (char *) slon_quote_identifier(SPI_fname(tupdesc, i + 1));
			cmddata_need = (cp - (char *) (cs->cmddata_buf)) + 16 +
				(len_ident = strlen(col_ident));
			if (cs->cmddata_size < cmddata_need)
			{
				int			have = (cp - (char *) (cs->cmddata_buf));

				while (cs->cmddata_size < cmddata_need)
					cs->cmddata_size *= 2;
				cs->cmddata_buf = realloc(cs->cmddata_buf, cs->cmddata_size);
				cp = (char *) (cs->cmddata_buf) + have;
			}

			if (need_comma)
				*cp++ = ',';
			else
				need_comma = true;

			memcpy(cp, col_ident, len_ident);
			cp += len_ident;
		}

		/*
		 * Append the string ") values ("
		 */
		*cp++ = ')';
		*cp++ = ' ';
		*cp++ = 'v';
		*cp++ = 'a';
		*cp++ = 'l';
		*cp++ = 'u';
		*cp++ = 'e';
		*cp++ = 's';
		*cp++ = ' ';
		*cp++ = '(';

		/*
		 * Append the values
		 */
		need_comma = false;
		OldDateStyle = GetConfigOptionByName("DateStyle", NULL);
		if (!strstr(OldDateStyle, "ISO"))
			set_config_option("DateStyle", "ISO", PGC_USERSET, PGC_S_SESSION, true, true);
		for (i = 0; i < tg->tg_relation->rd_att->natts; i++)
		{
			/*
			 * Skip dropped columns
			 */
			if (tupdesc->attrs[i]->attisdropped)
				continue;


			if ((col_value = SPI_getvalue(new_row, tupdesc, i + 1)) == NULL)
			{
				col_value = "NULL";
			}
			else
			{
				col_value = slon_quote_literal(col_value);
			}

			cmddata_need = (cp - (char *) (cs->cmddata_buf)) + 16 +
				(len_value = strlen(col_value));
			if (cs->cmddata_size < cmddata_need)
			{
				int			have = (cp - (char *) (cs->cmddata_buf));

				while (cs->cmddata_size < cmddata_need)
					cs->cmddata_size *= 2;
				cs->cmddata_buf = realloc(cs->cmddata_buf, cs->cmddata_size);
				cp = (char *) (cs->cmddata_buf) + have;
			}

			if (need_comma)
				*cp++ = ',';
			else
				need_comma = true;

			memcpy(cp, col_value, len_value);
			cp += len_value;
		}

		if (!strstr(OldDateStyle, "ISO"))
			set_config_option("DateStyle", OldDateStyle, PGC_USERSET, PGC_S_SESSION, true, true);

		/*
		 * Terminate and done
		 */
		*cp++ = ')';
		*cp = '\0';
		SET_VARSIZE(cs->cmddata_buf,
					VARHDRSZ + (cp - VARDATA(cs->cmddata_buf)));
	}
	else if (TRIGGER_FIRED_BY_UPDATE(tg->tg_event))
	{
		HeapTuple	old_row = tg->tg_trigtuple;
		HeapTuple	new_row = tg->tg_newtuple;
		TupleDesc	tupdesc = tg->tg_relation->rd_att;
		Datum		old_value;
		Datum		new_value;
		bool		old_isnull;
		bool		new_isnull;

		char	   *col_ident;
		char	   *col_value;
		int			len_ident;
		int			len_value;
		int			i;
		int			need_comma = false;
		int			need_and = false;
		char	   *OldDateStyle;

		char	   *cp = VARDATA(cs->cmddata_buf);

		/*
		 * UPDATE
		 *
		 * cmdtype = 'U' cmddata = "col_ident"='value' [, ...] where
		 * "pk_ident" = 'value' [ and ...]
		 */
		cmdtype = cs->cmdtype_U;
		for (i = 0; i < tg->tg_relation->rd_att->natts; i++)
		{
			/*
			 * Ignore dropped columns
			 */
			if (tupdesc->attrs[i]->attisdropped)
				continue;

			old_value = SPI_getbinval(old_row, tupdesc, i + 1, &old_isnull);
			new_value = SPI_getbinval(new_row, tupdesc, i + 1, &new_isnull);

			/*
			 * If old and new value are NULL, the column is unchanged
			 */
			if (old_isnull && new_isnull)
				continue;

			/*
			 * If both are NOT NULL, we need to compare the values and skip
			 * setting the column if equal
			 */
			if (!old_isnull && !new_isnull)
			{
				Oid			opr_oid;
				FmgrInfo   *opr_finfo_p;

				/*
				 * Lookup the equal operators function call info using the
				 * typecache if available
				 */
#ifdef HAVE_TYPCACHE
				TypeCacheEntry *type_cache;

				type_cache = lookup_type_cache(
											   SPI_gettypeid(tupdesc, i + 1),
								  TYPECACHE_EQ_OPR | TYPECACHE_EQ_OPR_FINFO);
				opr_oid = type_cache->eq_opr;
				if (opr_oid == ARRAY_EQ_OP)
					opr_oid = InvalidOid;
				else
					opr_finfo_p = &(type_cache->eq_opr_finfo);
#else
				FmgrInfo	opr_finfo;

				opr_oid = compatible_oper_funcid(makeList1(makeString("=")),
											   SPI_gettypeid(tupdesc, i + 1),
										SPI_gettypeid(tupdesc, i + 1), true);
				if (OidIsValid(opr_oid))
				{
					fmgr_info(opr_oid, &opr_finfo);
					opr_finfo_p = &opr_finfo;
				}
#endif

				/*
				 * If we have an equal operator, use that to do binary
				 * comparision. Else get the string representation of both
				 * attributes and do string comparision.
				 */
				if (OidIsValid(opr_oid))
				{
					if (DatumGetBool(FunctionCall2(opr_finfo_p,
												   old_value, new_value)))
						continue;
				}
				else
				{
					char	   *old_strval = SPI_getvalue(old_row, tupdesc, i + 1);
					char	   *new_strval = SPI_getvalue(new_row, tupdesc, i + 1);

					if (strcmp(old_strval, new_strval) == 0)
						continue;
				}
			}

			if (need_comma)
				*cp++ = ',';
			else
				need_comma = true;

			col_ident = (char *) slon_quote_identifier(SPI_fname(tupdesc, i + 1));
			if (new_isnull)
				col_value = "NULL";
			else
			{
				OldDateStyle = GetConfigOptionByName("DateStyle", NULL);
				if (!strstr(OldDateStyle, "ISO"))
					set_config_option("DateStyle", "ISO", PGC_USERSET, PGC_S_SESSION, true, true);
				col_value = slon_quote_literal(SPI_getvalue(new_row, tupdesc, i + 1));
				if (!strstr(OldDateStyle, "ISO"))
					set_config_option("DateStyle", OldDateStyle, PGC_USERSET, PGC_S_SESSION, true, true);
			}
			cmddata_need = (cp - (char *) (cs->cmddata_buf)) + 16 +
				(len_ident = strlen(col_ident)) +
				(len_value = strlen(col_value));
			if (cs->cmddata_size < cmddata_need)
			{
				int			have = (cp - (char *) (cs->cmddata_buf));

				while (cs->cmddata_size < cmddata_need)
					cs->cmddata_size *= 2;
				cs->cmddata_buf = realloc(cs->cmddata_buf, cs->cmddata_size);
				cp = (char *) (cs->cmddata_buf) + have;
			}

			memcpy(cp, col_ident, len_ident);
			cp += len_ident;
			*cp++ = '=';
			memcpy(cp, col_value, len_value);
			cp += len_value;
		}

		/*
		 * It can happen that the only UPDATE an application does is to set a
		 * column to the same value again. In that case, we'd end up here with
		 * no columns in the SET clause yet. We add the first key column here
		 * with it's old value to simulate the same for the replication
		 * engine.
		 */
		if (!need_comma)
		{
			for (i = 0, attkind_idx = -1; i < tg->tg_relation->rd_att->natts; i++)
			{
				if (tupdesc->attrs[i]->attisdropped)
					continue;

				attkind_idx++;
				if (!attkind[attkind_idx])
					elog(ERROR, "Slony-I: no key columns found in logTrigger() attkind parameter");

				if (attkind[attkind_idx] == 'k')
					break;
			}
			col_ident = (char *) slon_quote_identifier(SPI_fname(tupdesc, i + 1));
			col_value = slon_quote_literal(SPI_getvalue(old_row, tupdesc, i + 1));

			cmddata_need = (cp - (char *) (cs->cmddata_buf)) + 16 +
				(len_ident = strlen(col_ident)) +
				(len_value = strlen(col_value));
			if (cs->cmddata_size < cmddata_need)
			{
				int			have = (cp - (char *) (cs->cmddata_buf));

				while (cs->cmddata_size < cmddata_need)
					cs->cmddata_size *= 2;
				cs->cmddata_buf = realloc(cs->cmddata_buf, cs->cmddata_size);
				cp = (char *) (cs->cmddata_buf) + have;
			}

			memcpy(cp, col_ident, len_ident);
			cp += len_ident;
			*cp++ = '=';
			memcpy(cp, col_value, len_value);
			cp += len_value;
		}

		*cp++ = ' ';
		*cp++ = 'w';
		*cp++ = 'h';
		*cp++ = 'e';
		*cp++ = 'r';
		*cp++ = 'e';
		*cp++ = ' ';

		for (i = 0, attkind_idx = -1; i < tg->tg_relation->rd_att->natts; i++)
		{
			/*
			 * Ignore dropped columns
			 */
			if (tupdesc->attrs[i]->attisdropped)
				continue;

			attkind_idx++;
			if (!attkind[attkind_idx])
				break;
			if (attkind[attkind_idx] != 'k')
				continue;
			col_ident = (char *) slon_quote_identifier(SPI_fname(tupdesc, i + 1));
			col_value = slon_quote_literal(SPI_getvalue(old_row, tupdesc, i + 1));
			if (col_value == NULL)
				elog(ERROR, "Slony-I: old key column %s.%s IS NULL on UPDATE",
					 NameStr(tg->tg_relation->rd_rel->relname), col_ident);

			cmddata_need = (cp - (char *) (cs->cmddata_buf)) + 16 +
				(len_ident = strlen(col_ident)) +
				(len_value = strlen(col_value));
			if (cs->cmddata_size < cmddata_need)
			{
				int			have = (cp - (char *) (cs->cmddata_buf));

				while (cs->cmddata_size < cmddata_need)
					cs->cmddata_size *= 2;
				cs->cmddata_buf = realloc(cs->cmddata_buf, cs->cmddata_size);
				cp = (char *) (cs->cmddata_buf) + have;
			}

			if (need_and)
			{
				*cp++ = ' ';
				*cp++ = 'a';
				*cp++ = 'n';
				*cp++ = 'd';
				*cp++ = ' ';
			}
			else
				need_and = true;

			memcpy(cp, col_ident, len_ident);
			cp += len_ident;
			*cp++ = '=';
			memcpy(cp, col_value, len_value);
			cp += len_value;
		}
		*cp = '\0';
		SET_VARSIZE(cs->cmddata_buf,
					VARHDRSZ + (cp - VARDATA(cs->cmddata_buf)));
	}
	else if (TRIGGER_FIRED_BY_DELETE(tg->tg_event))
	{
		HeapTuple	old_row = tg->tg_trigtuple;
		TupleDesc	tupdesc = tg->tg_relation->rd_att;
		char	   *col_ident;
		char	   *col_value;
		int			len_ident;
		int			len_value;
		int			i;
		int			need_and = false;
		char	   *cp = VARDATA(cs->cmddata_buf);

		/*
		 * DELETE
		 *
		 * cmdtype = 'D' cmddata = "pk_ident"='value' [and ...]
		 */
		cmdtype = cs->cmdtype_D;

		for (i = 0, attkind_idx = -1; i < tg->tg_relation->rd_att->natts; i++)
		{
			if (tupdesc->attrs[i]->attisdropped)
				continue;

			attkind_idx++;
			if (!attkind[attkind_idx])
				break;
			if (attkind[attkind_idx] != 'k')
				continue;
			col_ident = (char *) slon_quote_identifier(SPI_fname(tupdesc, i + 1));
			col_value = slon_quote_literal(SPI_getvalue(old_row, tupdesc, i + 1));
			if (col_value == NULL)
				elog(ERROR, "Slony-I: old key column %s.%s IS NULL on DELETE",
					 NameStr(tg->tg_relation->rd_rel->relname), col_ident);

			cmddata_need = (cp - (char *) (cs->cmddata_buf)) + 16 +
				(len_ident = strlen(col_ident)) +
				(len_value = strlen(col_value));
			if (cs->cmddata_size < cmddata_need)
			{
				int			have = (cp - (char *) (cs->cmddata_buf));

				while (cs->cmddata_size < cmddata_need)
					cs->cmddata_size *= 2;
				cs->cmddata_buf = realloc(cs->cmddata_buf, cs->cmddata_size);
				cp = (char *) (cs->cmddata_buf) + have;
			}

			if (need_and)
			{
				*cp++ = ' ';
				*cp++ = 'a';
				*cp++ = 'n';
				*cp++ = 'd';
				*cp++ = ' ';
			}
			else
				need_and = true;

			memcpy(cp, col_ident, len_ident);
			cp += len_ident;
			*cp++ = '=';
			memcpy(cp, col_value, len_value);
			cp += len_value;
		}
		*cp = '\0';
		SET_VARSIZE(cs->cmddata_buf,
					VARHDRSZ + (cp - VARDATA(cs->cmddata_buf)));
	}
	else
		elog(ERROR, "Slony-I: logTrigger() fired for unhandled event");

	/*
	 * Construct the parameter array and insert the log row.
	 */
	argv[0] = Int32GetDatum(tab_id);
	argv[1] = PointerGetDatum(cmdtype);
	argv[2] = PointerGetDatum(cs->cmddata_buf);
	SPI_execp(cs->plan_active_log, argv, NULL, 0);

	SPI_finish();
	return PointerGetDatum(NULL);
}
/*
 *	This routine loads a previous postmaster dump of its non-default
 *	settings.
 */
void
read_nondefault_variables(void)
{
	FILE	   *fp;
	char	   *varname,
			   *varvalue,
			   *varsourcefile;
	int			varsourceline;
	GucSource	varsource;
	GucContext	varscontext;

	/*
	 * Assert that PGC_BACKEND/PGC_SU_BACKEND case in set_config_option() will
	 * do the right thing.
	 */
	Assert(IsInitProcessingMode());

	/*
	 * Open file
	 */
	fp = AllocateFile(CONFIG_EXEC_PARAMS, "r");
	if (!fp)
	{
		/* File not found is fine */
		if (errno != ENOENT)
			ereport(FATAL,
					(errcode_for_file_access(),
					 errmsg("could not read from file \"%s\": %m",
							CONFIG_EXEC_PARAMS)));
		return;
	}

	for (;;)
	{
		struct config_generic *record;

		if ((varname = read_string_with_null(fp)) == NULL)
			break;

		if ((record = find_option(varname, true, FATAL)) == NULL)
			elog(FATAL, "failed to locate variable \"%s\" in exec config params file", varname);

		if ((varvalue = read_string_with_null(fp)) == NULL)
			elog(FATAL, "invalid format of exec config params file");
		if ((varsourcefile = read_string_with_null(fp)) == NULL)
			elog(FATAL, "invalid format of exec config params file");
		if (fread(&varsourceline, 1, sizeof(varsourceline), fp) != sizeof(varsourceline))
			elog(FATAL, "invalid format of exec config params file");
		if (fread(&varsource, 1, sizeof(varsource), fp) != sizeof(varsource))
			elog(FATAL, "invalid format of exec config params file");
		if (fread(&varscontext, 1, sizeof(varscontext), fp) != sizeof(varscontext))
			elog(FATAL, "invalid format of exec config params file");

		(void) set_config_option(varname, varvalue,
								 varscontext, varsource,
								 GUC_ACTION_SET, true, 0, true);
		if (varsourcefile[0])
			set_config_sourcefile(varname, varsourcefile, varsourceline);

		free(varname);
		free(varvalue);
		free(varsourcefile);
	}

	FreeFile(fp);
}
Exemple #10
0
/* Parse a single option. */
static
error_t parse_opt(int key, char *arg, struct argp_state *state)
{
    struct args *argsp = state->input;
    struct poldek_ctx *ctx = argsp->ctx;
    struct poldek_ts *ts = argsp->ts;
//    if (key && arg)
//        chkarg(key, arg);

    switch (key) {
        case ARGP_KEY_INIT:
            {
                int i = 0;
                for (i=0; i < n_array_size(argsp->opgroup_rts); i++) 
                    state->child_inputs[i] = n_array_nth(argsp->opgroup_rts, i);
            }
            break;

        case OPT_LOG:
            poldek_configure(ctx, POLDEK_CONF_LOGFILE, arg);
            break;

        case OPT_CACHEDIR:
            poldek_configure(ctx, POLDEK_CONF_CACHEDIR, arg);
            if (!poldek_setup_cachedir(argsp->ctx)) /* set up immediately */
                exit(EXIT_FAILURE);
            break;

        case 'c':
            logn(LOGNOTICE, _("-c is depreciated, use --conf instead"));
                                /* no break */
        case OPT_CONF:
            args.path_conf = n_strdup(arg);
            break;

        case OPT_UPCONF:
            argsp->cnflags |= OPT_AS_FLAG(OPT_UPCONF);
            break;
            
        case 'q':
            poldek_set_verbose(-1);
            break;

        case OPT_SHCMD:
            DBGF("cmd\n");
            argsp->mode = RUNMODE_APT;
            break;
            
        case 'v':
            poldek_set_verbose(poldek_VERBOSE + 1);
            break;

        case OPT_NOCONF:
            argsp->cnflags |= OPT_AS_FLAG(OPT_NOCONF);
            break;
            
        case OPT_ASK:
            poldek_configure(ctx, POLDEK_CONF_OPT, POLDEK_OP_CONFIRM_INST, 1);
            poldek_configure(ctx, POLDEK_CONF_OPT, POLDEK_OP_CONFIRM_UNINST, 1);
            poldek_configure(ctx, POLDEK_CONF_OPT, POLDEK_OP_EQPKG_ASKUSER, 1);
            break;

        case OPT_NOASK:
            argsp->cnflags |= OPT_AS_FLAG(OPT_NOASK);
            poldek_configure(ctx, POLDEK_CONF_OPT, POLDEK_OP_CONFIRM_INST, 0);
            poldek_configure(ctx, POLDEK_CONF_OPT, POLDEK_OP_CONFIRM_UNINST, 0);
            poldek_configure(ctx, POLDEK_CONF_OPT, POLDEK_OP_EQPKG_ASKUSER, 0);
            break;

        case OPT_RUNAS:         /* ignored, catched at startup */
            break;

        case OPT_SHELL:         /* default */
            argsp->mjrmode = MODE_SHELL;
            argsp->cnflags |= OPT_AS_FLAG(OPT_SHELL);
            break;
            
        case OPT_SHELL_CMD:
            argsp->shcmd = arg;
            argsp->mjrmode = MODE_SHELL;
            argsp->cnflags |= OPT_AS_FLAG(OPT_SHELL);
            break;

        case 'f':
            logn(LOGWARN, "-f is obsoleted, use --skip-installed instead");
                                /* no break */
        case OPT_SKIPINSTALLED:
            argsp->cnflags |= OPT_AS_FLAG(OPT_SKIPINSTALLED);
            argsp->cctx->flags |= POCLIDEK_SKIP_INSTALLED;
            break;

        case OPT_PM:
            poldek_configure(ctx, POLDEK_CONF_PM, arg);
            break;            

        case OPT_PMCMD_ALIAS:
        case OPT_PMCMD:
            set_config_option(argsp, "pm command", arg);
            break;

        case OPT_SUDOCMD:
            set_config_option(argsp, "sudo command", arg);
            break;

        case OPT_BANNER:
            msgn(-1, "%s", poldek_BANNER);
            exit(EXIT_SUCCESS);
            break;

        case OPT_OPTION:
            if (argsp->addon_cnflines == NULL)
                argsp->addon_cnflines = n_array_new(8, free, NULL);
            n_array_push(argsp->addon_cnflines, n_strdup(arg));
            break;

        case OPT_DOCB:
            argsp->cnflags |= OPT_AS_FLAG(OPT_DOCB);
            break;
            
        case 'G':               /* XXX have no idea why this case from install.c
                                   does not work */
            ts->setop(ts, POLDEK_OP_GREEDY, 1);
            break;

        case OPT_NOPROGRESS:
    	    ts->setop(ts, POLDEK_OP_PROGRESS_NONE, 1);
    	    poldek_configure(ctx, POLDEK_CONF_PROGRESS, arg);
    	    break;

        case ARGP_KEY_ARG:
            DBGF("main.arg %s, mode = %d\n", arg, argsp->mode);
            if (argsp->mode == RUNMODE_APT) {
                argsp->argv[argsp->argc++] = arg;

                while (state->next < state->argc) {
                    char *arg = state->argv[state->next++];
                    argsp->argv[argsp->argc++] = arg;
                    DBGF("eatarg (%s)\n", arg);
                }
                argsp->argv[argsp->argc] = NULL;
                n_assert(state->next = state->argc);
                break;
            }
            /* apt => no break */
            
        default:
            return ARGP_ERR_UNKNOWN;
            break;
    }
    
    return 0;
}
ActivityConfigScreensaverView::ActivityConfigScreensaverView(Evas *_e, Evas_Object *_parent):
        ActivityView(_e, _parent, "calaos/page/config/screensaver")
{
        EdjeObject *slider;

        setPartText("tab1.text", _("Configure Touch Screen"));
        setPartText("tab1.text.detail", _("Resume : <light_blue>Touch Screen</light_blue><br><small>Configure your Touch Screen !</small>"));
        setPartText("tab2.text", _("About"));
        setPartText("tab2.text.detail", _("About : <light_blue>Calaos products</light_blue><br><small>Touchscreen solutions.</small>"));

        setPartText("module_screen", _("Configure power management settings"));
        setPartText("module_screen_desc", _("Enable if you want to activate automatic screen blanking and the delay after wich the screen will be turned off. You can also ask for a password when the screen is turned on again."));
        setPartText("tab1.title_icon", _("TouchScreen"));
        setPartText("tab1.subtitle_icon", _("TouchScreen configuration."));
        setPartText("tab2.web.label", _("Web Site : "));
        setPartText("tab2.web", CALAOS_WEBSITE_URL);
        setPartText("tab2.mail.label", _("Email : "));
        setPartText("tab2.mail", CALAOS_CONTACT_EMAIL);
        setPartText("tab2.copyright", CALAOS_COPYRIGHT_TEXT);

        setPartText("module_screen_time_desc", _("Time before screensaver activation : "));
        setPartText("module_screen suspend_desc", _("Enable screen saver : "));

        // Create a new slider for the DPMS standby option
        slider = new EdjeObject(ApplicationMain::getTheme(), evas);
        slider->setAutoDelete(true);
        
        double slider_val;
        string option_val;

        option_val = get_config_option("dpms_standby");
        from_string(option_val, slider_val);


        setPartText("module_screen_time_value", to_string((int)(slider_val / 60.0)) + _(" minutes"));

        slider->addCallback("object", "*",
                            [=](void *data, Evas_Object *edje_object, string emission, string source) 
                            {
                                    // Change value on screen when slider move
                                    if (emission == "slider,move")
                                    {
                                            double x;
                                            string val;

                                            slider->getDragValue("slider", &x, NULL);
                                            val = to_string((int)(x * DPMS_STANDBY_MAX_VALUE)) +  _(" minutes");
                                            setPartText("module_screen_time_value", val);
                                    }
                                    // Set new value in local_config.xml when slider,changed is received 
                                    else if (emission == "slider,changed")
                                    {
                                            double x;
                                            
                                            slider->getDragValue("slider", &x, NULL);
                                            // Value is store in seconds
                                            set_config_option("dpms_standby", to_string((int)(x * 60.0 * DPMS_STANDBY_MAX_VALUE)));
                                    }
                                    
                            }
                );
        slider->LoadEdje("calaos/slider/horizontal/default");
        slider->Show();
        slider->setDragValue("slider", slider_val / 60.0 / DPMS_STANDBY_MAX_VALUE, slider_val / 60.0 / DPMS_STANDBY_MAX_VALUE);   
        Swallow(slider, "dpms_standby_slider.swallow", true);

        addCallback("object", "*", [=](void *data, Evas_Object *edje_object, string emission, string source) 
                            {
                                    printf("Emission : %s | Source : %s\n", emission.c_str(), source.c_str());
                            });

}