diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2017-08-16 20:30:31 +0200 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@redhat.com> | 2017-10-10 23:31:08 +0200 |
commit | 0644fe4ad07ea00f45cf0a641dfa44a4247315b5 (patch) | |
tree | e26a4566664d03e522da72a3a7860dbf47e2fc4e /contrib | |
parent | b085b050c6a6ad5160ffc371b97e2113b7de9f66 (diff) |
vhost-user-scsi: connect unix socket before allocating
This simplify a little bit memory management in the following patches.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/vhost-user-scsi/vhost-user-scsi.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/contrib/vhost-user-scsi/vhost-user-scsi.c b/contrib/vhost-user-scsi/vhost-user-scsi.c index 1fb57da2da..e01bf31296 100644 --- a/contrib/vhost-user-scsi/vhost-user-scsi.c +++ b/contrib/vhost-user-scsi/vhost-user-scsi.c @@ -715,23 +715,17 @@ static void vdev_scsi_deinit(vhost_scsi_dev_t *vdev_scsi) } } -static vhost_scsi_dev_t *vdev_scsi_new(char *unix_fn) +static vhost_scsi_dev_t *vdev_scsi_new(int server_sock) { vhost_scsi_dev_t *vdev_scsi = NULL; - assert(unix_fn); - vdev_scsi = calloc(1, sizeof(vhost_scsi_dev_t)); if (!vdev_scsi) { PERR("calloc: %s", strerror(errno)); return NULL; } - vdev_scsi->server_sock = unix_sock_new(unix_fn); - if (vdev_scsi->server_sock < 0) { - goto err; - } - + vdev_scsi->server_sock = server_sock; vdev_scsi->loop = g_main_loop_new(NULL, FALSE); if (!vdev_scsi->loop) { PERR("Error creating glib event loop"); @@ -815,7 +809,7 @@ int main(int argc, char **argv) vhost_scsi_dev_t *vdev_scsi = NULL; char *unix_fn = NULL; char *iscsi_uri = NULL; - int opt, err = EXIT_SUCCESS; + int sock, opt, err = EXIT_SUCCESS; while ((opt = getopt(argc, argv, "u:i:")) != -1) { switch (opt) { @@ -835,7 +829,11 @@ int main(int argc, char **argv) goto help; } - vdev_scsi = vdev_scsi_new(unix_fn); + sock = unix_sock_new(unix_fn); + if (sock < 0) { + goto err; + } + vdev_scsi = vdev_scsi_new(sock); if (!vdev_scsi) { goto err; } |