From 8af76c3764a631d17b9a38a44d477c3244e0aefd Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Sun, 23 Jan 2022 14:58:36 +0100 Subject: [PATCH] virDomainChrSourceDefCopy: Copy more struct members MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The aim of virDomainChrSourceDefCopy() is to make a deep copy of given virDomainChrSourceDef. However, some types were not copied at all (VIR_DOMAIN_CHR_TYPE_SPICEVMC and VIR_DOMAIN_CHR_TYPE_SPICEPORT) and some members weren't copied either (@logfile, @logappend). After this, there are still some members that are not copied (seclabels and private data), but the sole caller qemuProcessFindCharDevicePTYsMonitor() doesn't seem to care. Therefore, just document this behavior so that future user is aware. Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- src/conf/domain_conf.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 87576d4804..5d3604c085 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2732,8 +2732,9 @@ virDomainChrSourceDefClear(virDomainChrSourceDef *def) VIR_FREE(def->logfile); } -/* Deep copies the contents of src into dest. Return -1 and report - * error on failure. */ +/* Almost deep copies the contents of src into dest. Some parts are not copied + * though. + * Returns -1 and report error on failure. */ int virDomainChrSourceDefCopy(virDomainChrSourceDef *dest, virDomainChrSourceDef *src) @@ -2743,7 +2744,11 @@ virDomainChrSourceDefCopy(virDomainChrSourceDef *dest, virDomainChrSourceDefClear(dest); - switch (src->type) { + dest->type = src->type; + dest->logfile = g_strdup(src->logfile); + dest->logappend = src->logappend; + + switch ((virDomainChrType)src->type) { case VIR_DOMAIN_CHR_TYPE_FILE: case VIR_DOMAIN_CHR_TYPE_PTY: case VIR_DOMAIN_CHR_TYPE_DEV: @@ -2783,9 +2788,21 @@ virDomainChrSourceDefCopy(virDomainChrSourceDef *dest, dest->data.nmdm.slave = g_strdup(src->data.nmdm.slave); break; - } - dest->type = src->type; + case VIR_DOMAIN_CHR_TYPE_SPICEVMC: + dest->data.spicevmc = src->data.spicevmc; + break; + + case VIR_DOMAIN_CHR_TYPE_SPICEPORT: + dest->data.spiceport.channel = g_strdup(src->data.spiceport.channel); + break; + + case VIR_DOMAIN_CHR_TYPE_NULL: + case VIR_DOMAIN_CHR_TYPE_VC: + case VIR_DOMAIN_CHR_TYPE_STDIO: + case VIR_DOMAIN_CHR_TYPE_LAST: + break; + } return 0; }