Unused multipath device map flushing in ipr_format_unit() is now done
with a fork()/exec() combination.

Since commit 0b693bd29cbe (iprutils: Unbind device before JBOD -> AF
formatting), multipath and /dev/sd device removal is done by the
binding and unbinding operations prior to formatting. We can now remove
the less secure system() calls that were in ipr_format_unit().

Signed-off-by: Heitor Ricardo Alves de Siqueira <hal...@linux.vnet.ibm.com>
---
 iprlib.c | 23 +++++++++--------------
 iprlib.h |  1 +
 2 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/iprlib.c b/iprlib.c
index c5dfd8bb50c0..85e14d918bc6 100644
--- a/iprlib.c
+++ b/iprlib.c
@@ -3738,23 +3738,18 @@ int ipr_format_unit(struct ipr_dev *dev)
        u8 *defect_list_hdr;
        int length = IPR_DEFECT_LIST_HDR_LEN;
        char *name = dev->gen_name;
-       char cmnd[1000];
-       struct ipr_dev *multipath_dev;
 
        if (strlen(dev->dev_name) && dev->scsi_dev_data->device_id) {
-               sprintf(cmnd, "/sbin/multipathd -k\"del path %s\" > /dev/null 
2>&1", strrchr(dev->dev_name, '/') + 1);
-               system(cmnd);
-               sprintf(cmnd, "/bin/rm -rf %s %s%s", dev->dev_name, 
dev->dev_name, "[0-9]*");
-               system(cmnd);
-
-               multipath_dev = find_multipath_jbod(dev);
-               if (multipath_dev) {
-                       sprintf(cmnd, "/sbin/multipathd -k\"del path %s\" > 
/dev/null 2>&1", strrchr(multipath_dev->dev_name, '/') + 1);
-                       system(cmnd);
-                       sprintf(cmnd, "/bin/rm -rf %s %s%s", 
multipath_dev->dev_name, multipath_dev->dev_name , "[0-9]*");
-                       system(cmnd);
+               int pid, status;
+
+               /* flush unused multipath device maps */
+               pid = fork();
+               if (pid == 0) {
+                       execl("/sbin/multipath", "-F", NULL);
+                       _exit(errno);
+               } else {
+                       waitpid(pid, &status, 0);
                }
-               system("/sbin/multipath -F > /dev/null 2>&1");
        }
 
        if (strlen(name) == 0)
diff --git a/iprlib.h b/iprlib.h
index 16fe1e162650..a4fea452a3f9 100644
--- a/iprlib.h
+++ b/iprlib.h
@@ -38,6 +38,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/wait.h>
 #include <ctype.h>
 #include <syslog.h>
 #include <term.h>
-- 
2.4.3


------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
_______________________________________________
Iprdd-devel mailing list
Iprdd-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/iprdd-devel

Reply via email to