[libvirt PATCH 0/3] acouple of net-metadata fixes

Ján Tomko (3): remote: add VIR_ERR_NO_NETWORK_METADATA to daemonErrorLogFilter virsh: remove trailing whitespace even when editing the description vsh: introduce vshEditString src/remote/remote_daemon.c | 1 + tools/virsh-domain.c | 21 +-------------------- tools/virsh-network.c | 20 +------------------- tools/vsh.c | 27 +++++++++++++++++++++++++++ tools/vsh.h | 1 + 5 files changed, 31 insertions(+), 39 deletions(-) -- 2.43.2

https://issues.redhat.com/browse/RHEL-27172 Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/remote/remote_daemon.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c index 657c053f6f..9e82132654 100644 --- a/src/remote/remote_daemon.c +++ b/src/remote/remote_daemon.c @@ -107,6 +107,7 @@ static int daemonErrorLogFilter(virErrorPtr err, int priority) case VIR_ERR_NO_SERVER: case VIR_ERR_NO_CLIENT: case VIR_ERR_NO_HOSTNAME: + case VIR_ERR_NO_NETWORK_METADATA: return VIR_LOG_DEBUG; } -- 2.43.2

On 2/28/24 16:51, Ján Tomko wrote:
Please prefix this ^^^ line with 'Resolves: ' or something similar.
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/remote/remote_daemon.c | 1 + 1 file changed, 1 insertion(+)
Michal

