[PATCH] vsh: Remove 'disconnected' set-only global variable

Peter Krempa via Devel posted 1 patch 1 month, 3 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1ed9be834e3bcf97bfcb8205749ef2742b12413a.1789663434.git.pkrempa@redhat.com
tools/vsh.c | 16 ----------------
1 file changed, 16 deletions(-)
[PATCH] vsh: Remove 'disconnected' set-only global variable
Posted by Peter Krempa via Devel 1 month, 3 weeks ago
From: Peter Krempa <pkrempa@redhat.com>

The instance of the 'disconnected' global variable in vsh.c is
written-only, so can be removed. Caught by new clang:

 clang -Itools/libvirt_shell.a.p -Itools -I../tools -Iinclude -I../include -Isrc -I../src -Isrc/util -I../src/util -I. -I.. -I/usr/include/libxml2 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-6 -I/usr/include/gio-unix-2.0 -I/usr/include/libmount -I/usr/include/blkid -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=gnu99 -O2 -g @/builds/libvirt/libvirt/build/c-warnings.txt -fPIC -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -D_FUNCTION_DEF -pthread -DWITH_GZFILEOP -MD -MQ tools/libvirt_shell.a.p/vsh.c.o -MF tools/libvirt_shell.a.p/vsh.c.o.d -o tools/libvirt_shell.a.p/vsh.c.o -c ../tools/vsh.c
../tools/vsh.c:242:12: error: variable 'disconnected' set but not used [-Werror,-Wunused-but-set-global]
   242 | static int disconnected; /* we may have been disconnected */
       |            ^
 1 error generated.

This instance exists since the 'vsh' module was split (834c5720e44).
'virsh' contains it's own instance.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 tools/vsh.c | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index 667cc1a0d2..d1540810ee 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -236,12 +236,6 @@ vshReportError(vshControl *ctl)
     vshResetLibvirtError();
 }

-/*
- * Detection of disconnections and automatic reconnection support
- */
-static int disconnected; /* we may have been disconnected */
-
-
 /* vshCmddefSearch:
  * @cmdname: name of command to find
  *
@@ -1392,16 +1386,6 @@ vshCommandRun(vshControl *ctl,

         after = g_get_real_time();

-        /* try to automatically catch disconnections */
-        if (ret != EXIT_SUCCESS &&
-            ((last_error != NULL) &&
-             (((last_error->code == VIR_ERR_SYSTEM_ERROR) &&
-               (last_error->domain == VIR_FROM_REMOTE)) ||
-              (last_error->code == VIR_ERR_RPC) ||
-              (last_error->code == VIR_ERR_NO_CONNECT) ||
-              (last_error->code == VIR_ERR_INVALID_CONN))))
-            disconnected++;
-
         if (ret != EXIT_SUCCESS)
             vshReportError(ctl);

-- 
2.55.0
Re: [PATCH] vsh: Remove 'disconnected' set-only global variable
Posted by Ján Tomko via Devel 1 month, 3 weeks ago
On a Thursday in 2026, Peter Krempa via Devel wrote:
>From: Peter Krempa <pkrempa@redhat.com>
>
>The instance of the 'disconnected' global variable in vsh.c is
>written-only, so can be removed. Caught by new clang:
>
> clang -Itools/libvirt_shell.a.p -Itools -I../tools -Iinclude -I../include -Isrc -I../src -Isrc/util -I../src/util -I. -I.. -I/usr/include/libxml2 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/sysprof-6 -I/usr/include/gio-unix-2.0 -I/usr/include/libmount -I/usr/include/blkid -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=gnu99 -O2 -g @/builds/libvirt/libvirt/build/c-warnings.txt -fPIC -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=600 -D_FUNCTION_DEF -pthread -DWITH_GZFILEOP -MD -MQ tools/libvirt_shell.a.p/vsh.c.o -MF tools/libvirt_shell.a.p/vsh.c.o.d -o tools/libvirt_shell.a.p/vsh.c.o -c ../tools/vsh.c
>../tools/vsh.c:242:12: error: variable 'disconnected' set but not used [-Werror,-Wunused-but-set-global]
>   242 | static int disconnected; /* we may have been disconnected */
>       |            ^
> 1 error generated.
>
>This instance exists since the 'vsh' module was split (834c5720e44).
>'virsh' contains it's own instance.
>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> tools/vsh.c | 16 ----------------
> 1 file changed, 16 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano