Example #1
0
int
show_config_gtmSlave(int flag, char *hostname)
{
	char lineBuf[MAXLINE+1];
	char editBuf[MAXPATH+1];

	if (!isVarYes(VAR_gtmSlave) || is_none(VAR_gtmSlaveServer))
	{
		elog(ERROR, "ERROR: gtm slave is not configured.\n");
		return 0;
	}
	lineBuf[0] = 0;
	if (flag)
		strncat(lineBuf, "GTM Slave: ", MAXLINE);
	if (hostname)
	{
		snprintf(editBuf, MAXPATH, "host: %s", hostname);
		strncat(lineBuf, editBuf, MAXLINE);
	}
	if (flag || hostname)
		strncat(lineBuf, "\n", MAXLINE);
	lockLogFile();
	elog(NOTICE, "%s", lineBuf);
	print_simple_node_info(sval(VAR_gtmName), sval(VAR_gtmSlavePort), sval(VAR_gtmSlaveDir),
						   sval(VAR_gtmExtraConfig), sval(VAR_gtmSlaveSpecificExtraConfig));
	unlockLogFile();
	return 0;
}
Example #2
0
/*
 * Please note that remote stdout is not in pgxc_ctl so far.  It will directly be written
 * to local stdout.
 */
char *createRemoteFileName(FileType type, char *buf, int len)
{
	char hostname[MAXPATH+1];
	/* 
	 * Filename is $TmpDir/hostname_type_serno.
	 */
	getCleanHostname(hostname, MAXPATH);
	switch (type)
	{
		case STDIN:
			snprintf(buf, len-1, "%s/%s_STDIN_%d_%d", sval(VAR_tmpDir), hostname, getpid(), file_sn++);
			break;
		case STDOUT:
			snprintf(buf, len-1, "%s/%s_STDOUT_%d_%d", sval(VAR_tmpDir), hostname, getpid(), file_sn++);
			break;
		case STDERR:
			snprintf(buf, len-1, "%s/%s_STDERR_%d_%d", sval(VAR_tmpDir), hostname, getpid(), file_sn++);
			break;
		case GENERAL:
			snprintf(buf, len-1, "%s/%s_GENERAL_%d_%d", sval(VAR_tmpDir), hostname, getpid(), file_sn++);
			break;
		default:
			return NULL;
	}
	return buf;
}
Example #3
0
TEST(Type, SpecificExamples) {
  // Random examples to stress option types, values, etc:

  EXPECT_TRUE(!TInt.subtypeOf(ival(1)));

  EXPECT_TRUE(TInitCell.couldBe(ival(1)));
  EXPECT_TRUE(TInitCell.subtypeOf(TGen));
  EXPECT_TRUE(ival(2).subtypeOf(TInt));
  EXPECT_TRUE(!ival(2).subtypeOf(TBool));
  EXPECT_TRUE(ival(3).subtypeOf(TOptInt));
  EXPECT_TRUE(TInt.subtypeOf(TOptInt));
  EXPECT_TRUE(!TBool.subtypeOf(TOptInt));
  EXPECT_TRUE(TInitNull.subtypeOf(TOptInt));
  EXPECT_TRUE(!TNull.subtypeOf(TOptInt));
  EXPECT_TRUE(TNull.couldBe(TOptInt));
  EXPECT_TRUE(TNull.couldBe(TOptBool));

  EXPECT_TRUE(TInitNull.subtypeOf(TInitCell));
  EXPECT_TRUE(TInitNull.subtypeOf(TCell));
  EXPECT_TRUE(!TUninit.subtypeOf(TInitNull));

  EXPECT_TRUE(ival(3).subtypeOf(TOptInt));
  EXPECT_TRUE(ival(3).subtypeOf(opt(ival(3))));
  EXPECT_TRUE(ival(3).couldBe(opt(ival(3))));
  EXPECT_TRUE(ival(3).couldBe(TInt));
  EXPECT_TRUE(TInitNull.couldBe(opt(ival(3))));
  EXPECT_TRUE(TNull.couldBe(opt(ival(3))));
  EXPECT_TRUE(TInitNull.subtypeOf(opt(ival(3))));
  EXPECT_TRUE(!TNull.subtypeOf(opt(ival(3))));

  EXPECT_EQ(TStr, union_of(sval(s_test.get()), TCStr));
  EXPECT_EQ(TStr, union_of(TCStr, sval(s_test.get())));

  EXPECT_EQ(TGen, union_of(TRef, TUninit));
}
Example #4
0
int checkDirConflict(char *host, char *dir)
{
	int ii;

	/* GTM Master */
	if ((strcasecmp(host, sval(VAR_gtmMasterServer)) == 0) && (strcmp(dir, sval(VAR_gtmMasterDir)) == 0))
		return 1;
	/* GTM Slave */
	if (isVarYes(VAR_gtmSlave) && (strcasecmp(host, sval(VAR_gtmSlaveServer)) == 0) && (strcmp(dir, sval(VAR_gtmSlaveDir)) == 0))
		return 1;
	/* GTM Proxy */
	if (isVarYes(VAR_gtmProxy))
		for (ii = 0; aval(VAR_gtmProxyNames)[ii]; ii++)
			if ((strcasecmp(host, aval(VAR_gtmProxyServers)[ii]) == 0) && (strcmp(dir, aval(VAR_gtmProxyDirs)[ii]) == 0))
				return 1;
	/* Coordinator Master */
	for (ii = 0; aval(VAR_coordNames)[ii]; ii++)
		if ((strcasecmp(host, aval(VAR_coordMasterServers)[ii]) == 0) && (strcmp(dir, aval(VAR_coordMasterDirs)[ii]) == 0))
			return 1;
	/* Coordinator Slave */
	if (isVarYes(VAR_coordSlave))
		for (ii = 0; aval(VAR_coordNames)[ii]; ii++)
			if ((strcasecmp(host, aval(VAR_coordSlaveServers)[ii]) == 0) && (strcmp(dir, aval(VAR_coordSlaveDirs)[ii]) == 0))
				return 1;
	/* Datanode Master */
	for (ii = 0; aval(VAR_datanodeNames)[ii]; ii++)
		if ((strcasecmp(host, aval(VAR_datanodeMasterServers)[ii]) == 0) && (strcmp(dir, aval(VAR_datanodeMasterDirs)[ii]) == 0))
			return 1;
	/* Datanode Slave */
	if (isVarYes(VAR_datanodeSlave))
		if (doesExist(VAR_datanodeSlaveServers, ii) && doesExist(VAR_datanodeSlaveDirs, ii) &&
			(strcasecmp(host, aval(VAR_datanodeSlaveServers)[ii]) == 0) && (strcmp(dir, aval(VAR_datanodeSlaveDirs)[ii]) == 0))
			return 1;
	return 0;
}
Example #5
0
static GTM_Conn *connectGTM()
{
	char connect_str[MAXLINE+1];

	/* Use 60s as connection timeout */
	snprintf(connect_str, MAXLINE, "host=%s port=%d node_name=%s remote_type=%d postmaster=0 connect_timeout=60",
			 sval(VAR_gtmMasterServer), atoi(sval(VAR_gtmMasterPort)), (myname == NULL) ? DefaultName : myname, GTM_NODE_COORDINATOR);
	return(PQconnectGTM(connect_str));
}
Example #6
0
static void build_configuration_path(char *path)
{
	struct stat statbuf;
	int rr;

	if (path)
		reset_var_val(VAR_configFile, path);
	if (!find_var(VAR_configFile) || !sval(VAR_configFile) || (sval(VAR_configFile)[0] == 0))
	{
		/* Default */
		snprintf(pgxc_ctl_config_path, MAXPATH, "%s/%s", pgxc_ctl_home, DEFAULT_CONF_FILE_NAME);
		rr = stat(pgxc_ctl_config_path, &statbuf);
		if (rr || !S_ISREG(statbuf.st_mode))
		{
			/* No configuration specified and the default does not apply --> simply ignore */
			elog(ERROR, "ERROR: Default configuration file \"%s\" was not found while no configuration file was specified\n", 
				pgxc_ctl_config_path);
			pgxc_ctl_config_path[0] = 0;

			/* Read prototype config file if no default config file found */
			install_pgxc_ctl_bash(pgxc_ctl_bash_path, true);
			return;
		}
	}
		else if (sval(VAR_configFile)[0]  == '/')
	{
		/* Absolute path */
		strncpy(pgxc_ctl_config_path, sval(VAR_configFile), MAXPATH);
	}
	else
	{
		/* Relative path from $pgxc_ctl_home */
		snprintf(pgxc_ctl_config_path, MAXPATH, "%s/%s", pgxc_ctl_home, sval(VAR_configFile));
	}
	rr = stat(pgxc_ctl_config_path, &statbuf);
	if (rr || !S_ISREG(statbuf.st_mode))
	{
		if (rr)
			elog(ERROR, "ERROR: File \"%s\" not found or not a regular file. %s\n", 
					 pgxc_ctl_config_path, strerror(errno));
		else
			elog(ERROR, "ERROR: File \"%s\" not found or not a regular file", 
					 pgxc_ctl_config_path);
		/* Read prototype config file if no config file found */
		install_pgxc_ctl_bash(pgxc_ctl_bash_path, true);
	}
	else
	{
		/* 
		 * Since we found a valid config file, don't read the prototype config
		 * file as it may conflict with the user conf file
		 */
		install_pgxc_ctl_bash(pgxc_ctl_bash_path, false);
	}
	return;
}
Example #7
0
/*
 * Stop gtm master ---------------------------------------------------------
 */
