Exemplo n.º 1
0
void ReadVarFile(char *filename) {
  
  FILE *input;
  
  real real_value;
  int  int_value, type;
  boolean bool_value = FALSE;
 
  real temp;

  char separator[20] = "\t :=>"; //Separators between a parameter name and its value
  char s[MAXLINELENGTH], name[MAXNAMELENGTH], strval[MAXNAMELENGTH];
  char testbool;
  char *s1;

  int  *int_var;
  real *real_var;
  boolean *bool_var;

  int found;

  int i, success;

  input = fopen(filename, "r");

  if (input == NULL) {
    mastererr("Unable to read '%s'. Program stopped.\n", filename);
    prs_exit(1);
  }
  ReadRedefined ();
  mastererr("Reading parameters file %s\n", filename);
  while (fgets(s, MAXLINELENGTH-1, input) != NULL ) {
    success = sscanf(s, "%s", name); // read finish in a white-space.
    if(name[0]!='#' && success == 1) {
      s1 = s + (int)strlen(name); // pointer shift (Here is the data)
      // cast to int because type of strlen is size_t.
#ifdef FLOAT
      sscanf(s1 + strspn(s1, separator),"%f", &temp); //single precision floating point value
#else
      sscanf(s1 + strspn(s1, separator),"%lf", &temp); //double precision floating point value
#endif
      sscanf(s1 + strspn(s1, separator),"%s", strval); //string value
      real_value = (real)temp;
      int_value  = (int)temp;
      testbool   = toupper(strval[0]); // Convert to upper case
      if (testbool == 'Y')  bool_value = TRUE;  //Yes, or
      else bool_value = FALSE;
      // name to upper case
      for (i = 0; i<strlen(name); i++) name[i] = (char)toupper(name[i]);
      if (strcmp(name, "INCLUDE") == 0) {
	ReadVarFile(strval); // Recursive call. You can include a parameter file within another one.
      }
      else {
	found = NO;
	for (i = 0; i<Id_Var; i++) {
	  if (strcmp(name, Var_Set[i].name) == 0) {
	    if (Var_Set[i].read == YES) {
	      mastererr("Warning : %s is defined more than once.\n", name);
	    }
	    if (Var_Set[i].read == REDEFINED) {
	      mastererr("Warning : %s is redefined on the command line.\n", name);
	    }
	    if (Var_Set[i].need == IRRELEVANT) {
	      mastererr("Warning : variable %s is irrelevant and nonetheless defined.\n", name);
	    }
	    found = YES;
	    if (Var_Set[i].read == NO) {
	      Var_Set[i].read = YES;
	      // Now we point to the correct variable
	      real_var = (real*)(Var_Set[i].variable);
	      int_var  = (int*) (Var_Set[i].variable);
	      bool_var = (boolean*)(Var_Set[i].variable);
	      // Now we reassign the value of the variable, if needed
	      if (Var_Set[i].type == REAL)   *real_var = real_value;
	      if (Var_Set[i].type == INT )   *int_var  = int_value;
	      if (Var_Set[i].type == BOOL)   *bool_var = bool_value;
	      if (Var_Set[i].type == STRING) strcpy(Var_Set[i].variable, strval);
	    }
	  }
	}
      }
      if ((found == NO) && strcmp(name, "INCLUDE")!=0 && strcmp(name, "END")!=0)
      mastererr("Warning: variable %s defined but does not exist in code.\n", name);
    }
  }
  found = NO;
  for (i = 0; i<Id_Var; i++) {
    if ((Var_Set[i].read == NO) && (Var_Set[i].need == YES)) {
      if (found == NO) {
	mastererr("Fatal error : undefined mandatory variable(s):\n");
	found = YES;
      }
      mastererr("%s\n", Var_Set[i].name);
    }
    if (found == YES)
      prs_exit(1);
  }
  found = NO;
  if(strcmp(name, "END")==0) {
    for (i=0; i<Id_Var; i++) {
      if (Var_Set[i].read == NO) {
	if (found == NO) {
	  mastererr("Secondary variables omitted:\n");
	  found = YES;
	}
	if ((type = Var_Set[i].type) == REAL)
	  mastererr("%s;\t Default Value : %.5g\n", \
		    Var_Set[i].name, *((real *) Var_Set[i].variable));
	if (type == INT)
	  mastererr("%s;\t Default Value : %d\n", \
		    Var_Set[i].name, *((int *) Var_Set[i].variable));
	if (type == STRING)
	  mastererr("%s;\t Default Value : %s\n", \
		    Var_Set[i].name, Var_Set[i].variable);
      }
    }
  }
  fclose(input);
  var_assign();
}
Exemplo n.º 2
0
int
remove_gtmProxy(char *name, bool clean_opt)
{
	FILE *f;
	int idx;

	/* Check if gtm proxy exists */
	if ((idx = gtmProxyIdx(name)) < 0)
	{
		elog(ERROR, "ERROR: %s is not a gtm proxy.\n", name);
		return 1;
	}
	/* Check if it is in use */
	if (ifExists(VAR_coordMasterServers, aval(VAR_gtmProxyServers)[idx]) ||
		ifExists(VAR_coordSlaveServers, aval(VAR_gtmProxyServers)[idx]) ||
		ifExists(VAR_datanodeMasterServers, aval(VAR_gtmProxyServers)[idx]) ||
		ifExists(VAR_datanodeSlaveServers, aval(VAR_gtmProxyServers)[idx]))
	{
		elog(ERROR, "ERROR: GTM Proxy %s is in use\n", name);
		return 1;
	}
	elog(NOTICE, "NOTICE: removing gtm_proxy %s\n", name);
	/* Clean */
	if (clean_opt)
	{
		char **nodelist = NULL;

		elog(NOTICE, "NOTICE: cleaning target resources.\n");
		AddMember(nodelist, name);
		clean_gtm_proxy(nodelist);
		CleanArray(nodelist);
	}
	/* Reconfigure */
	var_assign(&aval(VAR_gtmProxyNames)[idx], Strdup("none"));
	var_assign(&aval(VAR_gtmProxyServers)[idx], Strdup("none"));
	var_assign(&aval(VAR_gtmProxyPorts)[idx], Strdup("-1"));
	var_assign(&aval(VAR_gtmProxyDirs)[idx], Strdup("none"));
	handle_no_slaves();
	makeServerList();
	/* Update configuration file and backup 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 proxy addition\n"
			"#        %s\n"
			"%s=%s\n"					/* gtmProxy */
			"%s=( %s )\n"				/* gtmProxyNames */
			"%s=( %s )\n"				/* gtmProxyServers */
			"%s=( %s )\n"				/* gtmProxyPorts */
			"%s=( %s )\n"				/* gtmProxyDirs */
			"#----End of reconfiguration -------------------------\n",
			timeStampString(date, MAXTOKEN+1),
			VAR_gtmProxy, sval(VAR_gtmProxy),
			VAR_gtmProxyNames, listValue(VAR_gtmProxyNames),
			VAR_gtmProxyServers, listValue(VAR_gtmProxyServers),
			VAR_gtmProxyPorts, listValue(VAR_gtmProxyPorts),
			VAR_gtmProxyDirs, listValue(VAR_gtmProxyDirs));
	fclose(f);
	backup_configuration();
	elog(NOTICE, "Done.\n");
	return 0;
}