examples/vhost_blk: fix check of device path
authorJin Yu <jin.yu@intel.com>
Wed, 12 Feb 2020 12:54:46 +0000 (20:54 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 14 Feb 2020 11:42:13 +0000 (12:42 +0100)
Fix the time of check time of use warning in example code.
Ignore the errno of unlink failure. There are two situations.
The first one is that file doesn't exist the unlink fails and
it's ok to ignore. The second one is that unlink fails to remove
file but the next bind() would fail too.

Coverity issue: 350589, 158663
Fixes: c19beb3f38cd ("examples/vhost_blk: introduce vhost storage sample")
Cc: stable@dpdk.org
Signed-off-by: Jin Yu <jin.yu@intel.com>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
examples/vhost_blk/vhost_blk.c

index e1036bf..74c82a9 100644 (file)
@@ -994,11 +994,7 @@ vhost_blk_ctrlr_construct(const char *ctrlr_name)
        }
        snprintf(dev_pathname, sizeof(dev_pathname), "%s/%s", path, ctrlr_name);
 
-       if (access(dev_pathname, F_OK) != -1) {
-               if (unlink(dev_pathname) != 0)
-                       rte_exit(EXIT_FAILURE, "Cannot remove %s.\n",
-                                dev_pathname);
-       }
+       unlink(dev_pathname);
 
        if (rte_vhost_driver_register(dev_pathname, 0) != 0) {
                fprintf(stderr, "socket %s already exists\n", dev_pathname);
@@ -1041,8 +1037,7 @@ signal_handler(__rte_unused int signum)
 {
        struct vhost_blk_ctrlr *ctrlr;
 
-       if (access(dev_pathname, F_OK) == 0)
-               unlink(dev_pathname);
+       unlink(dev_pathname);
 
        if (g_should_stop != -1) {
                g_should_stop = 1;