static cmd_t *
prepare_stopGtmMaster(void)
{
	cmd_t *cmdGtmCtl;

	cmdGtmCtl = initCmd(sval(VAR_gtmMasterServer));
	snprintf(newCommand(cmdGtmCtl), MAXLINE,
			 "gtm_ctl stop -Z gtm -D %s",
			 sval(VAR_gtmMasterDir));
	return(cmdGtmCtl);
}
Example #8
0
/* localStdout has to be set by the caller */
int doCmdEl(cmd_t *cmd)
{
	if (cmd->isInternal)
	{
		if (*cmd->callback)
			(*cmd->callback)(cmd->callback_parm);
		else
			elog(ERROR, "ERROR: no function entry was found in cmd_t.\n");
		freeAndReset(cmd->callback_parm);
		return 0;
	}
	if (cmd->host)
	{
		/* Build actual command */
		snprintf(allocActualCmd(cmd), MAXLINE,
				 "ssh %s@%s \"( %s ) > %s 2>&1\" < %s > /dev/null 2>&1",
				 sval(VAR_pgxcUser),
				 cmd->host,
				 cmd->command,
				 cmd->remoteStdout ? cmd->remoteStdout : "/dev/null",
				 cmd->localStdin ? cmd->localStdin : "/dev/null");
		/* Do it */
		elog(DEBUG1, "Remote command: \"%s\", actual: \"%s\"\n", cmd->command, cmd->actualCmd);
		cmd->excode = system(cmd->actualCmd);
		/* Handle stdout */
		clearStdin(cmd);
		touchStdout(cmd);
		doImmediateRaw("(scp %s@%s:%s %s; ssh %s@%s rm -rf %s) < /dev/null > /dev/null",
					   sval(VAR_pgxcUser), cmd->host, cmd->remoteStdout, cmd->localStdout,
					   sval(VAR_pgxcUser), cmd->host, cmd->remoteStdout);
		freeAndReset(cmd->remoteStdout);
		/* Handle stdin */
		return (cmd->excode);
	}
	else
	{
		freeAndReset(cmd->remoteStdout);
		/* Build actual command */
		snprintf(allocActualCmd(cmd), MAXLINE,
				 "( %s ) > %s 2>&1 < %s",
				 cmd->command,
				 cmd->localStdout ? cmd->localStdout : "/dev/null",
				 cmd->localStdin ? cmd->localStdin : "/dev/null");
		/* Do it */
		elog(DEBUG1, "Local command: \"%s\", actual: \"%s\"\n", cmd->command, cmd->actualCmd);
		cmd->excode = system(cmd->actualCmd);
		/* Handle stdout */
		clearStdin(cmd);
		touchStdout(cmd);
		/* Handle stdin */
		return (cmd->excode);
	}
}
Example #9
0
int
remove_gtmSlave(bool clean_opt)
{
	FILE *f;

	/* Check if gtm_slave is configured */
	if (!isVarYes(VAR_gtmSlave) || !sval(VAR_gtmSlaveServer) || is_none(sval(VAR_gtmSlaveServer)))
	{
		elog(ERROR, "ERROR: GTM slave is not configured.\n");
		return 1;
	}
	/* Check if gtm_slave is not running */
	if (!do_gtm_ping(sval(VAR_gtmSlaveServer), atoi(sval(VAR_gtmSlavePort))))
	{
		elog(ERROR, "ERROR: GTM slave is now running. Cannot remove it.\n");
		return 1;
	}
	elog(NOTICE, "Removing gtm slave.\n");
	/* Clean */
	if (clean_opt)
		clean_gtm_slave();
	/* Reconfigure */
	reset_var(VAR_gtmSlave);
	assign_sval(VAR_gtmSlave, Strdup("n"));
	reset_var(VAR_gtmSlaveServer);
	assign_sval(VAR_gtmSlaveServer, Strdup("none"));
	reset_var(VAR_gtmSlavePort);
	assign_sval(VAR_gtmSlavePort, Strdup("-1"));
	reset_var(VAR_gtmSlaveDir);
	assign_sval(VAR_gtmSlaveDir, Strdup("none"));
	/* Write the configuration file and bakup it */
	if ((f = fopen(pgxc_ctl_config_path, "a")) == NULL)
	{
		/* Should it be panic? */
		elog(ERROR, "ERROR: cannot open configuration file \"%s\", %s\n", pgxc_ctl_config_path, strerror(errno));
		return 1;
	}
	fprintf(f, 
			"#===================================================\n"
			"# pgxc configuration file updated due to GTM slave removal\n"
			"#        %s\n",
			timeStampString(date, MAXTOKEN+1));
	fprintSval(f, VAR_gtmSlave);
	fprintSval(f, VAR_gtmSlaveServer);
	fprintSval(f, VAR_gtmSlavePort);
	fprintSval(f, VAR_gtmSlaveDir);
	fprintf(f, "%s", "#----End of reconfiguration -------------------------\n");
	fclose(f);
	backup_configuration();
	elog(NOTICE, "Done.\n");
	return 0;
}
Example #10
0
/*
 * Clean gtm master resources -- directory and socket --------------------------
 */
