Ejemplo n.º 1
0
/*
 * Sets the default logging method (whether to a specific filepath or syslog.
 * During initialization this is used and separate layer logging defaults to
 * this destination.
 */
void SetDefaultLogging(const char *name)
{
  int component;

  SetComponentLogFile(COMPONENT_LOG, name);

  LogChanges("Setting log destination for ALL components to %s", name);
  for(component = COMPONENT_ALL; component < COMPONENT_COUNT; component++)
    {
      if (component == COMPONENT_STDOUT)
        continue;
      SetComponentLogFile(component, name);
    }
}                               /* SetDefaultLogging */
Ejemplo n.º 2
0
fsal_status_t LUSTREFSAL_load_FSAL_parameter_from_conf(config_file_t in_config,
                                                       fsal_parameter_t * out_parameter)
{
  int err;
  int var_max, var_index;
  char *key_name;
  char *key_value;
  config_item_t block;

  int DebugLevel = -1;
  char *LogFile = NULL;

  block = config_FindItemByName(in_config, CONF_LABEL_FSAL);

  /* cannot read item */

  if(block == NULL)
    {
      LogCrit(COMPONENT_FSAL,"FSAL LOAD PARAMETER: Cannot read item \"%s\" from configuration file",
                 CONF_LABEL_FSAL);
      ReturnCode(ERR_FSAL_NOENT, 0);
    }
  else if(config_ItemType(block) != CONFIG_ITEM_BLOCK)
    {
      LogCrit(COMPONENT_FSAL,"FSAL LOAD PARAMETER: Item \"%s\" is expected to be a block",
                 CONF_LABEL_FSAL);
      ReturnCode(ERR_FSAL_INVAL, 0);
    }

  /* read variable for fsal init */

  var_max = config_GetNbItems(block);

  for(var_index = 0; var_index < var_max; var_index++)
    {
      config_item_t item;

      item = config_GetItemByIndex(block, var_index);

      err = config_GetKeyValue(item, &key_name, &key_value);
      if(err)
        {
	  LogCrit(COMPONENT_FSAL,
              "FSAL LOAD PARAMETER: ERROR reading key[%d] from section \"%s\" of configuration file.",
               var_index, CONF_LABEL_FSAL);
          ReturnCode(ERR_FSAL_SERVERFAULT, err);
        }

      if(!STRCMP(key_name, "DebugLevel"))
        {
          DebugLevel = ReturnLevelAscii(key_value);

          if(DebugLevel == -1)
            {
              LogCrit(COMPONENT_FSAL,"FSAL LOAD PARAMETER: ERROR: Invalid debug level name: \"%s\".",
                         key_value);
              ReturnCode(ERR_FSAL_INVAL, -1);
            }

        }
      else if(!STRCMP(key_name, "LogFile"))
        {

          LogFile = key_value;

        }
      else if(!STRCMP(key_name, "Max_FS_calls"))
        {

          int maxcalls = s_read_int(key_value);

          if(maxcalls < 0)
            {
              LogCrit(COMPONENT_FSAL,
                  "FSAL LOAD PARAMETER: ERROR: Unexpected value for %s: null or positive integer expected.",
                   key_name);
              ReturnCode(ERR_FSAL_INVAL, 0);
            }

          out_parameter->fsal_info.max_fs_calls = (unsigned int)maxcalls;

        }
      else
        {
          LogCrit(COMPONENT_FSAL,
              "FSAL LOAD PARAMETER: ERROR: Unknown or unsettable key: %s (item %s)",
               key_name, CONF_LABEL_FSAL);
          ReturnCode(ERR_FSAL_INVAL, 0);
        }

    }

  /* init logging */
  if(LogFile)
    SetComponentLogFile(COMPONENT_FSAL, LogFile);

  if(DebugLevel != -1)
    SetComponentLogLevel(COMPONENT_FSAL, DebugLevel);

  ReturnCode(ERR_FSAL_NO_ERROR, 0);

}                               /* FSAL_load_FSAL_parameter_from_conf */
Ejemplo n.º 3
0
/*
 *
 * cache_content_read_conf_client_parameter: read the configuration for a client to File Content layer.
 * 
 * Reads the configuration for a client to File Content layer (typically a worker thread).
 * 
 * @param in_config [IN] configuration file handle
 * @param pparam [OUT] read parameters
 *
 * @return CACHE_CONTENT_SUCCESS if ok, CACHE_CONTENT_INVALID_ARGUMENT otherwise.
 *
 */
