diff --git a/0001-virt-top-fix-to-explicitly-disconnect-from-libvirtd.patch b/0001-virt-top-fix-to-explicitly-disconnect-from-libvirtd.patch new file mode 100644 index 0000000000000000000000000000000000000000..fd607d3640d4b01c23ce477e11acbc2a371e55f7 --- /dev/null +++ b/0001-virt-top-fix-to-explicitly-disconnect-from-libvirtd.patch @@ -0,0 +1,39 @@ +From 4b15ee2440b0e70e3c1eb5e164ded493e2d8f0c8 Mon Sep 17 00:00:00 2001 +From: Yuya Higashi +Date: Tue, 15 Nov 2022 13:56:21 +0900 +Subject: [PATCH 1/3] virt-top: fix to explicitly disconnect from libvirtd + +To prevent libvirtd from printing virNetSocketReadWire I/O errors when +the virt-top command exits, explicitly disconnect from libvirtd. + +Signed-off-by: Yuya Higashi +--- + src/top.ml | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +diff --git a/src/top.ml b/src/top.ml +index 75fbcb9..cbe655a 100644 +--- a/src/top.ml ++++ b/src/top.ml +@@ -306,7 +306,7 @@ let get_string maxlen = + ) + + (* Main loop. *) +-let rec main_loop ((_, batch_mode, script_mode, csv_enabled, stream_mode, _, _, _) ++let rec main_loop ((conn, batch_mode, script_mode, csv_enabled, stream_mode, _, _, _) + as setup) = + let csv_flags = !csv_cpu, !csv_mem, !csv_block, !csv_net in + +@@ -372,7 +372,8 @@ let rec main_loop ((_, batch_mode, script_mode, csv_enabled, stream_mode, _, _, + if not !quit || !end_time <> None then + millisleep delay + ) +- done ++ done; ++ C.close conn + + and get_key_press setup delay = + (* Read the next key, waiting up to 'delay' milliseconds. *) +-- +2.42.0 + diff --git a/0002-virt-top-fix-to-parse-init-file-correctly.patch b/0002-virt-top-fix-to-parse-init-file-correctly.patch new file mode 100644 index 0000000000000000000000000000000000000000..8129f51e1f4c70529291517244b0440a14e1c461 --- /dev/null +++ b/0002-virt-top-fix-to-parse-init-file-correctly.patch @@ -0,0 +1,38 @@ +From 1d04fdfce6edea685596fbb18920799c70f1d7fa Mon Sep 17 00:00:00 2001 +From: Yuya Higashi +Date: Mon, 26 Dec 2022 09:18:15 +0900 +Subject: [PATCH 2/3] virt-top: fix to parse init-file correctly + +This fixes the following runtime error when parsing init-file. + +$ virt-top --init-file <(echo "sort id") +Error: Invalid_argument("String.sub / Bytes.sub") +Raised at Stdlib.invalid_arg in file "stdlib.ml", line 30, characters 20-45 +Called from Stdlib__String.sub in file "string.ml" (inlined), line 50, characters 2-23 +Called from Utils.split in file "utils.ml", line 82, characters 24-68 +Called from Utils.read_config_file.(fun) in file "utils.ml", line 114, characters 23-37 +Called from Stdlib__List.map in file "list.ml", line 92, characters 20-23 +Called from Top.start_up.try_to_read_init_file in file "top.ml", line 153, characters 17-42 +Called from Main.script_mode in file "main.ml", line 37, characters 6-17 + +Signed-off-by: Yuya Higashi +--- + src/utils.ml | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/utils.ml b/src/utils.ml +index 1f00803..8dfb255 100644 +--- a/src/utils.ml ++++ b/src/utils.ml +@@ -79,7 +79,7 @@ let trim ?(test = isspace) str = + let split str sep = + try + let i = String.index str sep in +- String.sub str 0 i, String.sub str (i+1) (String.length str - 1) ++ String.sub str 0 i, String.sub str (i+1) (String.length str - i - 1) + with + Not_found -> str, "" + +-- +2.42.0 + diff --git a/0003-src-Include-libxml-parser.h.patch b/0003-src-Include-libxml-parser.h.patch new file mode 100644 index 0000000000000000000000000000000000000000..a7d15376e761a74d1f3f7cc589b9bed77566c7fb --- /dev/null +++ b/0003-src-Include-libxml-parser.h.patch @@ -0,0 +1,33 @@ +From dd205eeae9fb06ac113884e4c9e9f3a90eef7554 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +Date: Mon, 27 Nov 2023 14:09:04 +0000 +Subject: [PATCH 3/3] src: Include +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +libxml2 2.12.1 failed with this error: + +xml-c.c:92:9: warning: implicit declaration of function ‘xmlReadMemory’; did you mean ‘xmlInitMemory’? [-Wimplicit-function-declaration] + 92 | doc = xmlReadMemory (String_val (xmlv), caml_string_length (xmlv), + | ^~~~~~~~~~~~~ + | xmlInitMemory +--- + src/xml-c.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/src/xml-c.c b/src/xml-c.c +index 72042bf..6c546b9 100644 +--- a/src/xml-c.c ++++ b/src/xml-c.c +@@ -28,6 +28,7 @@ + #include + #include + ++#include + #include + #include + +-- +2.42.0 + diff --git a/libguestfs.keyring b/libguestfs.keyring new file mode 100644 index 0000000000000000000000000000000000000000..bb3eb5537b7c398a10b7e2b26ca00af011d1a73e Binary files /dev/null and b/libguestfs.keyring differ diff --git a/processcsv.py b/processcsv.py new file mode 100755 index 0000000000000000000000000000000000000000..48122634d06aae144896cc7051c02cf065bf3287 --- /dev/null +++ b/processcsv.py @@ -0,0 +1,65 @@ +#!/usr/bin/python3 +# +# https://bugzilla.redhat.com/show_bug.cgi?id=665817 +# +# Usage: +# +# virt-top --csv data.csv +# processcsv.py < data.csv +# +# Note this OVERWRITES the following files in the current directory: +# +# global.csv # all the global data +# domain.csv # data for domain ID (multiple files) + +import sys +import csv + +rows = csv.reader (sys.stdin) + +# Get the header row. +header = next(rows) + +# Find the index of the 'Hostname' and 'Time' cols (usually first two). +hostname_i = header.index ("Hostname") +time_i = header.index ("Time") + +# Find the index of the 'Domain ID' column (i) and the number of +# columns per domain (w). +i = header.index ("Domain ID") +w = len (header) - i + +dom_header = header[i:i+w] +dom_header.insert (0, "Hostname") +dom_header.insert (1, "Time") + +gfile = open ("global.csv", "w") +gfile_writer = csv.writer (gfile) +gfile_writer.writerow (header[0:i]) + +dfiles = dict() + +# Process all the remaining data rows. +for data in rows: + # Global data is columns 0..i-1 + gfile_writer.writerow (data[0:i]) + + hostname = data[hostname_i] + time = data[time_i] + + # For each domain ... + for j in range(i,len(data),w): + dom = data[j:j+w] + domid = dom[0] + + if domid in dfiles: + dfile_writer = dfiles[domid] + else: + dfile = open ("domain%s.csv" % domid, "w") + dfile_writer = csv.writer (dfile) + dfile_writer.writerow (dom_header) + dfiles[domid] = dfile_writer + + dom.insert (0, hostname) + dom.insert (1, time) + dfile_writer.writerow (dom) diff --git a/processcsv.py.pod b/processcsv.py.pod new file mode 100644 index 0000000000000000000000000000000000000000..8c8893d82fc3baeec45127a66215d4e7b93e9774 --- /dev/null +++ b/processcsv.py.pod @@ -0,0 +1,64 @@ +=head1 NAME + +processcsv.py - process virt-top CSV files + +=head1 SUMMARY + + virt-top --csv data.csv + processcsv.py < data.csv + +=head1 DESCRIPTION + +virt-top is a L-like utility for showing stats of virtualized +domains. + +processcsv.py is a simple Python script that post-processes the output +of C. + +It is used like this: + + virt-top --csv data.csv + processcsv.py < data.csv + +The second command will B the following files in the +current directory: + +=over 4 + +=item C + +This contains the global (host) statistics columns from the CSV file. + +=item C.csv> (multiple files) + +For each libvirt domain ID I, a file is created containing +the per-domain statistics from the CSV file. + +=back + +=head1 SEE ALSO + +L + +=head1 AUTHORS + +Richard W.M. Jones + +=head1 COPYRIGHT + +(C) Copyright 2007-2012 Red Hat Inc., Richard W.M. Jones +http://libvirt.org/ + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. diff --git a/virt-top-1.1.1-ocaml-bytecode.patch b/virt-top-1.1.1-ocaml-bytecode.patch new file mode 100644 index 0000000000000000000000000000000000000000..d15627253d444a44fb1eb0cbe2c63f1687e4afde --- /dev/null +++ b/virt-top-1.1.1-ocaml-bytecode.patch @@ -0,0 +1,28 @@ +--- virt-top-1.1.1/configure.orig 2021-11-03 14:18:26.000000000 -0600 ++++ virt-top-1.1.1/configure 2023-07-10 12:31:15.525435684 -0600 +@@ -5357,7 +5357,7 @@ else + OCAMLOPT="$ac_cv_prog_OCAMLOPT" + fi + +- OCAMLBEST=byte ++ OCAMLBEST=ocamlc + if test "$OCAMLOPT" = "no"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING: Cannot find ocamlopt; bytecode compilation only." >&5 + $as_echo "$as_me: WARNING: Cannot find ocamlopt; bytecode compilation only." >&2;} +--- virt-top-1.1.1/ocaml-link.sh.in.orig 2021-11-03 06:00:07.000000000 -0600 ++++ virt-top-1.1.1/ocaml-link.sh.in 2023-07-10 12:31:41.012064849 -0600 +@@ -49,10 +49,12 @@ if [ x"${V:-@AM_DEFAULT_VERBOSITY@}" = x + echo "$@" \ + @OCAML_RUNTIME_VARIANT_PIC_OPTION@ \ + -linkpkg \ +- -cclib "'@LDFLAGS@ $cclib'" ++ -cclib "'@LDFLAGS@ $cclib'" \ ++ -output-complete-exe + fi + # NB -cclib must come last. + exec "$@" \ + @OCAML_RUNTIME_VARIANT_PIC_OPTION@ \ + -linkpkg \ +- -cclib "@LDFLAGS@ $cclib" ++ -cclib "@LDFLAGS@ $cclib" \ ++ -output-complete-exe diff --git a/virt-top-1.1.1.tar.gz.sig b/virt-top-1.1.1.tar.gz.sig new file mode 100644 index 0000000000000000000000000000000000000000..288fd066493ae6a252db00751b87ae4b29f0afd4 --- /dev/null +++ b/virt-top-1.1.1.tar.gz.sig @@ -0,0 +1,17 @@ +-----BEGIN PGP SIGNATURE----- + +iQJFBAABCAAvFiEE93dPsa0HSn6Mh2fqkXOPc+G3aKAFAmGC7/kRHHJpY2hAYW5u +ZXhpYS5vcmcACgkQkXOPc+G3aKBOvw/8CNFQqN8GqzWqlKjFd9ditzvu3tcmab9F +ru/qZOKn2RVE7T3vlPYKBIPMKHn9afx31Fvq9ftzPKVejhU7715Jm3uZ/lMgZvJg +PERbKT/ypx5NZYaHx2+uXGzVO600zSnqfnWM3xBguxDxRPqZxYXRSMXiwKHdZNzo +EriDt+By+zBo4PqBhdOFkr9Ppn4PI88170vx3O3PYJt7VGKywvuUoPsflCz4ODIf +8Uo8Wf2wIA6lAZGfnf345ZI99mgycm3eoXYHVxltBiUQxV0J3L0LTWGYP1jkOiYn +8UXfOn02pytgGqI91LAAS0XrcyCjtgmdgUkShwLiWT3CZkkX6wIw1YvPhDNBW46x +k3VRMhO6fckRnmOurbL9TpCObo/9mG7Ol8lVspRKhYgnYV+3V1eaMgXdcL2DpN4O +ueJMjQznmEoejOmyec++bVOmNvae4GgQZT2YsBXfYc3ZT7EMUQXrkcCr5A5BOEyZ +xXuWKFcbDD0XVjxHFZQjYo66eLG8swjPBZb+dUZjAiz0jXrzi2BOF2YJWbLQya+8 +zM9ZS1VSaYUX9qmR828bpHn7OqU8fZefL0NsCP8EFcIGQT175PzJ8BO6uYWfmpmp +6nLupdf3YGCHEnCMcPxZ0O4DB1bGZiPU9rvclTbP2uk9YdvBeXkPMDXroV1HDDaB +kkvgVVpdHUI= +=rDgd +-----END PGP SIGNATURE----- diff --git a/virt-top.spec b/virt-top.spec index baeac9ee3d0dd9d0b0ba8d9edd71295fdff254db..74eef98b4120698bb53acc1685eb5807be9a60f9 100644 --- a/virt-top.spec +++ b/virt-top.spec @@ -1,13 +1,21 @@ -%define anolis_release 1 +%define anolis_release 2 %undefine _package_note_flags Name: virt-top -Version: 1.1.1 +Version: 1.1.1 Release: %{anolis_release}%{?dist} Summary: Utility like top(1) for displaying virtualization stats License: GPLv2+ URL: https://people.redhat.com/rjones/virt-top -Source0: https://people.redhat.com/rjones/virt-top/files/%{name}-%{version}.tar.gz +Source0: http://people.redhat.com/~rjones/virt-top/files/virt-top-1.1.1.tar.gz +Source1: http://people.redhat.com/~rjones/virt-top/files/virt-top-1.1.1.tar.gz.sig +Source2: processcsv.py +Source3: processcsv.py.pod +Source4: libguestfs.keyring +Patch1: virt-top-1.1.1-ocaml-bytecode.patch +Patch2: 0002-virt-top-fix-to-parse-init-file-correctly.patch +Patch3: 0003-src-Include-libxml-parser.h.patch +Patch4: 0001-virt-top-fix-to-explicitly-disconnect-from-libvirtd.patch BuildRequires: gcc BuildRequires: make @@ -78,5 +86,9 @@ install -m 0644 src/virt-top.1 $RPM_BUILD_ROOT%{_mandir}/man1 %doc README TODO %changelog +* Mon Sep 29 2025 wenyuzifang - 1.1.1-2 +- Fix string parsing to prevent runtime crashes when loading init-files. +- Fix compilation warning by including required header for xmlReadMemory function. +- Prevent spurious I/O errors in libvirtd logs by cleanly disconnecting on exit. * Thu Mar 16 2023 Yuanhong Peng - 1.1.1-1 - Init from upstream