cmd_t *
prepare_cleanGtmMaster(void)
{
	cmd_t *cmd;

	/* Remote work dir and clean the socket */
	cmd = initCmd(sval(VAR_gtmMasterServer));
	snprintf(newCommand(cmd), MAXLINE, 
			 "rm -rf %s; mkdir -p %s; chmod 0700 %s;rm -f /tmp/.s.*%d*",
			 sval(VAR_gtmMasterDir), sval(VAR_gtmMasterDir), sval(VAR_gtmMasterDir),
			 atoi(VAR_gtmMasterPort));
	return cmd;
}
Example #11
0
/*
 * Start gtm master -----------------------------------------------------
 */
static cmd_t *
prepare_startGtmMaster(void)
{
	cmd_t *cmdGtmCtl;

	cmdGtmCtl = initCmd(sval(VAR_gtmMasterServer));
	snprintf(newCommand(cmdGtmCtl), MAXLINE, 
			 "gtm_ctl stop -Z gtm -D %s;"
			 "rm -f %s/register.node;"
			 "gtm_ctl start -Z gtm -D %s",
			 sval(VAR_gtmMasterDir), sval(VAR_gtmMasterDir), sval(VAR_gtmMasterDir));
	return cmdGtmCtl;
}
Example #12
0
/*
 * Null will be retruend if gtm slave is not configured.
 * Be careful.   If you configure gtm slave and gtm master on a same server,
 * bott slave amd master process will be killed.
 */
