char *
envvar_logdir_file (char *path, size_t size, const char *filename)
{
  assert (filename != NULL);

#if !defined (DO_NOT_USE_CUBRIDENV)
  if (envvar_Root == NULL)
    {
      envvar_root ();
    }
  snprintf (path, size, "%s/log/%s", envvar_Root, filename);
#else
  snprintf (path, size, "%s/%s", CUBRID_LOGDIR, filename);
#endif

  path[size - 1] = '\0';
  return path;
}
Exemple #2
0
/*
 * loaddb_internal - internal main loaddb function
 *    return: NO_ERROR if successful, error code otherwise
 *    argc(in): argc of main
 *    argv(in): argv of main
 *    dba_mode(in):
 */
static int
loaddb_internal (UTIL_FUNCTION_ARG * arg, int dba_mode)
{
  UTIL_ARG_MAP *arg_map = arg->arg_map;
  int error = NO_ERROR;
  /* set to static to avoid copiler warning (clobbered by longjump) */
  static FILE *schema_file = NULL;
  static FILE *index_file = NULL;
  static FILE *object_file = NULL;
  FILE *error_file = NULL;
  int status = 0;
  int errors, objects, defaults;
#if !defined (LDR_OLD_LOADDB)
  int lastcommit = 0;
#endif /* !LDR_OLD_LOADDB */
  char *passwd;
  /* set to static to avoid copiler warning (clobbered by longjump) */
  static int interrupted = false;
  int au_save = 0;
  extern bool obt_Enable_autoincrement;

  char log_file_name[PATH_MAX];

  LOADDB_INIT_DEBUG ();
  obt_Enable_autoincrement = false;

  Volume = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE, 0);
  Input_file = utility_get_option_string_value (arg_map, OPTION_STRING_TABLE,
						1);
  User_name = utility_get_option_string_value (arg_map, LOAD_USER_S, 0);
  Password = utility_get_option_string_value (arg_map, LOAD_PASSWORD_S, 0);
  Syntax_check = utility_get_option_bool_value (arg_map, LOAD_CHECK_ONLY_S);
  Load_only = utility_get_option_bool_value (arg_map, LOAD_LOAD_ONLY_S);
  Estimated_size = utility_get_option_int_value (arg_map,
						 LOAD_ESTIMATED_SIZE_S);
  Verbose = utility_get_option_bool_value (arg_map, LOAD_VERBOSE_S);
  Disable_statistics =
    utility_get_option_bool_value (arg_map, LOAD_NO_STATISTICS_S);
  Periodic_commit = utility_get_option_int_value (arg_map,
						  LOAD_PERIODIC_COMMIT_S);
  Verbose_commit = Periodic_commit > 0 ? true : false;
  No_oid_hint = utility_get_option_bool_value (arg_map, LOAD_NO_OID_S);
  Schema_file = utility_get_option_string_value (arg_map, LOAD_SCHEMA_FILE_S,
						 0);
  Index_file = utility_get_option_string_value (arg_map, LOAD_INDEX_FILE_S,
						0);
  Object_file = utility_get_option_string_value (arg_map, LOAD_DATA_FILE_S,
						 0);
  Error_file = utility_get_option_string_value (arg_map,
						LOAD_ERROR_CONTROL_FILE_S, 0);
  Ignore_logging = utility_get_option_bool_value (arg_map,
						  LOAD_IGNORE_LOGGING_S);
#if !defined (LDR_OLD_LOADDB)
  Ignore_class_file = utility_get_option_string_value (arg_map,
						       LOAD_IGNORE_CLASS_S,
						       0);
