[PATCH 0/4] virsh/virt-admin: Don't use virErrorRestore

Client application shouldn't need to reset the error. Peter Krempa (4): virshReconnect: Preserve current URI if not explicitly set in ctl->connname virshCatchDisconnect: Don't probe connection URI vshAdmConnect: Preserve connection URI in ctl->connname if auto-detected vshAdmCatchDisconnect: Don't probe connection URI tools/virsh.c | 13 +++++-------- tools/virt-admin.c | 11 ++++------- 2 files changed, 9 insertions(+), 15 deletions(-) -- 2.43.0

Probe the current URI so that other places don't need to do that. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tools/virsh.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/virsh.c b/tools/virsh.c index 7b71131db3..18a8c32f53 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -225,6 +225,9 @@ virshReconnect(vshControl *ctl, const char *name, bool readonly, bool force) ctl->connname = g_strdup(name); } + if (!ctl->connname) + ctl->connname = virConnectGetURI(priv->conn); + priv->readonly = readonly; if (virConnectRegisterCloseCallback(priv->conn, virshCatchDisconnect, -- 2.43.0

virsh already stores the connection URI in 'ctl->connname', use that instead. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tools/virsh.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 18a8c32f53..95ff63baeb 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -67,18 +67,13 @@ static int disconnected; /* we may have been disconnected */ * handler, just save the fact it was raised. */ static void -virshCatchDisconnect(virConnectPtr conn, +virshCatchDisconnect(virConnectPtr conn G_GNUC_UNUSED, int reason, void *opaque) { if (reason != VIR_CONNECT_CLOSE_REASON_CLIENT) { vshControl *ctl = opaque; const char *str = "unknown reason"; - virErrorPtr error; - g_autofree char *uri = NULL; - - virErrorPreserveLast(&error); - uri = virConnectGetURI(conn); switch ((virConnectCloseReason) reason) { case VIR_CONNECT_CLOSE_REASON_ERROR: @@ -94,9 +89,8 @@ virshCatchDisconnect(virConnectPtr conn, case VIR_CONNECT_CLOSE_REASON_LAST: break; } - vshError(ctl, _(str), NULLSTR(uri)); + vshError(ctl, _(str), NULLSTR(ctl->connname)); - virErrorRestore(&error); disconnected++; vshEventDone(ctl); } -- 2.43.0

Probe the current URI so that other places don't need to do that. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tools/virt-admin.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/virt-admin.c b/tools/virt-admin.c index 1e22a3c8a9..02cf421cee 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -120,6 +120,9 @@ vshAdmConnect(vshControl *ctl, unsigned int flags) if (priv->wantReconnect) vshPrint(ctl, "%s\n", _("Reconnected to the admin server")); + + if (!ctl->connname) + ctl->connname = virAdmConnectGetURI(priv->conn); } return 0; -- 2.43.0

On 12/14/23 17:56, Peter Krempa wrote:
Client application shouldn't need to reset the error.
Peter Krempa (4): virshReconnect: Preserve current URI if not explicitly set in ctl->connname virshCatchDisconnect: Don't probe connection URI vshAdmConnect: Preserve connection URI in ctl->connname if auto-detected vshAdmCatchDisconnect: Don't probe connection URI
tools/virsh.c | 13 +++++-------- tools/virt-admin.c | 11 ++++------- 2 files changed, 9 insertions(+), 15 deletions(-)
Reviewed-by: Michal Privoznik <mprivozn@redhat.com> which also applies to 4/4 that was send just a minute ago (something probably ate the original 4/4?). Michal
participants (2)
-
Michal Prívozník
-
Peter Krempa