cmd_t *
prepare_cleanGtmSlave(void)
{
	cmd_t *cmd;
	
	if (!isVarYes(VAR_gtmSlave) || is_none(VAR_gtmSlaveServer))
		return(NULL);
	cmd = initCmd(sval(VAR_gtmSlaveServer));
	snprintf(newCommand(cmd), MAXLINE,
			 "rm -rf %s; mkdir -p %s; chmod 0700 %s;rm -f /tmp/.s.*%d*",
			 sval(VAR_gtmSlaveDir), sval(VAR_gtmSlaveDir), sval(VAR_gtmMasterDir),
			 atoi(VAR_gtmSlavePort));
	return cmd;
}
Example #13
0
int doImmediate(char *host, char *stdIn, const char *cmd_fmt, ...)
{
	char cmd_wk[MAXLINE+1];
	char actualCmd[MAXLINE+1];
	char remoteStdout[MAXPATH+1];
	char localStdout[MAXPATH+1];
	va_list arg;
	int rc;

	va_start(arg, cmd_fmt);
	vsnprintf(cmd_wk, MAXLINE, cmd_fmt, arg);
	va_end(arg);
	if (host == NULL || host[0] == '\0')
	{
		/* Local case */
		snprintf(actualCmd, MAXLINE, "( %s ) < %s > %s 2>&1",
				 cmd_wk,
				 ((stdIn == NULL) || (stdIn[0] == 0)) ? "/dev/null" : stdIn,
				 createLocalFileName(STDOUT, localStdout, MAXPATH));
		elog(DEBUG1, "Actual command: %s\n", actualCmd);
		rc = system(actualCmd);
	}
	else
	{
		int rc1;
		/* Remote case */
		snprintf(actualCmd, MAXLINE, "ssh %s@%s \"( %s ) > %s 2>&1\" < %s > /dev/null 2>&1",
				 sval(VAR_pgxcUser), host, cmd_wk, 
				 createRemoteFileName(STDOUT, remoteStdout, MAXPATH),
				 ((stdIn == NULL) || (stdIn[0] == 0)) ? "/dev/null" : stdIn);
		elog(INFO, "Actual Command: %s\n", actualCmd);
		rc = system(actualCmd);
		snprintf(actualCmd, MAXLINE, "scp %s@%s:%s %s > /dev/null 2>&1",
				 sval(VAR_pgxcUser), host, remoteStdout,
				 createLocalFileName(STDOUT, localStdout, MAXPATH));
		elog(INFO, "Bring remote stdout: %s\n", actualCmd);
		rc1 = system(actualCmd);
		if (WEXITSTATUS(rc1) != 0)
			elog(WARNING, "WARNING: Stdout transfer not successful, file: %s:%s->%s\n",
				 host, remoteStdout, localStdout);
		doImmediateRaw("ssh %s@%s \"rm -f %s < /dev/null > /dev/null\" < /dev/null > /dev/null",
					   sval(VAR_pgxcUser), host, remoteStdout);
	}
	elogFile(INFO, localStdout);
	unlink(localStdout);
	if (stdIn && stdIn[0])
		unlink(stdIn);
	return((rc));
}
Example #14
0
/*
 * We rely on the PID file created in Postgres/GTM et al data directory to
 * fetch the PID. The first line in these respective files has the PID.
 */