#endif

  Input_file = Input_file ? Input_file : "";
  Schema_file = Schema_file ? Schema_file : "";
  Index_file = Index_file ? Index_file : "";
  Object_file = Object_file ? Object_file : "";
  Error_file = Error_file ? Error_file : "";

  if (ldr_validate_object_file (stderr, arg->argv0))
    {
      goto error_return;
    }

  /* error message log file */
  sprintf (log_file_name, "%s_%s.err", Volume, arg->command_name);
  er_init (log_file_name, ER_NEVER_EXIT);

  if (Index_file[0] != '\0'
      && PRM_SR_NBUFFERS < LOAD_INDEX_MIN_SORT_BUFFER_PAGES)
    {
      sysprm_set_force (PRM_NAME_SR_NBUFFERS,
			LOAD_INDEX_MIN_SORT_BUFFER_PAGES_STRING);
    }
  sysprm_set_force (PRM_NAME_JAVA_STORED_PROCEDURE, "no");

  /* login */
  if (User_name != NULL || !dba_mode)
    {
      (void) db_login (User_name, Password);
      if ((error = db_restart (arg->command_name, true, Volume)))
	{
	  if (error == ER_AU_INVALID_PASSWORD)
	    {
	      /* prompt for password and try again */
	      error = NO_ERROR;
	      passwd = getpass (msgcat_message (MSGCAT_CATALOG_UTILS,
						MSGCAT_UTIL_SET_LOADDB,
						LOADDB_MSG_PASSWORD_PROMPT));
	      if (!strlen (passwd))
		passwd = NULL;
	      (void) db_login (User_name, passwd);
	      error = db_restart (arg->command_name, true, Volume);
	    }
	}
    }
  else
    {
      /* if we're in the protected dba mode, just login without
         authorization */
      AU_DISABLE_PASSWORDS ();
      db_set_client_type (DB_CLIENT_TYPE_ADMIN_UTILITY);
      (void) db_login ("dba", NULL);
      error = db_restart (arg->command_name, true, Volume);
    }

  /* open loaddb log file */
  sprintf (log_file_name, "%s_loaddb.log", Volume);
  loaddb_log_file = fopen (log_file_name, "w+");
  if (loaddb_log_file == NULL)
    {
      printf ("Cannot open log file %s\n", log_file_name);
      status = 2;
      goto error_return;
    }

#if 0
#if !defined (LDR_OLD_LOADDB)

  /* Execute old loaddb if no optimization flag is set true
   * or LOADDB_NOPT is set, we must pass the argv except
   * -no option and invoke execvp() for no optimized loaddb
   */
  if (No_optimization || envvar_get ("LOADDB_NOPT"))
    {

      char **tmp;
      char *lastslash, path[PATH_MAX];
      int i = 1, j = 1;

      tmp = (char **) malloc (sizeof (char *) * (argc + 1));
      tmp[0] = (char *) "loaddb";
      while (j < argc)
	{
	  if (!strcmp (argv[j], "-no"))
	    j++;
	  else
	    tmp[i++] = argv[j++];
	};
      tmp[i] = 0;

      strcpy (path, argv[0]);
      lastslash = strrchr (path, (int) '/');
#if defined(WINDOWS)
      {
	char *p, exec_path[1024], cmd_line[1024 * 8];
	int cp_len = 0;

	db_shutdown ();

	p = envvar_root ();
	if (p == NULL)
	  {
	    printf ("The `CUBRID' environment variable is not set.\n");
	  }
	else
	  {
	    sprintf (exec_path, "%s/migdb_o.exe", p);
	    for (i = 0; tmp[i]; i++)
	      {
		cp_len += sprintf (cmd_line + cp_len, "\"%s\" ", tmp[i]);
	      }
	    if (envvar_get ("FRONT_DEBUG") != NULL)
	      {
		printf ("Executing:%s %s\n", exec_path, cmd_line);
	      }
	    run_proc (exec_path, cmd_line);
	  }
	exit (0);
      }
#else /* !WINDOWS */
      if (lastslash != NULL)
	strcpy (lastslash + 1, "migdb_o");
      else
	strcpy (path, "migdb_o");

      if (execvp (path, tmp) == -1)
	{
	  print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
					    MSGCAT_UTIL_SET_LOADDB,
					    LOADDB_MSG_NOPT_ERR));
	  exit (0);
	};
#endif /* WINDOWS */
    }
