Esempio n. 1
0
/*
 * The function to execute a RA.
 */
static int
execra(const char * rsc_id, const char * rsc_type, const char * provider,
       const char * op_type, const int timeout, GHashTable * params)
{
	char ra_pathname[RA_MAX_NAME_LENGTH];
	GHashTable * tmp_for_setenv;
	GString * params_gstring;
	char * inherit_debuglevel = NULL;
	int save_errno;

	get_ra_pathname(RA_PATH, rsc_type, provider, ra_pathname);

	/* Setup environment correctly */
	tmp_for_setenv = g_hash_table_new(g_str_hash, g_str_equal);
	add_OCF_prefix(params, tmp_for_setenv);
	add_OCF_env_vars(tmp_for_setenv, rsc_id, rsc_type, provider);
	raexec_setenv(tmp_for_setenv);
	g_hash_table_foreach_remove(tmp_for_setenv, let_remove_eachitem, NULL);
	g_hash_table_destroy(tmp_for_setenv);

	/* let this log show only high loglevel. */
	inherit_debuglevel = getenv(HADEBUGVAL);
	if ((inherit_debuglevel != NULL) && (atoi(inherit_debuglevel) > 1)) {
		params_gstring = g_string_new("");
		hash_to_str(params, params_gstring);
		cl_log(LOG_DEBUG, "RA instance %s executing: OCF::%s %s. Parameters: "
			"{%s}", rsc_id, rsc_type, op_type, params_gstring->str);
		g_string_free(params_gstring, TRUE);
	}

	closefiles(); /* don't leak open files */
	/* execute the RA */
	execl(ra_pathname, ra_pathname, op_type, (const char *)NULL);
	/* oops, exec failed */
	save_errno = errno; /* cl_perror may change errno */
	cl_perror("(%s:%s:%d) execl failed for %s" 
		  , __FILE__, __FUNCTION__, __LINE__, ra_pathname);
	errno = save_errno;
	exit(get_failed_exec_rc());
}
Esempio n. 2
0
/*
 * converts the variable to string-variable
 */
void v_tostr(var_t *arg) {
  if (arg->type != V_STR) {
    char *tmp;
    int l;

    tmp = tmp_alloc(64);

    switch (arg->type) {
    case V_UDS:
      uds_to_str(arg, tmp, 64);
      uds_free(arg);
      break;
    case V_HASH:
      hash_to_str(arg, tmp, 64);
      hash_free_var(arg);
      break;
    case V_PTR:
      ltostr(arg->v.ap.p, tmp);
      break;
    case V_INT:
      ltostr(arg->v.i, tmp);
      break;
    case V_NUM:
      ftostr(arg->v.n, tmp);
      break;
    default:
      err_varisarray();
      tmp_free(tmp);
      return;
    }

    l = strlen(tmp) + 1;
    arg->type = V_STR;
    arg->v.p.ptr = tmp_alloc(l);
    arg->v.p.size = l;
    strcpy(arg->v.p.ptr, tmp);
    tmp_free(tmp);
  }
}
Esempio n. 3
0
int
pr_hash_titles(
    char *op_file_prefix,
    char *hash_words_in_title,
    char *num_words_per_title
    )
{
  int status = 0;
  int nw_i, itemp, num_titles, num_dict_words, len;
  char *fname = NULL;
  char *nw_X = NULL; int n_nw_X = 0; unsigned int *num_words = NULL; 
  char *hw_X = NULL; int n_hw_X = 0; unsigned int *hash_words = NULL;
  char *twdict_X = NULL; int n_twdict_X = 0; 
  HT3_TYPE *title_words = NULL; int num_title_words = 0;
  unsigned int *offset = NULL;
  wchar_t *fc_ptr = NULL;
  wchar_t wc_buf[2];

  wc_buf[0] = wc_buf[0] = '\0';
  //----------------------------------------------
  len = strlen(op_file_prefix) + 16;
  fname = (char *)malloc(len * sizeof(char));
  return_if_malloc_failed(fname);
  //-----------------------------------------------
  status = rs_mmap(num_words_per_title, &nw_X, &n_nw_X, 0);
  cBYE(status);
  num_titles = n_nw_X / sizeof(int);
  if ( ( num_titles * sizeof(int) ) != n_nw_X ) { go_BYE(-1); }
  num_words = (unsigned int *)nw_X;
  //-----------------------------------------------
  status = rs_mmap(hash_words_in_title, &hw_X, &n_hw_X, 0);
  cBYE(status);
  itemp = n_hw_X / sizeof(int);
  if ( ( itemp * sizeof(int) ) != n_hw_X ) { go_BYE(-1); }
  hash_words = (unsigned int *)hw_X;
  //-----------------------------------------------
  zero_string(fname, len);
  strcpy(fname, op_file_prefix);
  strcat(fname, ".twdict.bin");
  status = rs_mmap(fname, &twdict_X, &n_twdict_X, 0);
  cBYE(status);
  num_dict_words = n_twdict_X / sizeof(HT3_TYPE);
  if ( ( num_dict_words * sizeof(HT3_TYPE) ) != n_twdict_X ) { go_BYE(-1); }
  //-----------------------------------------------
  for ( int i = 0, wc = 0; i < num_titles; i++ ) { 
    hw_i = hash_words[i];
    status = hash_to_str(twdict)X, num_dict_words,  hw_i,
	&found, wc_str_buffer);

    nw_i = num_words[i];
    fprintf(stdout, "Title %d: NumWords = %d \n", i+1, nw_i);
    fprintf(stdout, "(");
    for ( int j = 0; j < nw_i; j++ ) { 
      wc_buf[0] = fc_ptr[j];
      fprintf(stdout, "%S -> %u ", wc_buf, hash_words[j]);
    }
    fprintf(stdout, ")\n");
    hash_words += nw_i;
    fc_ptr += (nw_i + 1 );
  }
BYE:
  free_if_non_null(offset);
  free_if_non_null(fname);
  rs_munmap(nw_X, n_nw_X);
  rs_munmap(hw_X, n_hw_X);
  rs_munmap(twdict_X, n_twdict_X);
  return(status);
}