pid_t get_prog_pid(char *host, char *pidfile, char *dir)
{
	char cmd[MAXLINE+1];
	char pid_s[MAXLINE+1];
	FILE *wkf;

	snprintf(cmd, MAXLINE,
			 "ssh %s@%s "
			 "\"cat %s/%s.pid\"",
			 sval(VAR_pgxcUser), host, dir, pidfile);
	wkf = popen(cmd, "r");
	if (wkf == NULL)
	{
		elog(ERROR, "ERROR: cannot obtain pid value of the remote server process, host \"%s\" dir \"%s\", %s\n",
					host, dir, strerror(errno));
		return(-1);
	}

	if (fgets(pid_s, MAXLINE, wkf) == NULL)
	{
		elog(ERROR, "ERROR: fgets failed to get pid of remote server process, host \"%s\" dir \"%s\", %d\n",
					host, dir, ferror(wkf));
		pclose(wkf);
		return(-1);
	}

	pclose(wkf);
	return(atoi(pid_s));
}
Example #15
0
FuncAnalysis do_analyze(const Index& index,
                        Context const inputCtx,
                        ClassAnalysis* clsAnalysis,
                        const std::vector<Type>* knownArgs,
                        CollectionOpts opts) {
  auto const ctx = adjust_closure_context(inputCtx);
  CollectedInfo collect {
    index, ctx, clsAnalysis, nullptr, opts
  };

  auto ret = do_analyze_collect(index, ctx, collect, clsAnalysis, knownArgs);
  if (ctx.func->name == s_86cinit.get() && !knownArgs) {
    // We need to try to resolve any dynamic constants
    size_t idx = 0;
    for (auto const& c : ctx.cls->constants) {
      if (c.val && c.val->m_type == KindOfUninit) {
        auto const fa = analyze_func_inline(index, ctx, { sval(c.name) });
        if (auto const val = tv(fa.inferredReturn)) {
          ret.resolvedConstants.emplace_back(idx, *val);
        }
      }
      ++idx;
    }
  }
  return ret;
}
Example #16
0
/*
 * Stop gtm slave ---------------------------------------------------------------
 */