cache_content_status_t cache_content_read_conf_client_parameter(config_file_t in_config,
                                                                cache_content_client_parameter_t * pparam)
{
  int var_max;
  int var_index;
  int err;
  char *key_name;
  char *key_value;
  config_item_t block;

  int DebugLevel = -1;
  char *LogFile = NULL;

  /* Is the config tree initialized ? */
  if(in_config == NULL || pparam == NULL)
    return CACHE_CONTENT_INVALID_ARGUMENT;

  /* Get the config BLOCK */
  if((block = config_FindItemByName(in_config, CONF_LABEL_CACHE_CONTENT_CLIENT)) == NULL)
    {
      /* fprintf(stderr, "Cannot read item \"%s\" from configuration file\n", CONF_LABEL_CACHE_CONTENT_CLIENT ) ; */
      return CACHE_CONTENT_NOT_FOUND;
    }
  else if(config_ItemType(block) != CONFIG_ITEM_BLOCK)
    {
      /* Expected to be a block */
      return CACHE_CONTENT_INVALID_ARGUMENT;
    }

  var_max = config_GetNbItems(block);

  for(var_index = 0; var_index < var_max; var_index++)
    {
      config_item_t item;

      item = config_GetItemByIndex(block, var_index);

      /* Get key's name */
      if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0)
        {
          fprintf(stderr,
                  "Error reading key[%d] from section \"%s\" of configuration file.\n",
                  var_index, CONF_LABEL_CACHE_CONTENT_CLIENT);
          return CACHE_CONTENT_INVALID_ARGUMENT;
        }

      if(!strcasecmp(key_name, "LRU_Prealloc_PoolSize"))     /** @todo: BUGAZOMEU: to be removed */
        {
          //pparam->lru_param.nb_entry_prealloc = atoi( key_value ) ;
        }
      else if(!strcasecmp(key_name, "LRU_Nb_Call_Gc_invalid"))      /** @todo: BUGAZOMEU: to be removed */
        {
          //pparam->lru_param.nb_call_gc_invalid = atoi( key_value ) ;
        }
      else if(!strcasecmp(key_name, "Entry_Prealloc_PoolSize"))      /** @todo: BUGAZOMEU: to be removed */
        {
          pparam->nb_prealloc_entry = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "Cache_Directory"))
        {
          strcpy(pparam->cache_dir, key_value);
        }
      else if(!strcasecmp(key_name, "Refresh_FSAL_Force"))
        {
          pparam->flush_force_fsal = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "DebugLevel"))
        {
          DebugLevel = ReturnLevelAscii(key_value);

          if(DebugLevel == -1)
            {
              LogCrit(COMPONENT_CACHE_CONTENT,
                  "cache_content_read_conf: ERROR: Invalid debug level name: \"%s\".",
                   key_value);
              return CACHE_CONTENT_INVALID_ARGUMENT;
            }
        }
      else if(!strcasecmp(key_name, "LogFile"))
        {
          LogFile = key_value;
        }
      else if(!strcasecmp(key_name, "Max_Fd"))
        {
          pparam->max_fd = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "OpenFile_Retention"))
        {
          pparam->retention = atoi(key_value);
        }
      else if(!strcasecmp(key_name, "Use_OpenClose_cache"))
        {
          pparam->use_fd_cache = StrToBoolean(key_value);
        }
      else
        {
          fprintf(stderr,
                  "Unknown or unsettable key: %s (item %s)\n",
                  key_name, CONF_LABEL_CACHE_CONTENT_CLIENT);
          return CACHE_CONTENT_INVALID_ARGUMENT;
        }
    }

  fcc_debug_level = DebugLevel;
  if(LogFile) {
    LogEvent(COMPONENT_INIT, "Setting log file of emergency cache flush thread to %s",
	     LogFile);
    strncpy(fcc_log_path, LogFile, MAXPATHLEN);
  }
  else {
    LogDebug(COMPONENT_INIT, "No log file set for emergency cache flush thread in configuration. Setting to default.") ;
    strncpy(fcc_log_path, "/dev/null", MAXPATHLEN);
  }

  /* init logging */
  if(LogFile)
    SetComponentLogFile(COMPONENT_CACHE_CONTENT, LogFile);

  if(DebugLevel > -1)
    SetComponentLogLevel(COMPONENT_CACHE_CONTENT, DebugLevel);

  return CACHE_CONTENT_SUCCESS;
}                               /* cache_content_read_conf_client_parameter */
Ejemplo n.º 4
0
/**
 *  Tests about Log streams and special printf functions.
 */