#endif /* !LDR_OLD_LOADDB */
#endif

  /* check if schema/index/object files exist */
  ldr_check_file_name_and_line_no ();

  if (Schema_file[0] != 0)
    {
      schema_file = fopen (Schema_file, "r");
      if (schema_file == NULL)
	{
	  print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
					    MSGCAT_UTIL_SET_LOADDB,
					    LOADDB_MSG_BAD_INFILE),
			 Schema_file);
	  status = 2;
	  goto error_return;
	}
    }
  if (Index_file[0] != 0)
    {
      index_file = fopen (Index_file, "r");
      if (index_file == NULL)
	{
	  print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
					    MSGCAT_UTIL_SET_LOADDB,
					    LOADDB_MSG_BAD_INFILE),
			 Index_file);
	  status = 2;
	  goto error_return;
	}
    }
  if (Object_file[0] != 0)
    {
      object_file = fopen_ex (Object_file, "rb");	/* keep out ^Z */

      if (object_file == NULL)
	{
	  print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
					    MSGCAT_UTIL_SET_LOADDB,
					    LOADDB_MSG_BAD_INFILE),
			 Object_file);
	  status = 2;
	  goto error_return;
	}
    }

#if !defined (LDR_OLD_LOADDB)
  if (Ignore_class_file)
    {
      int retval;
      retval = get_ignore_class_list (Ignore_class_file);

      if (retval < 0)
	{
	  status = 2;
	  goto error_return;
	}
    }
#endif

  /* Disallow syntax only and load only options together */
  if (Load_only && Syntax_check)
    {
      print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
					MSGCAT_UTIL_SET_LOADDB,
					LOADDB_MSG_INCOMPATIBLE_ARGS),
		     "--" LOAD_LOAD_ONLY_L, "--" LOAD_CHECK_ONLY_L);
      status = 1;		/* parsing error */
      goto error_return;
    }

  if (Error_file[0] != 0)
    {
      if (Syntax_check)
	{
	  print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
					    MSGCAT_UTIL_SET_LOADDB,
					    LOADDB_MSG_INCOMPATIBLE_ARGS),
			 "--" LOAD_ERROR_CONTROL_FILE_L,
			 "--" LOAD_CHECK_ONLY_L);
	  status = 1;		/* parsing error */
	  goto error_return;
	}
      error_file = fopen_ex (Error_file, "rt");
      if (error_file == NULL)
	{
	  print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
					    MSGCAT_UTIL_SET_LOADDB,
					    LOADDB_MSG_BAD_INFILE),
			 Error_file);
	  status = 2;
	  goto error_return;
	}
      er_filter_fileset (error_file);
      fclose (error_file);
    }

  /* check if no log option can be applied */
  if (error
      || (Ignore_logging != 0 && locator_log_force_nologging () != NO_ERROR))
    {
      /* couldn't log in */
      print_log_msg (1, "%s\n", db_error_string (3));
      status = 3;
      db_shutdown ();
      goto error_return;
    }

  /* change "print_key_value_on_unique_error" parameter */
  sysprm_change_server_parameters ("print_key_value_on_unique_error=1");

  /* if schema file is specified, do schema loading */
  if (schema_file != NULL)
    {
      print_log_msg (1, "\nStart schema loading.\n");

      /*
       * CUBRID 8.2 should be compatible with earlier versions of CUBRID.
       * Therefore, we do not perform user authentication when the loader
       * is executing by DBA group user.
       */
      if (au_is_dba_group_member (Au_user))
	{
	  AU_DISABLE (au_save);
	}

      if (ldr_exec_query_from_file (Schema_file, schema_file,
				    &schema_file_start_line,
				    Periodic_commit) != 0)
	{
	  print_log_msg (1, "\nError occurred during schema loading."
			 "\nAborting current transaction...");
	  status = 3;
	  db_shutdown ();
	  print_log_msg (1,
			 " done.\n\nRestart loaddb with '-%c %s:%d' option\n",
			 LOAD_SCHEMA_FILE_S, Schema_file,
			 schema_file_start_line);
	  goto error_return;
	}

      if (au_is_dba_group_member (Au_user))
	{
	  AU_ENABLE (au_save);
	}

      print_log_msg (1, "Schema loading from %s finished.\n", Schema_file);

      /* update catalog statistics */
      AU_DISABLE (au_save);
      sm_update_all_catalog_statistics ();
      AU_ENABLE (au_save);

      print_log_msg (1,
		     "Statistics for Catalog classes have been updated.\n\n");

      db_commit_transaction ();
      fclose (schema_file);
      schema_file = NULL;

    }


  /* if index file is specified, do index creation */

  if (object_file != NULL)
    {
#if defined (SA_MODE)
      locator_Dont_check_foreign_key = true;
#endif
      print_log_msg (1, "\nStart object loading.\n");
      ldr_init (Verbose);

      /* set the flag to indicate what type of interrupts to raise
       * If logging has been disabled set commit flag.
       * If logging is enabled set abort flag.
       */

      if (Ignore_logging)
	Interrupt_type = LDR_STOP_AND_COMMIT_INTERRUPT;
      else
	Interrupt_type = LDR_STOP_AND_ABORT_INTERRUPT;

      if (Periodic_commit)
	{
	  /* register the post commit function */
#if defined(LDR_OLD_LOADDB)
	  ldr_register_post_commit_handler (&loaddb_report_num_of_commits);
#else /* !LDR_OLD_LOADDB */
	  ldr_register_post_commit_handler (&loaddb_report_num_of_commits,
					    NULL);
#endif /* LDR_OLD_LOADDB */
	}

      /* Check if we need to perform syntax checking. */
      if (!Load_only)
	{
	  print_log_msg ((int) Verbose, msgcat_message (MSGCAT_CATALOG_UTILS,
							MSGCAT_UTIL_SET_LOADDB,
							LOADDB_MSG_CHECKING));
	  do_loader_parse (object_file);
#if defined(LDR_OLD_LOADDB)
	  ldr_stats (&errors, &objects, &defaults);
#else /* !LDR_OLD_LOADDB */
	  ldr_stats (&errors, &objects, &defaults, &lastcommit);
#endif /* LDR_OLD_LOADDB */
	}
      else
	errors = 0;

      if (errors)
	print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
					  MSGCAT_UTIL_SET_LOADDB,
					  LOADDB_MSG_ERROR_COUNT), errors);
      else if (!Syntax_check)
	{
	  /* now do it for real if there were no errors and we aren't
	     doing a simple syntax check */
	  ldr_start (Periodic_commit);
	  fclose (object_file);
	  object_file = fopen_ex (Object_file, "rb");	/* keep out ^Z */
	  if (object_file != NULL)
	    {
	      print_log_msg ((int) Verbose,
			     msgcat_message (MSGCAT_CATALOG_UTILS,
					     MSGCAT_UTIL_SET_LOADDB,
					     LOADDB_MSG_INSERTING));

	      /* make sure signals are caught */
	      util_arm_signal_handlers (signal_handler, signal_handler);

	      /* register function to call  and jmp environment to longjmp to
	       * after aborting or committing.
	       */
	      ldr_register_post_interrupt_handler
		(&loaddb_get_num_of_inserted_objects, &loaddb_jmp_buf);

	      if (setjmp (loaddb_jmp_buf) != 0)
		{

		  /* We have had an interrupt, the transaction should have
		   * been already been aborted or committed by the loader.
		   * If Total_objects_loaded is -1 an error occurred during
		   * rollback or commit.
		   */
		  if (Total_objects_loaded != -1)
		    print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
						      MSGCAT_UTIL_SET_LOADDB,
						      LOADDB_MSG_OBJECT_COUNT),
				   Total_objects_loaded);
#if !defined(LDR_OLD_LOADDB)
		  ldr_stats (&errors, &objects, &defaults, &lastcommit);
		  if (lastcommit > 0)
		    print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
						      MSGCAT_UTIL_SET_LOADDB,
						      LOADDB_MSG_LAST_COMMITTED_LINE),
				   lastcommit);
#endif /* !LDR_OLD_LOADDB */
		  interrupted = true;

		}
	      else
		{
		  do_loader_parse (object_file);
#if defined(LDR_OLD_LOADDB)
		  ldr_stats (&errors, &objects, &defaults);
#else /* !LDR_OLD_LOADDB */
		  ldr_stats (&errors, &objects, &defaults, &lastcommit);
#endif /* LDR_OLD_LOADDB */
		  if (errors)
		    {
#if defined(LDR_OLD_LOADDB)
		      print_log_msg (1, msgcat_message (MSGCAT_CATALOG_UTILS,
							MSGCAT_UTIL_SET_LOADDB,
							LOADDB_MSG_ERROR_COUNT),
				     errors);
#else /* !LDR_OLD_LOADDB */
		      if (lastcommit > 0)
			print_log_msg (1,
				       msgcat_message (MSGCAT_CATALOG_UTILS,
						       MSGCAT_UTIL_SET_LOADDB,
						       LOADDB_MSG_LAST_COMMITTED_LINE),
				       lastcommit);
#endif /* LDR_OLD_LOADDB */
		      /*
		       * don't allow the transaction to be committed at
		       * this point, note that if we ever move to a scheme
		       * where we write directly to the heap without the
		       * transaction context, we will have to unwind the
		       * changes made if errors are detected !
		       */
		      db_abort_transaction ();
		    }
		  else
		    {
		      if (objects)
			print_log_msg (1,
				       msgcat_message (MSGCAT_CATALOG_UTILS,
						       MSGCAT_UTIL_SET_LOADDB,
						       LOADDB_MSG_OBJECT_COUNT),
				       objects);
		      if (defaults)
			print_log_msg (1,
				       msgcat_message (MSGCAT_CATALOG_UTILS,
						       MSGCAT_UTIL_SET_LOADDB,
						       LOADDB_MSG_DEFAULT_COUNT),
				       defaults);
		      print_log_msg ((int) Verbose,
				     msgcat_message (MSGCAT_CATALOG_UTILS,
						     MSGCAT_UTIL_SET_LOADDB,
						     LOADDB_MSG_COMMITTING));

		      /* commit the transaction and then update statistics */
		      if (!db_commit_transaction ())
			{
			  if (!Disable_statistics)
			    {
			      if (Verbose)
				print_log_msg (1,
					       msgcat_message
					       (MSGCAT_CATALOG_UTILS,
						MSGCAT_UTIL_SET_LOADDB,
						LOADDB_MSG_UPDATING_STATISTICS));
			      if (!ldr_update_statistics ())
				{
				  /*
				   * would it be faster to update statistics
				   * before the first commit and just have a
				   * single commit ?
				   */
				  print_log_msg ((int) Verbose,
						 msgcat_message
						 (MSGCAT_CATALOG_UTILS,
						  MSGCAT_UTIL_SET_LOADDB,
						  LOADDB_MSG_COMMITTING));
				  (void) db_commit_transaction ();
				}
			    }
			}
		    }
		}
	    }
	}
      ldr_final ();
      if (object_file != NULL)
	{
	  fclose (object_file);
	  object_file = NULL;
	}
    }

  /* create index */
  if (!interrupted && index_file != NULL)
    {
      print_log_msg (1, "\nStart index loading.\n");
      if (ldr_exec_query_from_file (Index_file, index_file,
				    &index_file_start_line,
				    Periodic_commit) != 0)
	{
	  print_log_msg (1, "\nError occurred during index loading."
			 "\nAborting current transaction...");
	  status = 3;
	  db_shutdown ();
	  print_log_msg (1,
			 " done.\n\nRestart loaddb with '-%c %s:%d' option\n",
			 LOAD_INDEX_FILE_S, Index_file,
			 index_file_start_line);
	  goto error_return;
	}
      /* update catalog statistics */
      AU_DISABLE (au_save);
      sm_update_catalog_statistics (CT_INDEX_NAME);
      sm_update_catalog_statistics (CT_INDEXKEY_NAME);
      AU_ENABLE (au_save);

      print_log_msg (1, "Index loading from %s finished.\n", Index_file);
      db_commit_transaction ();
    }
  print_log_msg ((int) Verbose, msgcat_message (MSGCAT_CATALOG_UTILS,
						MSGCAT_UTIL_SET_LOADDB,
						LOADDB_MSG_CLOSING));
  (void) db_shutdown ();

#if !defined (LDR_OLD_LOADDB)
  free_ignoreclasslist ();
#endif
  return (status);
error_return:
  if (schema_file != NULL)
    fclose (schema_file);
  if (object_file != NULL)
    fclose (object_file);
  if (index_file != NULL)
    fclose (index_file);