static cmd_t *
prepare_stopGtmSlave(void)
{
	cmd_t *cmdGtmCtl;

	if (!isVarYes(VAR_gtmSlave) || (sval(VAR_gtmSlaveServer) == NULL) || is_none(sval(VAR_gtmSlaveServer)))
	{
		elog(ERROR, "ERROR: GTM slave is not configured.\n");
		return(NULL);
	}
	cmdGtmCtl = initCmd(sval(VAR_gtmSlaveServer));
	snprintf(newCommand(cmdGtmCtl), MAXLINE,
			 "gtm_ctl stop -Z gtm -D %s",
			 sval(VAR_gtmSlaveDir));
	return(cmdGtmCtl);
}
Example #17
0
int
show_config_gtmProxy(int flag, int idx, char *hostname)
{
	char lineBuf[MAXLINE+1];
	char editBuf[MAXPATH+1];

	lineBuf[0] = 0;
	if (flag)
		strncat(lineBuf, "GTM Proxy: ", MAXLINE);
	if (hostname)
	{
		snprintf(editBuf, MAXPATH, "host: %s", hostname);
		strncat(lineBuf, editBuf, MAXLINE);
	}
	if (flag || hostname)
		strncat(lineBuf, "\n", MAXLINE);
	lockLogFile();
	if (lineBuf[0])
		elog(NOTICE, "%s", lineBuf);
	print_simple_node_info(aval(VAR_gtmProxyNames)[idx], aval(VAR_gtmProxyPorts)[idx],
						   aval(VAR_gtmProxyDirs)[idx], sval(VAR_gtmPxyExtraConfig),
						   aval(VAR_gtmPxySpecificExtraConfig)[idx]);
	unlockLogFile();
	return 0;
}
Example #18
0
std::unique_ptr<Value>
FunctionValueNode::getValue(std::unique_ptr<Value> val) const
{
    switch (val->getType()) {
        case Value::String:
        {
            StringValue& sval(static_cast<StringValue&>(*val));
            if (_function == LOWERCASE) {
                return std::unique_ptr<Value>(new StringValue(
                    vespalib::LowerCase::convert(sval.getValue())));
            } else if (_function == HASH) {
                return std::unique_ptr<Value>(new IntegerValue(
                    hash(sval.getValue().c_str(), sval.getValue().size()),
                    false));
            }
            break;
        }
        case Value::Float:
        {
            FloatValue& fval(static_cast<FloatValue&>(*val));
            if (_function == HASH) {
                FloatValue::ValueType ffval = fval.getValue();
                return std::unique_ptr<Value>(new IntegerValue(
                    hash(&ffval, sizeof(ffval)), false));
            } else if (_function == ABS) {
                FloatValue::ValueType ffval = fval.getValue();
                if (ffval < 0) ffval *= -1;
                return std::unique_ptr<Value>(new FloatValue(ffval));
            }
            break;
        }
        case Value::Integer:
        {
            IntegerValue& ival(static_cast<IntegerValue&>(*val));
            if (_function == HASH) {
                IntegerValue::ValueType iival = ival.getValue();
                return std::unique_ptr<Value>(new IntegerValue(
                    hash(&iival, sizeof(iival)), false));
            } else if (_function == ABS) {
                IntegerValue::ValueType iival = ival.getValue();
                if (iival < 0) iival *= -1;
                return std::unique_ptr<Value>(new IntegerValue(iival, false));
            }
            break;
        }
        case Value::Bucket:
        {
            throw ParsingFailedException(
                    "No functioncalls are allowed on value of type bucket",
                    VESPA_STRLOC);
            break;
        }

        case Value::Array: break;
        case Value::Struct: break;
        case Value::Invalid: break;
        case Value::Null: break;
    }
    return std::unique_ptr<Value>(new InvalidValue);
}
Example #19
0
/*
 * Note that 1 will be returned when a conflict is found
 */
