[openib-general] [PATCH] osm: fixing OSM_LOG_DIR and OSM_CACHE_DIR treatment

Yevgeny Kliteynik kliteyn at dev.mellanox.co.il
Mon Oct 16 15:15:06 PDT 2006


Sasha Khapyorsky wrote:
> On 11:47 Mon 16 Oct     , Yevgeny Kliteynik wrote:
>> Hi Hal
>>
>> Leaving OSM_LOG_DIR or OSM_CACHE_DIR environment variables
>> empty will cause OSM to wright log or cache files to /
>> since OSM runs as root process.
>>
>> Although one might say that this is just a question of point 
>> of view, I really think that to prevent root directory trashing
>> (as I did by mistake on my machine), empty variable should be 
>> treated as if it is not set.
>> If a user wants the SM to write something to /, he should specify
>> this explicitly by setting "/" as an env. variable value.
>>
>> --
>> Yevgeny
>>
>> Signed-off-by:  Yevgeny Kliteynik <kliteyn at dev.mellanox.co.il>
>>  
>> Index: opensm/osm_db_files.c
>> ===================================================================
>> --- opensm/osm_db_files.c	(revision 9820)
>> +++ opensm/osm_db_files.c	(working copy)
>> @@ -182,6 +182,8 @@ osm_db_init(
>>    CL_ASSERT( p_db_imp != NULL);
>>  
>>    p_db_imp->db_dir_name = getenv("OSM_CACHE_DIR");
>> +  if (p_db_imp->db_dir_name && (strlen(p_db_imp->db_dir_name) == 0))
>> +    p_db_imp->db_dir_name = NULL;
>>    if ( p_db_imp->db_dir_name == NULL )
>>      p_db_imp->db_dir_name = OSM_DEFAULT_CACHE_DIR;
> 
> Would be better something like:
> 
> 	if (p_db_imp->db_dir_name == NULL || !*p_db_imp->dir_name)
> 		p_db_imp->db_dir_name = OSM_DEFAULT_CACHE_DIR;
> 
> This eliminates invocation of strlen() which will return !=0 in most of
> cases.

Sure, I thought about it right after I saw that the patch was applied :)

--
Yevgeny

> 
> The same is below.
> 
> Sasha
> 
>>  
>> Index: opensm/osm_subnet.c
>> ===================================================================
>> --- opensm/osm_subnet.c	(revision 9820)
>> +++ opensm/osm_subnet.c	(working copy)
>> @@ -472,6 +472,8 @@ osm_subn_set_default_opt(
>>    p_opt->honor_guid2lid_file = FALSE;
>>  
>>    p_opt->dump_files_dir = getenv("OSM_TMP_DIR");
>> +  if (p_opt->dump_files_dir && (strlen(p_opt->dump_files_dir) == 0))
>> +    p_opt->dump_files_dir = NULL;
>>    if (!p_opt->dump_files_dir)
>>      p_opt->dump_files_dir = OSM_DEFAULT_TMP_DIR;
>>  
>> @@ -719,6 +721,8 @@ osm_subn_rescan_conf_file(
>>    char *p_key, *p_val ,*p_last;
>>    
>>    /* try to open the options file from the cache dir */
>> +  if (p_cache_dir && (strlen(p_cache_dir) == 0))
>> +    p_cache_dir = NULL;
>>    if (! p_cache_dir)
>>      p_cache_dir = OSM_DEFAULT_CACHE_DIR;
>>  
>> @@ -770,6 +774,8 @@ osm_subn_parse_conf_file(
>>    char *p_key, *p_val ,*p_last;
>>    
>>    /* try to open the options file from the cache dir */
>> +  if (p_cache_dir && (strlen(p_cache_dir) == 0))
>> +    p_cache_dir = NULL;
>>    if (! p_cache_dir)
>>      p_cache_dir = OSM_DEFAULT_CACHE_DIR;
>>  
>> @@ -1002,6 +1008,8 @@ osm_subn_write_conf_file(
>>    FILE *opts_file;
>>    
>>    /* try to open the options file from the cache dir */
>> +  if (p_cache_dir && (strlen(p_cache_dir) == 0))
>> +    p_cache_dir = NULL;
>>    if (! p_cache_dir)
>>      p_cache_dir = OSM_DEFAULT_CACHE_DIR;
>>  
>>
>> _______________________________________________
>> openib-general mailing list
>> openib-general at openib.org
>> http://openib.org/mailman/listinfo/openib-general
>>
>> To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general
>>
> 




More information about the general mailing list