[PATCH v2 01/10] security: add virSecurityUpdateTimestampIfexists

Peng Liang liangpeng10 at huawei.com
Mon Oct 11 12:00:39 UTC 2021


Signed-off-by: Peng Liang <liangpeng10 at huawei.com>
---
 src/security/security_util.c | 32 ++++++++++++++++++++++++++++++++
 src/security/security_util.h |  4 ++++
 2 files changed, 36 insertions(+)

diff --git a/src/security/security_util.c b/src/security/security_util.c
index 26a7861e2935..07960b577e1a 100644
--- a/src/security/security_util.c
+++ b/src/security/security_util.c
@@ -227,6 +227,38 @@ virSecurityAddTimestamp(const char *name,
 }
 
 
+/**
+ * virSecurityUpdateTimestampIfexists:
+ * @name: security driver name
+ * @path: file name
+ *
+ * Update timestamp of @path for given security driver (@name) if the timestamp
+ * of @path exists.
+ *
+ * Returns: 0 on success,
+ *          1 if timestamp of @path doesn't exist,
+ *          -1 otherwise.
+ */
+int
+virSecurityUpdateTimestampIfexists(const char *name,
+                                   const char *path)
+{
+    g_autofree char *timestamp_name = NULL;
+    g_autofree char *timestamp_value = NULL;
+    g_autofree char *old_value = NULL;
+
+    if (!(timestamp_value = virSecurityGetTimestamp()) ||
+        !(timestamp_name = virSecurityGetTimestampAttrName(name)))
+        return -1;
+
+    if (virFileGetXAttrQuiet(path, timestamp_name, &old_value) < 0)
+        return 1;
+
+
+    return virFileSetXAttr(path, timestamp_name, timestamp_value);
+}
+
+
 static int
 virSecurityRemoveTimestamp(const char *name,
                            const char *path)
diff --git a/src/security/security_util.h b/src/security/security_util.h
index 7af6f009e2ca..b66541fd92c5 100644
--- a/src/security/security_util.h
+++ b/src/security/security_util.h
@@ -33,5 +33,9 @@ virSecurityMoveRememberedLabel(const char *name,
                                const char *src,
                                const char *dst);
 
+int
+virSecurityUpdateTimestampIfexists(const char *name,
+                                   const char *path);
+
 bool
 virSecurityXATTRNamespaceDefined(void);
-- 
2.31.1





More information about the libvir-list mailing list