int checkNameConflict(char *name, int is_gtm)
{
	int ii;

	/*
	 * GTM Master
	 */
	if (!is_gtm && strcasecmp(name, sval(VAR_gtmName)) == 0)
		return 1;
	/*
	 * GTM Proxy
	 */
	if (isVarYes(VAR_gtmProxy))
		for (ii = 0; aval(VAR_gtmProxyNames)[ii]; ii++)
			if (strcasecmp(name, aval(VAR_gtmProxyNames)[ii]) == 0)
				return 1;
	/*
	 * Coordinator
	 */
	for (ii = 0; aval(VAR_coordNames)[ii]; ii++)
		if (strcasecmp(name, aval(VAR_coordNames)[ii]) == 0)
			return 1;
	/*
	 * Datanode
	 */
	for (ii = 0; aval(VAR_datanodeNames)[ii]; ii++)
		if (strcasecmp(name, aval(VAR_datanodeNames)[ii]) == 0)
			return 1;
	return 0;
}
Example #20
0
NodeType getNodeType(char *nodeName)
{
	int ii;

	/* Check GTM */
	if (strcmp(nodeName, sval(VAR_gtmName)) == 0)
		return NodeType_GTM;
	/* GTM_Proxy */
	for (ii = 0; aval(VAR_gtmProxyNames)[ii]; ii++)
		if (strcmp(nodeName, aval(VAR_gtmProxyNames)[ii]) == 0)
			return NodeType_GTM_PROXY;
	/* Coordinator */
	for (ii = 0; aval(VAR_coordNames)[ii]; ii++)
		if (strcmp(nodeName, aval(VAR_coordNames)[ii]) == 0)
			return NodeType_COORDINATOR;
	/* Datanode */
	for (ii = 0; aval(VAR_datanodeNames)[ii]; ii++)
		if (strcmp(nodeName, aval(VAR_datanodeNames)[ii]) == 0)
			return NodeType_DATANODE;
	/* Nodename */
	for (ii = 0; aval(VAR_allServers)[ii]; ii++)
		if (strcmp(nodeName, aval(VAR_allServers)[ii]) == 0)
			return NodeType_SERVER;
	return NodeType_UNDEF;

}
Example #21
0
void IniSetting::ParserCallback::onEntry(
    const std::string &key, const std::string &value, void *arg) {
  Variant *arr = (Variant*)arg;
  String skey(key);
  Variant sval(value);
  forceToArray(*arr).set(skey, sval);
}
  //------------------------------------------------------------------------------
  void FunMax::Eval(ptr_val_type &ret, const ptr_val_type *a_pArg, int a_iArgc)
  {
	  if (a_iArgc < 1)
		throw ParserError(ErrorContext(ecTOO_FEW_PARAMS, GetExprPos(), GetIdent()));

	float_type smax(-1e30), sval(0);
	for (int i=0; i<a_iArgc; ++i)
	{
	  switch(a_pArg[i]->GetType())
	  {
	  case 'f': sval = a_pArg[i]->GetFloat();   break;
	  case 'i': sval = a_pArg[i]->GetFloat(); break;
	  case 'n': break; // ignore not in list entries (missing parameter)
	  case 'c':
	  default:
		{
		  ErrorContext err;
		  err.Errc = ecTYPE_CONFLICT_FUN;
		  err.Arg = i+1;
		  err.Type1 = a_pArg[i]->GetType();
		  err.Type2 = 'f';
		  throw ParserError(err);
		}
	  }
	  smax = max(smax, sval);
	}

	*ret = smax;
  }
  /** \brief Returns the minimum value of all values.
	  \param a_pArg Pointer to an array of Values
	  \param a_iArgc Number of values stored in a_pArg
  */
  void FunMin::Eval(ptr_val_type &ret, const ptr_val_type *a_pArg, int a_iArgc)
  {
	  if (a_iArgc < 1)
		  throw ParserError(ErrorContext(ecTOO_FEW_PARAMS, GetExprPos(), GetIdent()));

	float_type smin(1e30), sval(smin);

	for (int i=0; i<a_iArgc; ++i)
	{
	  switch(a_pArg[i]->GetType())
	  {
	  case 'f':
	  case 'i': sval = a_pArg[i]->GetFloat();   break;
	  default:
		{
		  ErrorContext err;
		  err.Errc = ecTYPE_CONFLICT_FUN;
		  err.Arg = i+1;
		  err.Type1 = a_pArg[i]->GetType();
		  err.Type2 = 'f';
		  throw ParserError(err);
		}
	  }
	  smin = min(smin, sval);
	}

	*ret = smin;
  }
Example #24
0
/*
 * Please note that this function deeply depend upon
 * the environment.
 *
 * It works find with CentOS/Ubuntu/ReadHat Linux but
 * may need another tweak for other operation systems
 * such as Solaris, FreeBSD, MacOS.
 */
pid_t get_prog_pid(char *host, char *progname, char *dir)
{
	char cmd[MAXLINE+1];
	char pid_s[MAXLINE+1];
	int ii;
	FILE *wkf;
	char *token;
	char *line;

	snprintf(cmd, MAXLINE,
			 "ssh %s@%s "
			 "\"ps -f -C %s | grep %s\"",
			 sval(VAR_pgxcUser), host, progname, dir);
	wkf = popen(cmd, "r");
	if (wkf == NULL)
	{
		elog(ERROR, "ERROR: cannot obtain pid value of the remote postmaster, host \"%s\" dir \"%s\", %s\n",
					host, dir, strerror(errno));
		return(-1);
	}
	fgets(pid_s, MAXLINE, wkf);
	fclose(wkf);
	/* Get the second token */
	line = pid_s;
	if ((line = get_word(line, &token)) == NULL)
		return 0;
	get_word(line, &token);
	if (token == NULL)
		return 0;
	for (ii = 0; token[ii]; ii++)
		if (token[ii] < '0' || token[ii] > '9')
			return 0;
	return(atoi(token));
}
Example #25
0
static void checkIfVarIsConfigured(char *name)
{
	if (!find_var(name) || !sval(name))
	{
		anyConfigErrors = TRUE;
		reportMissingVar(name);
	}
}
Example #26
0
/*
 * Backup configuration files to a remote site as specified.
 */
