remove unnecessary leading '/' from filename
PATCH 1/1 remove unnecessary leading '/' from filename
In osm_db_domain_init() the filename is appended to a path string 'db_dir_name' which contains a trailing '/'. Remove extra '/'.
opensm/opensm/osm_lid_mgr.c +1 -1
@@ -239,7 +239,7 @@ ib_api_status_t osm_lid_mgr_init(IN osm_lid_mgr_t * p_mgr, IN osm_sm_t * sm) p_mgr->p_lock = sm->p_lock;/* we initialize and restore the db domain of guid to lid map */ - p_mgr->p_g2l =osm_db_domain_init (p_mgr->p_db,"/guid2lid" ); + p_mgr->p_g2l =osm_db_domain_init (p_mgr->p_db,"guid2lid" );if (!p_mgr->p_g2l) {OSM_LOG (p_mgr->p_log,OSM_LOG_ERROR ,"ERR 0316: " "Error initializing Guid-to-Lid persistent database\n" );
Quoted 11 lines · Stan C. Smith
In
osm_db_domain_init()the filename is appended to a path string 'db_dir_name' which contains a trailing '/'. Remove extra '/'.Signed-off-by stan smith <[email protected]>opensm/opensm/osm_lid_mgr.c +0
-0
opensm/opensm/osm_lid_mgr.c ib_api_status_t osm_lid_mgr_init(IN osm_lid_mgr_t * p_mgr, IN osm_sm_t * sm) · line 242
Quoted 5 lines
opensm/opensm/osm_lid_mgr.c +1
-1@@ -239,7 +239,7 @@ ib_api_status_t osm_lid_mgr_init(IN osm_lid_mgr_t * p_mgr, IN osm_sm_t * sm) p_mgr->p_lock = sm->p_lock;/* we initialize and restore the db domain of guid to lid map */ - p_mgr->p_g2l =osm_db_domain_init (p_mgr->p_db,"/guid2lid" ); + p_mgr->p_g2l =osm_db_domain_init (p_mgr->p_db,"guid2lid" );
I think that this can break when OSM_CACHE_DIR is supplied as environment variable and its value doesn't have '/' at the end. The patch below is from 2007 and it fixed this issue.
Sasha
commit 907b95ec02d6a794ee8f6d6996cc6350a476bd15
Author: Albert L. Chu <[email protected]> Date: Wed Mar 14 07:08:58 2007 -0500
OpenSM: Fix cache filename corner case
osm/opensm/osm_lid_mgr.c +1 -1
@@ -282,7 +282,7 @@ osm_lid_mgr_init( p_mgr->p_req = p_req;/* we initialize and restore the db domain of guid to lid map */ - p_mgr->p_g2l =osm_db_domain_init (p_mgr->p_db,"guid2lid" ); + p_mgr->p_g2l =osm_db_domain_init (p_mgr->p_db,"/guid2lid" );if (! p_mgr->p_g2l) { osm_log( p_mgr->p_log, OSM_LOG_ERROR,
osm/opensm/osm_subnet.c +3 -3
@@ -745,7 +745,7 @@ osm_subn_rescan_conf_file( p_cache_dir =OSM_DEFAULT_CACHE_DIR ;strcpy (file_name, p_cache_dir); -strcat (file_name,"opensm.opts" ); +strcat (file_name,"/opensm.opts" ); opts_file =fopen (file_name,"r" );if (!opts_file)
@@ -838,7 +838,7 @@ osm_subn_parse_conf_file( p_cache_dir =OSM_DEFAULT_CACHE_DIR ;strcpy (file_name, p_cache_dir); -strcat (file_name,"opensm.opts" ); +strcat (file_name,"/opensm.opts" ); opts_file =fopen (file_name,"r" );if (!opts_file)return ;
@@ -1096,7 +1096,7 @@ osm_subn_write_conf_file( p_cache_dir =OSM_DEFAULT_CACHE_DIR ;strcpy (file_name, p_cache_dir); -strcat (file_name,"opensm.opts" ); +strcat (file_name,"/opensm.opts" ); opts_file =fopen (file_name,"w" );if (!opts_file)return ;
Quoted 4 lines
opensm/opensm/osm_lid_mgr.c +0
-0if (!p_mgr->p_g2l) {OSM_LOG (p_mgr->p_log,OSM_LOG_ERROR ,"ERR 0316: " "Error initializing Guid-to-Lid persistent database\n" );
Quoted 24 lines · Sasha Khapyorsky
Quoted 16 lines · Stan C. Smith
In
osm_db_domain_init()the filename is appended to a path string 'db_dir_name' which contains a trailing '/'. Remove extra '/'.Signed-off-by stan smith <[email protected]>opensm/opensm/osm_lid_mgr.c +0
-0@@ -239,7 +239,7 @@ ib_api_status_t osm_lid_mgr_init(IN
osm_lid_mgr_t*p_mgr, INosm_sm_t* sm)p_mgr->p_lock=sm->p_lock;/* we initialize and restore the db domain of guid to lid map */opensm/opensm/osm_lid_mgr.c
Quoted 2 lines
opensm/opensm/osm_lid_mgr.c +1
-1- p_mgr->p_g2l =osm_db_domain_init (p_mgr->p_db,"/guid2lid" ); + p_mgr->p_g2l =osm_db_domain_init (p_mgr->p_db,"guid2lid" );I think that this can break when
OSM_CACHE_DIRis supplied as environment variable and its value doesn't have '/' at the end. The patch below is from 2007 and it fixed this issue.
Quoted 1 line
Sasha
I believe removing the starting '/' from guid2lid filename is the correct fix for a couple of reasons:
1) prefixing a / to a filename seems strange when the path name is spec'ed as having a trailing / ?
2) / in a windows filename is a problem.
Due to comments in opensm/include/opensm/osm_base.h which explicitly speak to the requirement for a trailing directory delimiter, the missing functionality is the check for the trailing directory delimiter when using an environment var to build a path. One could be a 'good' guy and if the env is missing the trailing / then add one.
Do want me to resubmit with the env var check/fix or do you want to do it?
Stan.
Quoted 59 lines
commit
907b95ec02d6a794ee8f6d6996cc6350a476bd15Author: Albert L. Chu <[email protected]> Date: Wed Mar 14 07:08:58 2007 -0500OpenSM: Fix cache filename corner case
Signed-off-by Albert L. Chu <[email protected]>Signed-off-by Hal Rosenstock <[email protected]>osm/opensm/osm_lid_mgr.c +1
-1@@ -282,7 +282,7 @@ osm_lid_mgr_init( p_mgr->p_req = p_req;/* we initialize and restore the db domain of guid to lid map */ - p_mgr->p_g2l =osm_db_domain_init (p_mgr->p_db,"guid2lid" ); + p_mgr->p_g2l =osm_db_domain_init (p_mgr->p_db,"/guid2lid" );if (! p_mgr->p_g2l) { osm_log( p_mgr->p_log, OSM_LOG_ERROR,osm/opensm/osm_subnet.c +3
-3@@ -745,7 +745,7 @@ osm_subn_rescan_conf_file( p_cache_dir =OSM_DEFAULT_CACHE_DIR ;strcpy (file_name, p_cache_dir); -strcat (file_name,"opensm.opts" ); +strcat (file_name,"/opensm.opts" ); opts_file =fopen (file_name,"r" );if (!opts_file)@@ -838,7 +838,7 @@ osm_subn_parse_conf_file( p_cache_dir =OSM_DEFAULT_CACHE_DIR ;strcpy (file_name, p_cache_dir); -strcat (file_name,"opensm.opts" ); +strcat (file_name,"/opensm.opts" ); opts_file =fopen (file_name,"r" );if (!opts_file)return ;@@ -1096,7 +1096,7 @@ osm_subn_write_conf_file( p_cache_dir =OSM_DEFAULT_CACHE_DIR ;strcpy (file_name, p_cache_dir); -strcat (file_name,"opensm.opts" ); +strcat (file_name,"/opensm.opts" ); opts_file =fopen (file_name,"w" );if (!opts_file)return ;Quoted 4 lines
if (!p_mgr->p_g2l) { OSM_LOG(p_mgr->p_log, OSM_LOG_ERROR, "ERR 0316: " "Error initializing Guid-to-Lid persistent database\n");
A message that is not in the archive (sent off-list or not yet received): 3F6F638B8D880340AB536D29CD4C1E1912C896BBDA-osO9UTpF0USkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org
Hi Stan,
Quoted 3 lines · Stan
I believe removing the starting '/' from guid2lid filename is the correct fix for a couple of reasons:
1) prefixing a / to a filename seems strange when the path name is spec'ed as having a trailing / ?
I agree. We need to care about making path properly rather than introduce a restrictions for directory names definitions.
Sasha
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/1 opensm/osm_db_files.c: add '/' path delimited
Add '/' path delimiter unconditionally on file path generation.
--- opensm/opensm/osm_db_files.c | 14 ++++++-------- 1 files changed, 6 insertions(+), 8 deletions(-)
opensm/opensm/osm_db_files.c +6 -8
@@ -195,7 +195,7 @@ osm_db_domain_t *osm_db_domain_init(IN osm_db_t * p_db, IN char *domain_name) {osm_db_domain_t *p_domain;osm_db_domain_imp_t *p_domain_imp; -int dir_name_len; +size_t path_len;osm_log_t *p_log = p_db->p_log;FILE *p_file;
@@ -209,16 +209,14 @@ osm_db_domain_t *osm_db_domain_init(IN osm_db_t * p_db, IN char *domain_name) (osm_db_domain_imp_t *)malloc (sizeof (osm_db_domain_imp_t));CL_ASSERT (p_domain_imp !=NULL ); - dir_name_len =strlen (((osm_db_imp_t *) p_db->p_db_imp)->db_dir_name); + path_len =strlen (((osm_db_imp_t *) p_db->p_db_imp)->db_dir_name) + +strlen (domain_name) +2 ;/* set the domain file name */ - p_domain_imp->file_name = - (char *)malloc (sizeof (char ) * (dir_name_len) +strlen (domain_name) + -2 ); + p_domain_imp->file_name =malloc (path_len);CL_ASSERT (p_domain_imp->file_name !=NULL ); -strcpy (p_domain_imp->file_name, - ((osm_db_imp_t *) p_db->p_db_imp)->db_dir_name); -strcat (p_domain_imp->file_name, domain_name); +snprintf (p_domain_imp->file_name, path_len,"%s/%s" , + ((osm_db_imp_t *) p_db->p_db_imp)->db_dir_name, domain_name);/* make sure the file exists - or exit if not writable */ p_file =fopen (p_domain_imp->file_name,"a+" );
Signature · 6 lines
1.6.5.3 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/1 opensm/osm_base.h: remove trailing '/' in OSM_DEFAULT_CACHE_DIR
Remove trailing '/' character in OSM_DEFAULT_CACHE_DIR definition as well as misleading comment about its mandatory status.
--- opensm/include/opensm/osm_base.h | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
opensm/include/opensm/osm_base.h +1 -2
@@ -192,14 +192,13 @@ BEGIN_C_DECLS* * DESCRIPTION * Specifies the default cache directory for the db files. -* Note that the directory must appear with "/" ("\\" for windows) at the end. * * SYNOPSIS */ #ifdef __WIN__#define OSM_DEFAULT_CACHE_DIR GetOsmCachePath()#else -#define OSM_DEFAULT_CACHE_DIR "/var/cache/opensm/" +#define OSM_DEFAULT_CACHE_DIR "/var/cache/opensm"#endif /***********/ /****d* OpenSM: Base/OSM_DEFAULT_LOG_FILE
Signature · 6 lines
1.6.5.3 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RE: [PATCH] opensm/osm_db_files.c: add '/' path delimited
In reply to Sasha KhapyorskyQuoted 1 line · Sasha Khapyorsky
Add '/' path delimiter unconditionally on file path generation.
Any chance you could make the path delimiter a #define so there is not an explicit Linux filesystem assumption?
Quoted 34 lines
--- opensm/opensm/osm_db_files.c | 14 ++++++-------- 1 files changed, 6 insertions(+), 8 deletions(-)opensm/opensm/osm_db_files.c +1
-4@@ -195,7 +195,7 @@ osm_db_domain_t *osm_db_domain_init(IN osm_db_t * p_db, IN char *domain_name) {osm_db_domain_t *p_domain;osm_db_domain_imp_t *p_domain_imp; -int dir_name_len; +size_t path_len;osm_log_t *p_log = p_db->p_log;FILE *p_file;@@ -209,16 +209,14 @@ osm_db_domain_t *osm_db_domain_init(IN osm_db_t * p_db, IN char *domain_name) (osm_db_domain_imp_t *)malloc (sizeof (osm_db_domain_imp_t));CL_ASSERT (p_domain_imp !=NULL ); - dir_name_len =strlen (((osm_db_imp_t *) p_db->p_db_imp)->db_dir_name); + path_len = strlen(((osm_db_imp_t *) p_db->p_db_imp)->db_dir_name) + +strlen (domain_name) +2 ;/* set the domain file name */ - p_domain_imp->file_name = - (char *)malloc(sizeof(char) * (dir_name_len) +
strlen(domain_name)+opensm/opensm/osm_db_files.c +0
-1- 2);
opensm/opensm/osm_db_files.c osm_db_domain_t *osm_db_domain_init(IN osm_db_t * p_db, IN char *domain_name) · line 222
Quoted 10 lines
opensm/opensm/osm_db_files.c +3
-3+ p_domain_imp->file_name =malloc (path_len);CL_ASSERT (p_domain_imp->file_name !=NULL ); -strcpy (p_domain_imp->file_name, - ((osm_db_imp_t *) p_db->p_db_imp)->db_dir_name); -strcat (p_domain_imp->file_name, domain_name); +snprintf (p_domain_imp->file_name, path_len,"%s/%s" , + ((osm_db_imp_t *) p_db->p_db_imp)->db_dir_name, domain_name);/* make sure the file exists - or exit if not writable */ p_file =fopen (p_domain_imp->file_name,"a+" );
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 3F6F638B8D880340AB536D29CD4C1E1912CC7DAF13-osO9UTpF0USkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org
Re: [PATCH] opensm/osm_db_files.c: add '/' path delimited
Quoted 5 lines · Stan
Quoted 1 line · Sasha Khapyorsky
Add '/' path delimiter unconditionally on file path generation.
Any chance you could make the path delimiter a #define so there is not an explicit Linux filesystem assumption?
As far as I know the Windows kernel recognizes both forward and backward slashes as a path separator.
Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): e2e108260911280936w27de9761r7a8818184f184535-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
RE: [PATCH] opensm/osm_db_files.c: add '/' path delimited
Quoted 6 lines · Bart Van Assche
Quoted 4 lines · Stan
Quoted 1 line · Sasha Khapyorsky
Add '/' path delimiter unconditionally on file path generation.
Quoted 7 lines
Quoted 2 lines
Any chance you could make the path delimiter a #define so there is not an explicit Linux filesystem assumption?
As far as I know the Windows kernel recognizes both forward and backward slashes as a path separator.
Bart.
Who would of thought...windows _open() & fopen() can now tolerate a mix-n-match of path delimiters; Implementations do change.
Sasha, skip the #define thought.
Thanks Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 4 lines · Sasha Khapyorsky
Hi Stan,
Quoted 1 line · Stan
Quoted 8 lines
Quoted 3 lines
I believe removing the starting '/' from guid2lid filename is the correct fix for a couple of reasons: 1) prefixing a / to a filename seems strange when the path name is spec'ed as having a trailing / ?
I agree. We need to care about making path properly rather than introduce a restrictions for directory names definitions.
Sasha
Hello,
OK on proper paths.
What about the excellent point you raised in previous discussions about those pathnames which are input from environment vars which could be improperly formed? For badly formed paths from ENV vars (lacking trailing '/'), is it sufficient to let open() fail and output path/filename to osm log file?
Stan.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 3F6F638B8D880340AB536D29CD4C1E1912CC7DAF12-osO9UTpF0USkrb+BlOpmy7fspsVTdybXVpNB7YpNyf8@public.gmane.org
Quoted 1 line · Stan
What about the excellent point you raised in previous discussions about those pathnames which are input from environment vars which could be improperly formed? For badly formed paths from ENV vars (lacking trailing '/'), is it sufficient to let
open()fail and output path/filename to osm log file?
We are adding delimiter now (in a file path building code), so it is not mandatory to have trailing '/' in directory name environment variable.
Sasha
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 784A3771E5D143179461A7D5151AE78C-Zpru7NauK7drdx17CPfAsdBPR1lH4CV8@public.gmane.org
Sasha Khapyorsky
AppliedQuoted 5 lines · Stan C. Smith
In
osm_db_domain_init()the filename is appended to a path string 'db_dir_name' which contains a trailing '/'. Remove extra '/'.Signed-off-by stan smith <[email protected]>
Applied. Thanks.
Sasha
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html