Small fixes and cleanup
cover Small fixes and cleanup
Hi Christophe,
as requested here are the missing bits and some fixes I found on the way.
Please apply.
Hannes Reinecke (5):
multipathd: document return values for check_path() Make 'multipath -t' able to run as normal user
libmultipath: remove 'remove_trailing_chars'
libmultipath: simplify basenamecpy()
libmultipath: Fix overflow in sysfs_get_str()
libmultipath/config.c | 1 - libmultipath/discovery.c | 5 ++--- libmultipath/util.c | 12 +----------- libmultipath/util.h | 1 - multipath/main.c | 22 +++++++++++++--------- multipathd/main.c | 9 +++++++-- 6 files changed, 23 insertions(+), 27 deletions(-)
Signature · 1 line
1.7.12.4
PATCH 1/5 multipathd: document return values for check_path()
check_path() should return '1' if the path has been checked, and '0' otherwise. So fixup missing return values and document it properly.
--- multipathd/main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
multipathd/main.c +5 -2
@@ -1107,6 +1107,9 @@ int update_path_groups(struct multipath *mpp, struct vectors *vecs, int refresh)return 0 ; } +/* +* Returns '1' if the path has been checked, '0' otherwise +*/ int check_path (struct vectors * vecs,struct path * pp) {
@@ -1131,7 +1134,7 @@ check_path (struct vectors * vecs, struct path * pp)if (newstate ==PATH_REMOVED ) {condlog (2 ,"%s: remove path (checker)" , pp->dev);ev_remove_path (pp, vecs); -return ; +return 0 ; }if (newstate ==PATH_UP ) newstate =get_state (pp,1 );
@@ -1152,7 +1155,7 @@ check_path (struct vectors * vecs, struct path * pp) pp->tick =1 ; } } -return ; +return 0 ; }/* * Async IO in flight. Keep the previous path state
Signature · 1 line
1.7.12.4
PATCH 2/5 Make 'multipath -t' able to run as normal user
In reply to Hannes Reinecke'multipath -t' should be run as normal user, as we might be needing it to update the default configuration.
--- libmultipath/config.c | 1 - multipath/main.c | 22 +++++++++++++--------- multipathd/main.c | 2 ++ 3 files changed, 15 insertions(+), 10 deletions(-)
libmultipath/config.c +0 -1
@@ -543,7 +543,6 @@ load_config (char * file, struct udev *udev) conf->verbosity =DEFAULT_VERBOSITY ; conf->udev = udev; -dm_drv_version (conf->version,TGT_MPATH ); conf->dev_type =DEV_NONE ; conf->minio =DEFAULT_MINIO ; conf->minio_rq =DEFAULT_MINIO_RQ ;
multipath/main.c +13 -9
@@ -428,16 +428,8 @@ main (int argc, char *argv[])extern int optind;int r =1 ; -if (getuid () !=0 ) { -fprintf (stderr,"need to be root\n" ); -exit (1 ); - } - udev =udev_new (); -if (dm_prereq ()) -exit (1 ); -if (load_config (DEFAULT_CONFIGFILE , udev))exit (1 );
@@ -502,7 +494,7 @@ main (int argc, char *argv[])break ;case 't' : r =dump_config (); - goto out; + goto out_free_config;case 'h' :usage (argv[0 ]);exit (0 );
@@ -525,6 +517,16 @@ main (int argc, char *argv[])exit (1 ); } } + +if (getuid () !=0 ) { +fprintf (stderr,"need to be root\n" ); +exit (1 ); + } + +if (dm_prereq ()) +exit (1 ); +dm_drv_version (conf->version,TGT_MPATH ); +if (optind < argc) { conf->dev =MALLOC (FILE_NAME_SIZE );
@@ -609,6 +611,8 @@ out:cleanup_prio ();cleanup_checkers (); + +out_free_config:/* * Freeing config must be done after dm_lib_exit(), because * the logging function (dm_write_log()), which is called there,
multipathd/main.c +2 -0
@@ -1457,6 +1457,7 @@ reconfigure (struct vectors * vecs)tzset ();if (!load_config (DEFAULT_CONFIGFILE , udev)) { +dm_drv_version (conf->version,TGT_MPATH ); conf->verbosity = old->verbosity; conf->daemon =1 ;configure (vecs,1 );
@@ -1682,6 +1683,7 @@ child (void * param)if (load_config (DEFAULT_CONFIGFILE , udev)) goto failed; +dm_drv_version (conf->version,TGT_MPATH );if (init_checkers ()) {condlog (0 ,"failed to initialize checkers" ); goto failed;
Signature · 1 line
1.7.12.4
PATCH 3/5 libmultipath: remove 'remove_trailing_chars'
In reply to Hannes ReineckeUnused; superseded by strchop().
--- libmultipath/util.c | 9 --------- libmultipath/util.h | 1 - 2 files changed, 10 deletions(-)
libmultipath/util.c +0 -9
@@ -142,15 +142,6 @@ size_t strlcat(char *dst, const char *src, size_t size)return bytes; } -void remove_trailing_chars (char *path,char c) -{ -size_t len; - - len =strlen (path); -while (len >0 && path[len-1 ] == c) - path[--len] ='\0' ; -} -extern int devt2devname (char *devname,int devname_len,char *devt) {
libmultipath/util.h +0 -1
@@ -7,7 +7,6 @@ int filepresent (char * run);int get_word (char * sentence,char ** word);size_t strlcpy (char *dst,const char *src,size_t size);size_t strlcat (char *dst,const char *src,size_t size); -void remove_trailing_chars (char *path,char c);int devt2devname (char *,int ,char *);dev_t parse_devt (const char *dev_t);char *convert_dev (char *dev,int is_path_device);
Signature · 1 line
1.7.12.4
PATCH 4/5 libmultipath: simplify basenamecpy()
In reply to Hannes Reineckestrlcpy() already does a strlen() at the end, so no need to call it explicitly.
--- libmultipath/util.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
libmultipath/util.c +1 -2
@@ -44,8 +44,7 @@ basenamecpy (const char * str1, char * str2, int str2len)strncpy (str2, p, str2len); str2[str2len -1 ] ='\0' ; -strchop (str2); -return strlen (str2); +return strchop (str2); }int
Signature · 1 line
1.7.12.4
PATCH 5/5 libmultipath: Fix overflow in sysfs_get_str()
In reply to Hannes Reineckesysfs_get_str() should first do a strchop() before comparing the returned string length with the provided buffer. Otherwise we might incur a false positive as the overflowing bits might be occupied by spaces, which will be removed later on.
--- libmultipath/discovery.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
libmultipath/discovery.c +2 -3
@@ -157,13 +157,12 @@ sysfs_get_##fname (struct udev_device * udev, char * buff, size_t len) \ devname, #fname); \ return -ENXIO; \ } \ - if (strlen(attr) > len) { \ + if (strchop(attr) > len) { \ condlog(3, "%s: overflow in attribute %s", \ devname, #fname); \ return -EINVAL; \ } \ - strlcpy(buff, attr, len); \ - return strchop(buff); \ + return strlcpy(buff, attr, len); \ }declare_sysfs_get_str (devtype);
Signature · 1 line
1.7.12.4