diff mbox

[11/27] vhost-user-scsi: simplify unix path cleanup

Message ID 20170823162004.27337-12-marcandre.lureau@redhat.com
State New
Headers show

Commit Message

Marc-André Lureau Aug. 23, 2017, 4:19 p.m. UTC
Always remove the unix path when leaving the program (instead of when
freeing scsi_dev). Note that unix_sock_new() also unlink() exisiting
path before creating the socket.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 contrib/vhost-user-scsi/vhost-user-scsi.c | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)

Comments

Paolo Bonzini Sept. 19, 2017, 1:45 p.m. UTC | #1
On 23/08/2017 18:19, Marc-André Lureau wrote:
> Always remove the unix path when leaving the program (instead of when
> freeing scsi_dev). Note that unix_sock_new() also unlink() exisiting
> path before creating the socket.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  contrib/vhost-user-scsi/vhost-user-scsi.c | 22 +++++-----------------
>  1 file changed, 5 insertions(+), 17 deletions(-)
> 
> diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
> index bb10848cd2..624efc24ca 100644
> --- a/contrib/vhost-user-scsi/vhost-user-scsi.c
> +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
> @@ -636,24 +636,9 @@ fail:
>  
>  static void vdev_scsi_free(vhost_scsi_dev_t *vdev_scsi)
>  {
> -    if (!vdev_scsi) {
> -        return;
> -    }
> -
>      if (vdev_scsi->server_sock >= 0) {
> -        struct sockaddr_storage ss;
> -        socklen_t sslen = sizeof(ss);
> -
> -        if (getsockname(vdev_scsi->server_sock, (struct sockaddr *)&ss,
> -                        &sslen) == 0) {
> -            struct sockaddr_un *su = (struct sockaddr_un *)&ss;
> -            (void)unlink(su->sun_path);
> -        }
> -
> -        (void)close(vdev_scsi->server_sock);
> -        vdev_scsi->server_sock = -1;
> +        close(vdev_scsi->server_sock);
>      }
> -
>      g_main_loop_unref(vdev_scsi->loop);
>      g_tree_destroy(vdev_scsi->fdmap);
>      g_free(vdev_scsi);
> @@ -764,7 +749,10 @@ int main(int argc, char **argv)
>      }
>  
>  out:
> -    vdev_scsi_free(vdev_scsi);
> +    if (vdev_scsi) {
> +        vdev_scsi_free(vdev_scsi);
> +        unlink(unix_fn);
> +    }
>      g_free(unix_fn);
>      g_free(iscsi_uri);
>  
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
diff mbox

Patch

diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c
index bb10848cd2..624efc24ca 100644
--- a/contrib/vhost-user-scsi/vhost-user-scsi.c
+++ b/contrib/vhost-user-scsi/vhost-user-scsi.c
@@ -636,24 +636,9 @@  fail:
 
 static void vdev_scsi_free(vhost_scsi_dev_t *vdev_scsi)
 {
-    if (!vdev_scsi) {
-        return;
-    }
-
     if (vdev_scsi->server_sock >= 0) {
-        struct sockaddr_storage ss;
-        socklen_t sslen = sizeof(ss);
-
-        if (getsockname(vdev_scsi->server_sock, (struct sockaddr *)&ss,
-                        &sslen) == 0) {
-            struct sockaddr_un *su = (struct sockaddr_un *)&ss;
-            (void)unlink(su->sun_path);
-        }
-
-        (void)close(vdev_scsi->server_sock);
-        vdev_scsi->server_sock = -1;
+        close(vdev_scsi->server_sock);
     }
-
     g_main_loop_unref(vdev_scsi->loop);
     g_tree_destroy(vdev_scsi->fdmap);
     g_free(vdev_scsi);
@@ -764,7 +749,10 @@  int main(int argc, char **argv)
     }
 
 out:
-    vdev_scsi_free(vdev_scsi);
+    if (vdev_scsi) {
+        vdev_scsi_free(vdev_scsi);
+        unlink(unix_fn);
+    }
     g_free(unix_fn);
     g_free(iscsi_uri);