int backup_configuration(void)
{
	if ((strcasecmp(sval(VAR_configBackup), "y") != 0) || is_none(sval(VAR_configBackupHost)) || 
		is_none(sval(VAR_configBackupDir)) || is_none(sval(VAR_configBackupFile)))
		return (2);
	return(doImmediate(NULL, NULL, "scp %s %s@%s:%s/%s",
					   pgxc_ctl_config_path,
					   sval(VAR_pgxcUser), sval(VAR_configBackupHost),
					   sval(VAR_configBackupDir), sval(VAR_configBackupFile)));
}
Example #27
0
// Save account_reg into sql (type=2)
int mapif_parse_Registry(int fd)
{
	int account_id = RFIFOL(fd, 4), char_id = RFIFOL(fd, 8), count = RFIFOW(fd, 12);

	if( count ) {
		int cursor = 14, i;
		bool isLoginActive = session_isActive(login_fd);

		if( isLoginActive )
			chlogif_upd_global_accreg(account_id,char_id);

		for(i = 0; i < count; i++) {
			size_t lenkey = RFIFOB( fd, cursor );
			const char* src_key= RFIFOCP(fd, cursor + 1);
			std::string key( src_key, lenkey );
			cursor += lenkey + 1;

			unsigned int  index = RFIFOL(fd, cursor);
			cursor += 4;

			switch (RFIFOB(fd, cursor++)) {
				// int
				case 0:
				{
					intptr_t lVal = RFIFOL( fd, cursor );
					inter_savereg( account_id, char_id, key.c_str(), index, lVal, false );
					cursor += 4;
					break;
				}
				case 1:
					inter_savereg(account_id,char_id,key.c_str(),index,0,false);
					break;
				// str
				case 2:
				{
					size_t len_val = RFIFOB( fd, cursor );
					const char* src_val= RFIFOCP(fd, cursor + 1);
					std::string sval( src_val, len_val );
					cursor += len_val + 1;
					inter_savereg( account_id, char_id, key.c_str(), index, (intptr_t)sval.c_str(), true );
					break;
				}
				case 3:
					inter_savereg(account_id,char_id,key.c_str(),index,0,true);
					break;
				default:
					ShowError("mapif_parse_Registry: unknown type %d\n",RFIFOB(fd, cursor - 1));
					return 1;
			}

		}

		if (isLoginActive)
			chlogif_prepsend_global_accreg();
	}
	return 0;
}
Example #28
0
static void setDefaultIfNeeded(char *name, char *val)
{
	if (!find_var(name) || !sval(name))
	{
		if (val)
			reset_var_val(name, val);
		else
			reset_var(name);
	}
}
Example #29
0
TEST(Type, OptUnionOf) {
  EXPECT_EQ(opt(ival(2)), union_of(ival(2), TInitNull));
  EXPECT_EQ(opt(dval(2.0)), union_of(TInitNull, dval(2.0)));
  EXPECT_EQ(opt(sval(s_test.get())), union_of(sval(s_test.get()), TInitNull));
  EXPECT_EQ(opt(sval(s_test.get())), union_of(TInitNull, sval(s_test.get())));

  EXPECT_EQ(TOptBool, union_of(TOptFalse, TOptTrue));
  EXPECT_EQ(TOptBool, union_of(TOptTrue, TOptFalse));

  EXPECT_EQ(TOptCArr, union_of(TCArr, TInitNull));
  EXPECT_EQ(TOptCArr, union_of(TInitNull, TCArr));
  EXPECT_EQ(TOptSArr, union_of(TInitNull, TOptSArr));
  EXPECT_EQ(TOptSArr, union_of(TOptSArr, TInitNull));
  EXPECT_EQ(TOptArr, union_of(TOptArr, TInitNull));
  EXPECT_EQ(TOptArr, union_of(TInitNull, TOptArr));

  EXPECT_EQ(TInitUnc, union_of(TOptSArr, TSStr));
  EXPECT_EQ(TInitUnc, union_of(TSStr, TOptSArr));
}
Example #30
0
TEST(Type, OptTV) {
  EXPECT_TRUE(!tv(opt(ival(2))));
  EXPECT_TRUE(!tv(opt(sval(s_test.get()))));
  EXPECT_TRUE(!tv(opt(dval(2.0))));
  EXPECT_TRUE(!tv(TOptFalse));
  EXPECT_TRUE(!tv(TOptTrue));
  for (auto& x : optionals) {
    EXPECT_TRUE(!tv(x));
  }
}