void Test1(char *str, char *file)
{
	char tempstr[2048];
	struct display_buffer buffer = { sizeof(tempstr), tmpstr, tmpstr };
	int i;

	SetComponentLogFile(COMPONENT_INIT, "STDOUT");
	LogAlways(COMPONENT_INIT, "%s", "Starting Log Tests");
	LogTest("My PID = %d", getpid());

	LogTest("------------------------------------------------------");
	LogTest("Test conversion of log levels between string and integer");
	for (i = NIV_NULL; i < NB_LOG_LEVEL; i++) {
		int j;
		if (strcmp(tabLogLevel[i].str, ReturnLevelInt(i)) != 0) {
			LogTest(
			     "FAILURE: Log level %d did not convert to %s, it converted to %s",
			     i, tabLogLevel[i].str, ReturnLevelInt(i));
			exit(1);
		}
		j = ReturnLevelAscii(tabLogLevel[i].str);
		if (j != i) {
			LogTest(
			     "FAILURE: Log level %s did not convert to %d, it converted to %d",
			     tabLogLevel[i].str, i, j);
			exit(1);
		}
	}

	LogTest("------------------------------------------------------");

	LogTest("\nTesting possible environment variable");
	LogTest("COMPONENT_MEMCORRUPT debug level is %s",
		ReturnLevelInt(LogComponents[COMPONENT_MEMCORRUPT].
			       comp_log_level));
	LogFullDebug(COMPONENT_MEMCORRUPT,
		     "This should appear if environment is set properly");

	LogTest("------------------------------------------------------");
	LogTest("Send some messages to various files");
	SetComponentLogFile(COMPONENT_DISPATCH, "STDERR");
	LogEvent(COMPONENT_DISPATCH, "This should go to stderr");
	SetComponentLogFile(COMPONENT_DISPATCH, "STDOUT");
	LogEvent(COMPONENT_DISPATCH, "This should go to stdout");
	SetComponentLogFile(COMPONENT_DISPATCH, "SYSLOG");
	LogEvent(COMPONENT_DISPATCH, "This should go to syslog (verf = %s)",
		 str);
	LogTest("About to set %s", file);
	SetComponentLogFile(COMPONENT_DISPATCH, file);
	LogTest("Got it set");
	LogEvent(COMPONENT_DISPATCH, "This should go to %s", file);

	/* Set up for tests that will verify what was actually produced by log
	 * messages. This is used to test log levels and to test the
	 * log_vnsprintf function.
	 */
	/** @todo FSF: this can be done by setting the right header flags and
	 * peeking at the context buffer.
	 */
	SetComponentLogBuffer(COMPONENT_MAIN, &buffer);
	SetComponentLogBuffer(COMPONENT_INIT, &buffer);

	LogTest("------------------------------------------------------");
	LogTest("Test all levels of log filtering");
	SetComponentLogLevel(COMPONENT_MAIN, NIV_NULL);
	TestAlways(true, tempstr, COMPONENT_MAIN, "LogAlways (should print)");
	TestMajor(false, tempstr, COMPONENT_MAIN, "LogMajor (shouldn't print)");
	TestCrit(false, tempstr, COMPONENT_MAIN, "LogCrit (shouldn't print)");
	TestEvent(false, tempstr, COMPONENT_MAIN, "LogEvent (shouldn't print)");
	TestDebug(false, tempstr, COMPONENT_MAIN, "LogDebug (shouldn't print)");
	TestFullDebug(false, tempstr, COMPONENT_MAIN,
		      "LogFullDebug (shouldn't print)");
	SetComponentLogLevel(COMPONENT_MAIN, NIV_MAJOR);
	TestAlways(true, tempstr, COMPONENT_MAIN, "LogAlways (should print)");
	TestMajor(true, tempstr, COMPONENT_MAIN, "LogMajor (should print)");
	TestCrit(false, tempstr, COMPONENT_MAIN, "LogCrit (shouldn't print)");
	TestEvent(false, tempstr, COMPONENT_MAIN, "LogEvent (shouldn't print)");
	TestDebug(false, tempstr, COMPONENT_MAIN, "LogDebug (shouldn't print)");
	TestFullDebug(false, tempstr, COMPONENT_MAIN,
		      "LogFullDebug (shouldn't print)");
	SetComponentLogLevel(COMPONENT_MAIN, NIV_CRIT);
	TestAlways(true, tempstr, COMPONENT_MAIN, "LogAlways (should print)");
	TestMajor(true, tempstr, COMPONENT_MAIN, "LogMajor (should print)");
	TestCrit(true, tempstr, COMPONENT_MAIN, "LogCrit (should print)");
	TestEvent(false, tempstr, COMPONENT_MAIN, "LogEvent (shouldn't print)");
	TestDebug(false, tempstr, COMPONENT_MAIN, "LogDebug (shouldn't print)");
	TestFullDebug(false, tempstr, COMPONENT_MAIN,
		      "LogFullDebug (shouldn't print)");
	SetComponentLogLevel(COMPONENT_MAIN, NIV_EVENT);
	TestAlways(true, tempstr, COMPONENT_MAIN, "LogAlways (should print)");
	TestMajor(true, tempstr, COMPONENT_MAIN, "LogMajor (should print)");
	TestCrit(true, tempstr, COMPONENT_MAIN, "LogCrit (should print)");
	TestEvent(true, tempstr, COMPONENT_MAIN, "LogEvent (should print)");
	TestDebug(false, tempstr, COMPONENT_MAIN, "LogDebug (shouldn't print)");
	TestFullDebug(false, tempstr, COMPONENT_MAIN,
		      "LogFullDebug (shouldn't print)");
	SetComponentLogLevel(COMPONENT_MAIN, NIV_DEBUG);
	TestAlways(true, tempstr, COMPONENT_MAIN, "LogAlways (should print)");
	TestMajor(true, tempstr, COMPONENT_MAIN, "LogMajor (should print)");
	TestCrit(true, tempstr, COMPONENT_MAIN, "LogCrit (should print)");
	TestEvent(true, tempstr, COMPONENT_MAIN, "LogEvent (should print)");
	TestDebug(true, tempstr, COMPONENT_MAIN, "LogDebug (should print)");
	TestFullDebug(false, tempstr, COMPONENT_MAIN,
		      "LogFullDebug (shouldn't print)");
	SetComponentLogLevel(COMPONENT_MAIN, NIV_FULL_DEBUG);
	TestAlways(true, tempstr, COMPONENT_MAIN, "LogAlways (should print)");
	TestMajor(true, tempstr, COMPONENT_MAIN, "LogMajor (should print)");
	TestCrit(true, tempstr, COMPONENT_MAIN, "LogCrit (should print)");
	TestEvent(true, tempstr, COMPONENT_MAIN, "LogEvent (should print)");
	TestDebug(true, tempstr, COMPONENT_MAIN, "LogDebug (should print)");
	TestFullDebug(true, tempstr, COMPONENT_MAIN,
		      "LogFullDebug (should print)");
}
Ejemplo n.º 5
0
/**
 *  Tests about Log streams and special printf functions.
 */