#if !defined (LDR_OLD_LOADDB)
  free_ignoreclasslist ();
#endif

  return status;
}
Exemple #3
0
int
jsp_start_server (const char *db_name, const char *path)
{
  JNIEnv *env_p = NULL;
  jint res;
  jclass cls, string_cls;
  jmethodID mid;
  jstring jstr_dbname, jstr_path, jstr_version, jstr_envroot;
  jobjectArray args;
  JavaVMInitArgs vm_arguments;
  JavaVMOption options[3];
  char classpath[PATH_MAX + 32], logging_prop[PATH_MAX + 32];
  char *loc_p, *locale;
  const char *envroot;
  char jsp_file_path[PATH_MAX];
  char optionString2[] = "-Xrs";
  CREATE_VM_FUNC create_vm_func = NULL;

  if (PRM_JAVA_STORED_PROCEDURE == false)
    {
      return NO_ERROR;
    }

  if (jvm != NULL)
    {
      return NO_ERROR;		/* already created */
    }

  envroot = envvar_root ();
  if (envroot == NULL)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_CANNOT_START_JVM,
	      1, "envvar_root");
      return ER_SP_CANNOT_START_JVM;
    }

  snprintf (classpath, sizeof (classpath) - 1,
	    "-Djava.class.path=%s",
	    envvar_javadir_file (jsp_file_path, PATH_MAX, "jspserver.jar"));

  snprintf (logging_prop, sizeof (logging_prop) - 1,
	    "-Djava.util.logging.config.file=%s",
	    envvar_javadir_file (jsp_file_path, PATH_MAX,
				 "logging.properties"));

  options[0].optionString = classpath;
  options[1].optionString = logging_prop;
  options[2].optionString = optionString2;
  vm_arguments.version = JNI_VERSION_1_4;
  vm_arguments.options = options;
  vm_arguments.nOptions = 3;
  vm_arguments.ignoreUnrecognized = JNI_TRUE;

  locale = NULL;
  loc_p = setlocale (LC_TIME, NULL);
  if (loc_p != NULL)
    {
      locale = strdup (loc_p);
    }

#if defined(WINDOWS)

  __try
  {
    res = JNI_CreateJavaVM (&jvm, (void **) &env_p, &vm_arguments);
  }
  __except (delay_load_dll_exception_filter (GetExceptionInformation ()))
  {
    res = -1;
  }

#else /* WINDOWS */

  create_vm_func = (CREATE_VM_FUNC) jsp_get_create_java_vm_function_ptr ();
  if (create_vm_func)
    {
      res = (*create_vm_func) (&jvm, (void **) &env_p, &vm_arguments);
    }
  else
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_JVM_LIB_NOT_FOUND, 1,
	      dlerror ());
      jsp_display_warning_msg ();
      if (locale != NULL)
	{
	  free (locale);
	}
      return er_errid ();
    }

#endif /* !WINDOWS */

  setlocale (LC_TIME, locale);
  if (locale != NULL)
    {
      free (locale);
    }

  if (res < 0)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_CANNOT_START_JVM,
	      1, "JNI_CreateJavaVM");
      jsp_display_warning_msg ();
      jvm = NULL;
      return er_errid ();
    }

  cls = JVM_FindClass (env_p, "com/cubrid/jsp/Server");
  if (cls == NULL)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_CANNOT_START_JVM,
	      1, "FindClass: " "com/cubrid/jsp/Server");
      goto error;
    }

  mid = JVM_GetStaticMethodID (env_p, cls, "start", "([Ljava/lang/String;)I");
  if (mid == NULL)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_CANNOT_START_JVM,
	      1, "GetStaticMethodID");
      goto error;
    }

  jstr_dbname = JVM_NewStringUTF (env_p, db_name);
  if (jstr_dbname == NULL)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_CANNOT_START_JVM,
	      1, "NewStringUTF");
      goto error;
    }

  jstr_path = JVM_NewStringUTF (env_p, path);
  if (jstr_path == NULL)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_CANNOT_START_JVM,
	      1, "NewStringUTF");
      goto error;
    }

  jstr_version = JVM_NewStringUTF (env_p, rel_build_number ());
  if (jstr_version == NULL)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_CANNOT_START_JVM,
	      1, "NewStringUTF");
      goto error;
    }

  jstr_envroot = JVM_NewStringUTF (env_p, envvar_root ());
  if (jstr_envroot == NULL)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_CANNOT_START_JVM,
	      1, "NewStringUTF");
      goto error;
    }

  string_cls = JVM_FindClass (env_p, "java/lang/String");
  if (string_cls == NULL)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_CANNOT_START_JVM,
	      1, "FindClass: " "java/lang/String");
      goto error;
    }

  args = JVM_NewObjectArray (env_p, 4, string_cls, NULL);
  if (args == NULL)
    {
      er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_SP_CANNOT_START_JVM,
	      1, "NewObjectArray");
      goto error;
    }

  JVM_SetObjectArrayElement (env_p, args, 0, jstr_dbname);
  JVM_SetObjectArrayElement (env_p, args, 1, jstr_path);
  JVM_SetObjectArrayElement (env_p, args, 2, jstr_version);
  JVM_SetObjectArrayElement (env_p, args, 3, jstr_envroot);

  sp_port = JVM_CallStaticIntMethod (env_p, cls, mid, args);

  return 0;

error:
  jsp_display_warning_msg ();
  jsp_stop_server ();
  jvm = NULL;

  return er_errid ();
}
Exemple #4
0
/*
 * hb_pack_server_name() - make a "server_name" string
 *   return: packed name
 *   server_name(in)   : server name
 *   name_length(out)  : length of packed name
 *   log_path(in)      : log path
 *   copylogdbyn(in)   : true if copylogdb
 *
 * Note:
 *         make a "server_name" string to connect to master
 *         server_name = server_type ( # ) +
 *                       server_name +
 *                       release_string +
 *                       env_name +   ($CUBRID path)
 *                       pid_string   (process id)
 */
static char *
hb_pack_server_name (const char *server_name, int *name_length, const char *log_path, HB_PROC_TYPE type)
{
  char *packed_name = NULL;
  const char *env_name = NULL;
  char pid_string[16];
  int n_len, l_len, r_len, e_len, p_len;

  if (server_name != NULL)
    {
      env_name = envvar_root ();
      if (env_name == NULL)
	{
	  return NULL;
	}

      /* here we changed the 2nd string in packed_name from rel_release_string() to rel_major_release_string() solely
       * for the purpose of matching the name of the CUBRID driver. */

      snprintf (pid_string, sizeof (pid_string), "%d", getpid ());
      n_len = strlen (server_name) + 1;
      l_len = (log_path) ? strlen (log_path) + 1 : 0;
      r_len = strlen (rel_major_release_string ()) + 1;
      e_len = strlen (env_name) + 1;
      p_len = strlen (pid_string) + 1;
      *name_length = n_len + l_len + r_len + e_len + p_len + 5;

      packed_name = malloc (*name_length);
      if (packed_name == NULL)
	{
	  er_set (ER_ERROR_SEVERITY, ARG_FILE_LINE, ER_OUT_OF_VIRTUAL_MEMORY, 1, (*name_length));
	  return NULL;
	}

      if (type == HB_PTYPE_COPYLOGDB)
	{
	  packed_name[0] = '$';
	}
      else if (type == HB_PTYPE_APPLYLOGDB)
	{
	  packed_name[0] = '%';
	}
      else if (type == HB_PTYPE_PREFETCHLOGDB)
	{
	  packed_name[0] = '_';
	}
      else
	{
	  assert (0);

	  free_and_init (packed_name);
	  return NULL;
	}
      memcpy (packed_name + 1, server_name, n_len);
      if (l_len)
	{
	  packed_name[(1 + n_len) - 1] = ':';
	  memcpy (packed_name + 1 + n_len, log_path, l_len);
	}
      memcpy (packed_name + 1 + n_len + l_len, rel_major_release_string (), r_len);
      memcpy (packed_name + 1 + n_len + l_len + r_len, env_name, e_len);
      memcpy (packed_name + 1 + n_len + l_len + r_len + e_len, pid_string, p_len);
    }
  return (packed_name);
}