summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2017-08-16 21:05:20 +0200
committerMarc-André Lureau <marcandre.lureau@redhat.com>2017-10-10 23:31:09 +0200
commit245792ddb71df93ef4f8b25834734c8dfa17af9e (patch)
treeac7011e32e95bea8209799469028fd47ce9c2287
parent4309251a8c67c0893489dea18b30cc48f859c9fd (diff)
downloadfocaccia-qemu-245792ddb71df93ef4f8b25834734c8dfa17af9e.tar.gz
focaccia-qemu-245792ddb71df93ef4f8b25834734c8dfa17af9e.zip
vhost-user-scsi: simplify unix path cleanup
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>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--contrib/vhost-user-scsi/vhost-user-scsi.c22
1 files 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 82624a0f17..a9a4066eeb 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);
@@ -762,7 +747,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);