When editing the title of a domain or network via the `desc` or `net-desc` commands, we strip the final newline that is added by some editors. Do the same when editing the description as well. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tools/virsh-domain.c | 5 ++--- tools/virsh-network.c | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e69d14a6aa..7a87da1cbb 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -8525,10 +8525,9 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) return false; /* strip a possible newline at the end of file; some - * editors enforce a newline, this makes editing the title + * editors enforce a newline, this makes editing * more convenient */ - if (title && - (tmpstr = strrchr(desc_edited, '\n')) && + if ((tmpstr = strrchr(desc_edited, '\n')) && *(tmpstr+1) == '\0') *tmpstr = '\0'; diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 68c7543863..c676fc603c 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -481,8 +481,7 @@ cmdNetworkDesc(vshControl *ctl, const vshCmd *cmd) /* strip a possible newline at the end of file; some * editors enforce a newline, this makes editing the title * more convenient */ - if (title && - (tmpstr = strrchr(desc_edited, '\n')) && + if ((tmpstr = strrchr(desc_edited, '\n')) && *(tmpstr+1) == '\0') *tmpstr = '\0'; -- 2.43.2

Remove some code repetition between desc and net-desc commands. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tools/virsh-domain.c | 20 +------------------- tools/virsh-network.c | 19 +------------------ tools/vsh.c | 27 +++++++++++++++++++++++++++ tools/vsh.h | 1 + 4 files changed, 30 insertions(+), 37 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 7a87da1cbb..6482daebaf 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -8508,29 +8508,11 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) descArg = g_strdup(descDom); if (edit) { - g_autoptr(vshTempFile) tmp = NULL; g_autofree char *desc_edited = NULL; - char *tmpstr; - /* Create and open the temporary file. */ - if (!(tmp = vshEditWriteToTempFile(ctl, descArg))) + if (vshEditString(ctl, &desc_edited, descArg) < 0) return false; - /* Start the editor. */ - if (vshEditFile(ctl, tmp) == -1) - return false; - - /* Read back the edited file. */ - if (!(desc_edited = vshEditReadBackFile(ctl, tmp))) - return false; - - /* strip a possible newline at the end of file; some - * editors enforce a newline, this makes editing - * more convenient */ - if ((tmpstr = strrchr(desc_edited, '\n')) && - *(tmpstr+1) == '\0') - *tmpstr = '\0'; - /* Compare original XML with edited. Has it changed at all? */ if (STREQ(descDom, desc_edited)) { if (title) diff --git a/tools/virsh-network.c b/tools/virsh-network.c index c676fc603c..399035f8cf 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -462,29 +462,12 @@ cmdNetworkDesc(vshControl *ctl, const vshCmd *cmd) descArg = g_strdup(descNet); if (edit) { - g_autoptr(vshTempFile) tmp = NULL; g_autofree char *desc_edited = NULL; - char *tmpstr; /* Create and open the temporary file. */ - if (!(tmp = vshEditWriteToTempFile(ctl, descArg))) + if (vshEditString(ctl, &desc_edited, descArg) < 0) return false; - /* Start the editor. */ - if (vshEditFile(ctl, tmp) == -1) - return false; - - /* Read back the edited file. */ - if (!(desc_edited = vshEditReadBackFile(ctl, tmp))) - return false; - - /* strip a possible newline at the end of file; some - * editors enforce a newline, this makes editing the title - * more convenient */ - if ((tmpstr = strrchr(desc_edited, '\n')) && - *(tmpstr+1) == '\0') - *tmpstr = '\0'; - /* Compare original XML with edited. Has it changed at all? */ if (STREQ(descNet, desc_edited)) { if (title) diff --git a/tools/vsh.c b/tools/vsh.c index 65deaa77e8..0543ba299f 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2506,6 +2506,33 @@ vshEditReadBackFile(vshControl *ctl, const char *filename) return ret; } +int +vshEditString(vshControl *ctl, char **output, const char *string) +{ + g_autoptr(vshTempFile) tmp = NULL; + char *tmpstr; + + /* Create and open the temporary file. */ + if (!(tmp = vshEditWriteToTempFile(ctl, string))) + return -1; + + /* Start the editor. */ + if (vshEditFile(ctl, tmp) == -1) + return -1; + + /* Read back the edited file. */ + if (!(*output = vshEditReadBackFile(ctl, tmp))) + return -1; + + /* strip a possible newline at the end of file; some + * editors enforce a newline, this makes editing + * more convenient */ + if ((tmpstr = strrchr(*output, '\n')) && + *(tmpstr+1) == '\0') + *tmpstr = '\0'; + + return 0; +} /* Tree listing helpers. */ diff --git a/tools/vsh.h b/tools/vsh.h index 2a1be29b1c..6f8e3895b7 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -350,6 +350,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(vshTempFile, vshEditUnlinkTempfile); char *vshEditWriteToTempFile(vshControl *ctl, const char *doc); int vshEditFile(vshControl *ctl, const char *filename); char *vshEditReadBackFile(vshControl *ctl, const char *filename); +int vshEditString(vshControl *ctl, char **output, const char *string); int vshAskReedit(vshControl *ctl, const char *msg, bool relax_avail); /* terminal modifications */ -- 2.43.2

On 2/28/24 16:51, Ján Tomko wrote:
Remove some code repetition between desc and net-desc commands.
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- tools/virsh-domain.c | 20 +------------------- tools/virsh-network.c | 19 +------------------ tools/vsh.c | 27 +++++++++++++++++++++++++++ tools/vsh.h | 1 + 4 files changed, 30 insertions(+), 37 deletions(-)
diff --git a/tools/vsh.c b/tools/vsh.c index 65deaa77e8..0543ba299f 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2506,6 +2506,33 @@ vshEditReadBackFile(vshControl *ctl, const char *filename) return ret; }
+int +vshEditString(vshControl *ctl, char **output, const char *string)
One argument per line please.
+{ + g_autoptr(vshTempFile) tmp = NULL; + char *tmpstr; + + /* Create and open the temporary file. */ + if (!(tmp = vshEditWriteToTempFile(ctl, string))) + return -1; + + /* Start the editor. */ + if (vshEditFile(ctl, tmp) == -1) + return -1; + + /* Read back the edited file. */ + if (!(*output = vshEditReadBackFile(ctl, tmp))) + return -1; + + /* strip a possible newline at the end of file; some + * editors enforce a newline, this makes editing + * more convenient */ + if ((tmpstr = strrchr(*output, '\n')) && + *(tmpstr+1) == '\0') + *tmpstr = '\0'; + + return 0; +}
/* Tree listing helpers. */
Michal

On 2/28/24 16:51, Ján Tomko wrote:
Ján Tomko (3): remote: add VIR_ERR_NO_NETWORK_METADATA to daemonErrorLogFilter virsh: remove trailing whitespace even when editing the description vsh: introduce vshEditString
src/remote/remote_daemon.c | 1 + tools/virsh-domain.c | 21 +-------------------- tools/virsh-network.c | 20 +------------------- tools/vsh.c | 27 +++++++++++++++++++++++++++ tools/vsh.h | 1 + 5 files changed, 31 insertions(+), 39 deletions(-)
Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Michal
participants (2)
-
Ján Tomko
-
Michal Prívozník