int Test1(char *str, char *file)
{
  char tempstr[2048];
  int  i;

  SetComponentLogFile(COMPONENT_INIT, "STDOUT");
  LogAlways(COMPONENT_INIT, "%s", "Starting Log Tests");
  LogTest("My PID = %d", getpid());

  LogTest("------------------------------------------------------");

  LogTest("Test ERR_DUMMY");
  LogTest("A numerical error : error %%d = %%J%%R, in ERR_DUMMY_2 %%J%%R");
  log_snprintf(tempstr, sizeof(tempstr),
               "A numerical error : error %d = %J%R, in ERR_DUMMY_2 %J%R",
               ERR_SIGACTION, ERR_SYS, ERR_SIGACTION, ERR_DUMMY, ERR_DUMMY_2);
  LogTest("%s", tempstr);
  LogTest("A numerical error : error %d = %J%R, in ERR_DUMMY_1 %J%R",
          ERR_OPEN, ERR_SYS, ERR_OPEN, ERR_DUMMY, ERR_DUMMY_1);

  LogTest("------------------------------------------------------");
  LogTest("Test conversion of log levels between string and integer");
  for (i = NIV_NULL; i < NB_LOG_LEVEL; i++)
    {
      int j;
      if (strcmp(tabLogLevel[i].str, ReturnLevelInt(i)) != 0)
        {
          LogTest("FAILURE: Log level %d did not convert to %s, it converted to %s",
                  i, tabLogLevel[i].str, ReturnLevelInt(i));
          exit(1);
        }
      j = ReturnLevelAscii(tabLogLevel[i].str);
      if (j != i)
        {
          LogTest("FAILURE: Log level %s did not convert to %d, it converted to %d",
                  tabLogLevel[i].str, i, j);
          exit(1);
        }
    }

  LogTest("------------------------------------------------------");

  log_snprintf(tempstr, sizeof(tempstr), "Test log_snprintf");
  LogTest("%s", tempstr);
  LogTest("\nTesting LogError function");
  LogError(COMPONENT_CONFIG, ERR_SYS, ERR_MALLOC, EINVAL);
  LogTest("\nTesting possible environment variable");
  LogTest("COMPONENT_MEMCORRUPT debug level is %s",
          ReturnLevelInt(LogComponents[COMPONENT_MEMCORRUPT].comp_log_level));
  LogFullDebug(COMPONENT_MEMCORRUPT,
               "This should appear if environment is set properly");

  LogTest("------------------------------------------------------");
  LogTest("Send some messages to various files");
  SetComponentLogFile(COMPONENT_DISPATCH, "STDERR");
  LogEvent(COMPONENT_DISPATCH, "This should go to stderr");
  SetComponentLogFile(COMPONENT_DISPATCH, "STDOUT");
  LogEvent(COMPONENT_DISPATCH, "This should go to stdout");
  SetComponentLogFile(COMPONENT_DISPATCH, "SYSLOG");
  LogEvent(COMPONENT_DISPATCH, "This should go to syslog (verf = %s)", str);
  LogTest("About to set %s", file);
  SetComponentLogFile(COMPONENT_DISPATCH, file);
  LogTest("Got it set");
  LogEvent(COMPONENT_DISPATCH, "This should go to %s", file);

  /*
   * Set up for tests that will verify what was actually produced by log messages.
   * This is used to test log levels and to test the log_vnsprintf function.
   */
  SetComponentLogBuffer(COMPONENT_MAIN, tempstr);
  SetComponentLogBuffer(COMPONENT_INIT, tempstr);

#ifdef _SNMP_ADM_ACTIVE
  {
    snmp_adm_type_union param;
    int rc;
    strcpy(param.string, "FAILED");

    LogTest("------------------------------------------------------");
    LogTest("Test SNMP functions");
    SetLevelDebug(NIV_DEBUG);

    rc = getComponentLogLevel(&param, (void *)COMPONENT_ALL);
    LogTest("getComponentLogLevel(&param, (void *)COMPONENT_ALL) rc=%d result=%s",
            rc, param.string);
    if (rc != 0)
    {
      LogTest("FAILURE");
      exit(1);
    }
    strcpy(param.string, "NIV_EVENT");
    rc = setComponentLogLevel(&param, (void *)COMPONENT_MAIN);
    LogTest("setComponentLogLevel(&param, (void *)COMPONENT_MAIN) rc=%d", rc);
    if (rc != 0)
    {
      LogTest("FAILURE");
      exit(1);
    }
    TestAlways    (TRUE,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
    TestMajor     (TRUE,  tempstr, COMPONENT_MAIN, "LogMajor (should print)");
    TestCrit      (TRUE,  tempstr, COMPONENT_MAIN, "LogCrit (should print)");
    TestEvent     (TRUE,  tempstr, COMPONENT_MAIN, "LogEvent (should print)");
    TestDebug     (FALSE, tempstr, COMPONENT_MAIN, "LogDebug (shouldn't print)");
    TestFullDebug (FALSE, tempstr, COMPONENT_MAIN, "LogFullDebug (shouldn't print)");
    TestAlways    (TRUE,  tempstr, COMPONENT_INIT, "LogAlways (should print)");
    TestMajor     (TRUE,  tempstr, COMPONENT_INIT, "LogMajor (should print)");
    TestCrit      (TRUE,  tempstr, COMPONENT_INIT, "LogCrit (should print)");
    TestEvent     (TRUE,  tempstr, COMPONENT_INIT, "LogEvent (should print)");
    TestDebug     (TRUE,  tempstr, COMPONENT_INIT, "LogDebug (should print)");
    TestFullDebug (FALSE, tempstr, COMPONENT_INIT, "LogFullDebug (shouldn't print)");
  }
#endif /* _SNMP_ADM_ACTIVE */

  LogTest("------------------------------------------------------");
  LogTest("Test all levels of log filtering");
  SetComponentLogLevel(COMPONENT_MAIN, NIV_NULL);
  TestAlways    (TRUE,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
  TestMajor     (FALSE, tempstr, COMPONENT_MAIN, "LogMajor (shouldn't print)");
  TestCrit      (FALSE, tempstr, COMPONENT_MAIN, "LogCrit (shouldn't print)");
  TestEvent     (FALSE, tempstr, COMPONENT_MAIN, "LogEvent (shouldn't print)");
  TestDebug     (FALSE, tempstr, COMPONENT_MAIN, "LogDebug (shouldn't print)");
  TestFullDebug (FALSE, tempstr, COMPONENT_MAIN, "LogFullDebug (shouldn't print)");
  SetComponentLogLevel(COMPONENT_MAIN, NIV_MAJOR);
  TestAlways    (TRUE,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
  TestMajor     (TRUE,  tempstr, COMPONENT_MAIN, "LogMajor (should print)");
  TestCrit      (FALSE, tempstr, COMPONENT_MAIN, "LogCrit (shouldn't print)");
  TestEvent     (FALSE, tempstr, COMPONENT_MAIN, "LogEvent (shouldn't print)");
  TestDebug     (FALSE, tempstr, COMPONENT_MAIN, "LogDebug (shouldn't print)");
  TestFullDebug (FALSE, tempstr, COMPONENT_MAIN, "LogFullDebug (shouldn't print)");
  SetComponentLogLevel(COMPONENT_MAIN, NIV_CRIT);
  TestAlways    (TRUE,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
  TestMajor     (TRUE,  tempstr, COMPONENT_MAIN, "LogMajor (should print)");
  TestCrit      (TRUE,  tempstr, COMPONENT_MAIN, "LogCrit (should print)");
  TestEvent     (FALSE, tempstr, COMPONENT_MAIN, "LogEvent (shouldn't print)");
  TestDebug     (FALSE, tempstr, COMPONENT_MAIN, "LogDebug (shouldn't print)");
  TestFullDebug (FALSE, tempstr, COMPONENT_MAIN, "LogFullDebug (shouldn't print)");
  SetComponentLogLevel(COMPONENT_MAIN, NIV_EVENT);
  TestAlways    (TRUE,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
  TestMajor     (TRUE,  tempstr, COMPONENT_MAIN, "LogMajor (should print)");
  TestCrit      (TRUE,  tempstr, COMPONENT_MAIN, "LogCrit (should print)");
  TestEvent     (TRUE,  tempstr, COMPONENT_MAIN, "LogEvent (should print)");
  TestDebug     (FALSE, tempstr, COMPONENT_MAIN, "LogDebug (shouldn't print)");
  TestFullDebug (FALSE, tempstr, COMPONENT_MAIN, "LogFullDebug (shouldn't print)");
  SetComponentLogLevel(COMPONENT_MAIN, NIV_DEBUG);
  TestAlways    (TRUE,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
  TestMajor     (TRUE,  tempstr, COMPONENT_MAIN, "LogMajor (should print)");
  TestCrit      (TRUE,  tempstr, COMPONENT_MAIN, "LogCrit (should print)");
  TestEvent     (TRUE,  tempstr, COMPONENT_MAIN, "LogEvent (should print)");
  TestDebug     (TRUE,  tempstr, COMPONENT_MAIN, "LogDebug (should print)");
  TestFullDebug (FALSE, tempstr, COMPONENT_MAIN, "LogFullDebug (shouldn't print)");
  SetComponentLogLevel(COMPONENT_MAIN, NIV_FULL_DEBUG);
  TestAlways    (TRUE,  tempstr, COMPONENT_MAIN, "LogAlways (should print)");
  TestMajor     (TRUE,  tempstr, COMPONENT_MAIN, "LogMajor (should print)");
  TestCrit      (TRUE,  tempstr, COMPONENT_MAIN, "LogCrit (should print)");
  TestEvent     (TRUE,  tempstr, COMPONENT_MAIN, "LogEvent (should print)");
  TestDebug     (TRUE,  tempstr, COMPONENT_MAIN, "LogDebug (should print)");
  TestFullDebug (TRUE,  tempstr, COMPONENT_MAIN, "LogFullDebug (should print)");
}
Ejemplo n.º 6
0
int _9p_read_conf( config_file_t   in_config,
                   _9p_parameter_t *pparam )
{
  int var_max;
  int var_index;
  int err;
  char *key_name;
  char *key_value;
  config_item_t block;

  int DebugLevel = -1;
  char *LogFile = NULL;

  /* Is the config tree initialized ? */
  if(in_config == NULL || pparam == NULL)
    return -1 ;

  /* Get the config BLOCK */
  if((block = config_FindItemByName(in_config, CONF_LABEL_9P )) == NULL)
    return -2 ; /* no 9P config, use default */
  else if(config_ItemType(block) != CONFIG_ITEM_BLOCK)
    return -1 ;

  var_max = config_GetNbItems(block);

  for(var_index = 0; var_index < var_max; var_index++)
    {
      config_item_t item;

      item = config_GetItemByIndex(block, var_index);

      /* Get key's name */
      if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0)
        {
          fprintf(stderr,
                  "Error reading key[%d] from section \"%s\" of configuration file.\n",
                  var_index, CONF_LABEL_9P );
          return -1 ;
        }
      if(!strcasecmp(key_name, "_9P_Port"))     
        {
          pparam->_9p_port = atoi( key_value ) ;
        }
      else if(!strcasecmp(key_name, "DebugLevel"))
        {
          DebugLevel = ReturnLevelAscii(key_value);

          if(DebugLevel == -1)
            {
              fprintf(stderr,
                      "9P: ERROR: Invalid debug level name: \"%s\".",
                      key_value);
              return -1 ;
            }
        }
      else if(!strcasecmp(key_name, "LogFile"))
        {
          LogFile = key_value;
        }
      else
        {
          fprintf(stderr,
                  "Unknown or unsettable key: %s (item %s)\n",
                  key_name, CONF_LABEL_9P);
          return -1 ;
        }
    } /* for */

  /* init logging */
  if(LogFile)
    SetComponentLogFile(COMPONENT_9P, LogFile);

  if(DebugLevel > -1)
    SetComponentLogLevel(COMPONENT_9P, DebugLevel);


  return 0 ;
} /* _9p_read_conf */
/**
 * @brief Read the configuration for the Cache inode layer
 *
 * @param[in]  config Configuration file handle
 * @param[out] param  Read parameters
 *
 * @retval CACHE_INODE_SUCCESS on success.
 * @retval CACHE_INODE_NOT_FOUND if stanza not present
 * @retval CACHE_INODE_INVALID_ARGUMENT otherwise
 */
cache_inode_status_t
cache_inode_read_conf_parameter(config_file_t config,
                                cache_inode_parameter_t *param)
{
  int var_max;
  int var_index;
  int err;
  char *key_name;
  char *key_value;
  config_item_t block;

  int DebugLevel = -1;
  char *LogFile = NULL;

  /* Is the config tree initialized ? */
  if(config == NULL || param == NULL)
    return CACHE_INODE_INVALID_ARGUMENT;

  /* Get the config BLOCK */
  if((block = config_FindItemByName(config,
                                    CONF_LABEL_CACHE_INODE)) == NULL)
    {
      LogDebug(COMPONENT_CONFIG,
               "Cannot read item \"%s\" from configuration file",
               CONF_LABEL_CACHE_INODE);
      return CACHE_INODE_NOT_FOUND;
    }
  else if(config_ItemType(block) != CONFIG_ITEM_BLOCK)
    {
      /* Expected to be a block */
      LogCrit(COMPONENT_CONFIG,
              "Item \"%s\" is expected to be a block",
              CONF_LABEL_CACHE_INODE);
      return CACHE_INODE_INVALID_ARGUMENT;
    }

  var_max = config_GetNbItems(block);

  for(var_index = 0; var_index < var_max; var_index++)
    {
      config_item_t item;

      item = config_GetItemByIndex(block, var_index);

      /* Get key's name */
      if((err = config_GetKeyValue(item, &key_name, &key_value)) != 0)
        {
          LogCrit(COMPONENT_CONFIG,
                  "Error reading key[%d] from section \"%s\" of configuration file.",
                  var_index, CONF_LABEL_CACHE_INODE);
          return CACHE_INODE_INVALID_ARGUMENT;
        }

      else if(!strcasecmp(key_name, "Attr_Expiration_Time"))
        {
          err = parse_cache_expire(&param->expire_type_attr,
                                   &param->grace_period_attr,
                                   key_value);
          if(err != CACHE_INODE_SUCCESS)
            return err;
        }
      else if(!strcasecmp(key_name, "Symlink_Expiration_Time"))
        {
          err = parse_cache_expire(&param->expire_type_link,
                                   &param->grace_period_link,
                                   key_value);
          if(err != CACHE_INODE_SUCCESS)
            return err;
        }
      else if(!strcasecmp(key_name, "Directory_Expiration_Time"))
        {
          err = parse_cache_expire(&param->expire_type_dirent,
                                   &param->grace_period_dirent,
                                   key_value);
          if(err != CACHE_INODE_SUCCESS)
            return err;
        }
      else if(!strcasecmp(key_name, "Use_Getattr_Directory_Invalidation"))
        {
          param->getattr_dir_invalidation = StrToBoolean(key_value);
        }
      else if(!strcasecmp(key_name, "Use_Test_Access"))
        {
          param->use_test_access = atoi(key_value);
        }
      else if(!strcasecmp( key_name, "Use_FSAL_Hash" ) )
        {
          param->use_fsal_hash = StrToBoolean(key_value);
        }
      else if(!strcasecmp(key_name, "DebugLevel"))
        {
          DebugLevel = ReturnLevelAscii(key_value);

          if(DebugLevel == -1)
            {
              LogDebug(COMPONENT_CACHE_INODE,
                       "cache_inode_read_conf: ERROR: Invalid debug level name: \"%s\".",
                       key_value);
              return CACHE_INODE_INVALID_ARGUMENT;
            }
        }
      else if(!strcasecmp(key_name, "LogFile"))
        {

          LogFile = key_value;

        }
      else
        {
          LogCrit(COMPONENT_CONFIG,
                  "Unknown or unsettable key: %s (item %s)",
                  key_name, CONF_LABEL_CACHE_INODE);
          return CACHE_INODE_INVALID_ARGUMENT;
        }
    }

  /* init logging */
  if(LogFile)
    SetComponentLogFile(COMPONENT_CACHE_INODE, LogFile);

  if(DebugLevel > -1)
    SetComponentLogLevel(COMPONENT_CACHE_INODE, DebugLevel);

  return CACHE_INODE_SUCCESS;
} /* cache_inode_read_conf_parameter */