Avoid the need for the drivers to explicitly check for a NULL path by making sure it is at least the empty string. Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx> --- src/bhyve/bhyve_driver.c | 2 +- src/esx/esx_driver.c | 2 +- src/libvirt.c | 8 +++++++- src/libxl/libxl_driver.c | 5 ++--- src/lxc/lxc_driver.c | 3 +-- src/openvz/openvz_driver.c | 3 +-- src/phyp/phyp_driver.c | 2 +- src/qemu/qemu_driver.c | 6 ------ src/test/test_driver.c | 5 ++--- src/vbox/vbox_common.c | 6 ------ src/vbox/vbox_driver.c | 6 ------ src/vmware/vmware_driver.c | 2 +- src/vz/vz_driver.c | 2 +- 13 files changed, 18 insertions(+), 34 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 7d6439d79d..8870756ac5 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -199,7 +199,7 @@ bhyveConnectOpen(virConnectPtr conn, { virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (STRNEQ_NULLABLE(conn->uri->path, "/system")) { + if (STRNEQ(conn->uri->path, "/system")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected bhyve URI path '%s', try bhyve:///system"), conn->uri->path); diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 335d9a970d..c682c800ca 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -852,7 +852,7 @@ esxConnectOpen(virConnectPtr conn, virConnectAuthPtr auth, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); if (STRCASENEQ(conn->uri->scheme, "vpx") && - conn->uri->path && STRNEQ(conn->uri->path, "/")) { + STRNEQ(conn->uri->path, "/")) { VIR_WARN("Ignoring unexpected path '%s' for non-vpx scheme '%s'", conn->uri->path, conn->uri->scheme); } diff --git a/src/libvirt.c b/src/libvirt.c index 600beaa4d5..0b6bd6666e 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -1007,6 +1007,12 @@ virConnectOpenInternal(const char *name, goto failed; } + /* Avoid need for drivers to worry about NULLs, as + * no one needs to distinguish "" vs NULL */ + if (ret->uri->path == NULL && + VIR_STRDUP(ret->uri->path, "") < 0) + goto failed; + VIR_DEBUG("Split \"%s\" to URI components:\n" " scheme %s\n" " server %s\n" @@ -1016,7 +1022,7 @@ virConnectOpenInternal(const char *name, uristr, NULLSTR(ret->uri->scheme), NULLSTR(ret->uri->server), NULLSTR(ret->uri->user), ret->uri->port, - NULLSTR(ret->uri->path)); + ret->uri->path); if (ret->uri->scheme == NULL) { virReportError(VIR_ERR_NO_CONNECT, diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 45d0c99902..8808da8db1 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -853,13 +853,12 @@ libxlConnectOpen(virConnectPtr conn, } /* /session isn't supported in libxenlight */ - if (conn->uri->path && - STRNEQ(conn->uri->path, "") && + if (STRNEQ(conn->uri->path, "") && STRNEQ(conn->uri->path, "/") && STRNEQ(conn->uri->path, "/system")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected Xen URI path '%s', try xen:///system"), - NULLSTR(conn->uri->path)); + conn->uri->path); return VIR_DRV_OPEN_ERROR; } diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 2079dd0704..f6041aab43 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -170,8 +170,7 @@ static virDrvOpenStatus lxcConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); /* If path isn't '/' then they typoed, tell them correct path */ - if (conn->uri->path != NULL && - STRNEQ(conn->uri->path, "/") && + if (STRNEQ(conn->uri->path, "/") && STRNEQ(conn->uri->path, "/system")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected LXC URI path '%s', try lxc:///system"), diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 33893ac009..5a1446ddda 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1444,8 +1444,7 @@ static virDrvOpenStatus openvzConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); /* If path isn't /system, then they typoed, so tell them correct path */ - if (conn->uri->path == NULL || - STRNEQ(conn->uri->path, "/system")) { + if (STRNEQ(conn->uri->path, "/system")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected OpenVZ URI path '%s', try openvz:///system"), conn->uri->path); diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 55d459df5c..ed3d9feb58 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -1155,7 +1155,7 @@ phypConnectOpen(virConnectPtr conn, if (VIR_ALLOC(uuid_table) < 0) goto failure; - if (conn->uri->path) { + if (conn->uri->path[0] != '\0') { /* need to shift one byte in order to remove the first "/" of URI component */ if (VIR_STRDUP(managed_system, conn->uri->path + (conn->uri->path[0] == '/')) < 0) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index e677bf13b5..97d72f6fe8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1150,12 +1150,6 @@ static virDrvOpenStatus qemuConnectOpen(virConnectPtr conn, } cfg = virQEMUDriverGetConfig(qemu_driver); - if (conn->uri->path == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("no QEMU URI path given, try %s"), - cfg->uri); - goto cleanup; - } if (virQEMUDriverIsPrivileged(qemu_driver)) { if (STRNEQ(conn->uri->path, "/system") && diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 56d496a849..eec7a82924 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1454,9 +1454,8 @@ testConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (!conn->uri->path - || conn->uri->path[0] == '\0' - || (conn->uri->path[0] == '/' && conn->uri->path[1] == '\0')) { + if (conn->uri->path[0] == '\0' || + (conn->uri->path[0] == '/' && conn->uri->path[1] == '\0')) { virReportError(VIR_ERR_INVALID_ARG, "%s", _("testOpen: supply a path or use test:///default")); return VIR_DRV_OPEN_ERROR; diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 05cf9ad0de..ee94931918 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -517,12 +517,6 @@ vboxConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->uri->path == NULL || STREQ(conn->uri->path, "")) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("no VirtualBox driver path specified (try vbox:///session)")); - return VIR_DRV_OPEN_ERROR; - } - if (uid != 0) { if (STRNEQ(conn->uri->path, "/session")) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/vbox/vbox_driver.c b/src/vbox/vbox_driver.c index 9e95ab01c5..1f31fa28df 100644 --- a/src/vbox/vbox_driver.c +++ b/src/vbox/vbox_driver.c @@ -58,12 +58,6 @@ static virDrvOpenStatus dummyConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); - if (conn->uri->path == NULL || STREQ(conn->uri->path, "")) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("no VirtualBox driver path specified (try vbox:///session)")); - return VIR_DRV_OPEN_ERROR; - } - if (uid != 0) { if (STRNEQ(conn->uri->path, "/session")) { virReportError(VIR_ERR_INTERNAL_ERROR, diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index de3708aab3..c8a3151faf 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -131,7 +131,7 @@ vmwareConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); /* If path isn't /session, then they typoed, so tell them correct path */ - if (conn->uri->path == NULL || STRNEQ(conn->uri->path, "/session")) { + if (STRNEQ(conn->uri->path, "/session")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected VMware URI path '%s', try vmwareplayer:///session, vmwarews:///session or vmwarefusion:///session"), NULLSTR(conn->uri->path)); diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 5867f1c911..e51d968f28 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -359,7 +359,7 @@ vzConnectOpen(virConnectPtr conn, virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR); /* From this point on, the connection is for us. */ - if (STRNEQ_NULLABLE(conn->uri->path, "/system")) { + if (STRNEQ(conn->uri->path, "/system")) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected Virtuozzo URI path '%s', try vz:///system"), conn->uri->path); -- 2.14.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list