[libvirt] [PATCH 02/10] util: seclabel: Add deep copy function for device labels

Peter Krempa pkrempa at redhat.com
Thu Jun 19 13:46:36 UTC 2014


---
 src/util/virseclabel.c | 23 +++++++++++++++++++++++
 src/util/virseclabel.h |  6 +++++-
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/util/virseclabel.c b/src/util/virseclabel.c
index 5a4d78e..8f07de3 100644
--- a/src/util/virseclabel.c
+++ b/src/util/virseclabel.c
@@ -80,3 +80,26 @@ virSecurityDeviceLabelDefNew(const char *model)

     return seclabel;
 }
+
+
+virSecurityDeviceLabelDefPtr
+virSecurityDeviceLabelDefCopy(const virSecurityDeviceLabelDef *src)
+{
+    virSecurityDeviceLabelDefPtr ret;
+
+    if (VIR_ALLOC(ret) < 0)
+        return NULL;
+
+    ret->norelabel = src->norelabel;
+    ret->labelskip = src->labelskip;
+
+    if (VIR_STRDUP(ret->model, src->model) < 0 ||
+        VIR_STRDUP(ret->label, src->label) < 0)
+        goto error;
+
+    return ret;
+
+ error:
+    virSecurityDeviceLabelDefFree(ret);
+    return NULL;
+}
diff --git a/src/util/virseclabel.h b/src/util/virseclabel.h
index 9e970a5..b90d212 100644
--- a/src/util/virseclabel.h
+++ b/src/util/virseclabel.h
@@ -45,7 +45,7 @@ struct _virSecurityLabelDef {
 };


-/* Security configuration for domain */
+/* Security configuration for device */
 typedef struct _virSecurityDeviceLabelDef virSecurityDeviceLabelDef;
 typedef virSecurityDeviceLabelDef *virSecurityDeviceLabelDefPtr;
 struct _virSecurityDeviceLabelDef {
@@ -61,6 +61,10 @@ virSecurityLabelDefNew(const char *model);
 virSecurityDeviceLabelDefPtr
 virSecurityDeviceLabelDefNew(const char *model);

+virSecurityDeviceLabelDefPtr
+virSecurityDeviceLabelDefCopy(const virSecurityDeviceLabelDef *src)
+    ATTRIBUTE_NONNULL(1);
+
 void virSecurityLabelDefFree(virSecurityLabelDefPtr def);
 void virSecurityDeviceLabelDefFree(virSecurityDeviceLabelDefPtr def);

-- 
1.9.3




More information about the libvir-list mailing list