adeaf8
From fe544fd4c18d6982e652a1d5cd016816c609b72c Mon Sep 17 00:00:00 2001
adeaf8
From: "Daniel P. Berrange" <berrange@redhat.com>
adeaf8
Date: Wed, 28 Aug 2013 15:22:05 +0100
adeaf8
Subject: [PATCH] Ensure system identity includes process start time
adeaf8
adeaf8
The polkit access driver will want to use the process start
adeaf8
time field. This was already set for network identities, but
adeaf8
not for the system identity.
adeaf8
adeaf8
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
adeaf8
(cherry picked from commit e65667c0c6e016d42abea077e31628ae43f57b74)
adeaf8
---
adeaf8
 src/util/viridentity.c | 16 ++++++++++++++++
adeaf8
 1 file changed, 16 insertions(+)
adeaf8
adeaf8
diff --git a/src/util/viridentity.c b/src/util/viridentity.c
adeaf8
index 03c375b..f681f85 100644
adeaf8
--- a/src/util/viridentity.c
adeaf8
+++ b/src/util/viridentity.c
adeaf8
@@ -35,6 +35,7 @@
adeaf8
 #include "virthread.h"
adeaf8
 #include "virutil.h"
adeaf8
 #include "virstring.h"
adeaf8
+#include "virprocess.h"
adeaf8
 
adeaf8
 #define VIR_FROM_THIS VIR_FROM_IDENTITY
adeaf8
 
adeaf8
@@ -142,11 +143,20 @@ virIdentityPtr virIdentityGetSystem(void)
adeaf8
     security_context_t con;
adeaf8
 #endif
adeaf8
     char *processid = NULL;
adeaf8
+    unsigned long long timestamp;
adeaf8
+    char *processtime = NULL;
adeaf8
 
adeaf8
     if (virAsprintf(&processid, "%llu",
adeaf8
                     (unsigned long long)getpid()) < 0)
adeaf8
         goto cleanup;
adeaf8
 
adeaf8
+    if (virProcessGetStartTime(getpid(), &timestamp) < 0)
adeaf8
+        goto cleanup;
adeaf8
+
adeaf8
+    if (timestamp != 0 &&
adeaf8
+        virAsprintf(&processtime, "%llu", timestamp) < 0)
adeaf8
+        goto cleanup;
adeaf8
+
adeaf8
     if (!(username = virGetUserName(getuid())))
adeaf8
         goto cleanup;
adeaf8
     if (virAsprintf(&userid, "%d", (int)getuid()) < 0)
adeaf8
@@ -198,6 +208,11 @@ virIdentityPtr virIdentityGetSystem(void)
adeaf8
                            VIR_IDENTITY_ATTR_UNIX_PROCESS_ID,
adeaf8
                            processid) < 0)
adeaf8
         goto error;
adeaf8
+    if (processtime &&
adeaf8
+        virIdentitySetAttr(ret,
adeaf8
+                           VIR_IDENTITY_ATTR_UNIX_PROCESS_TIME,
adeaf8
+                           processtime) < 0)
adeaf8
+        goto error;
adeaf8
 
adeaf8
 cleanup:
adeaf8
     VIR_FREE(username);
adeaf8
@@ -206,6 +221,7 @@ cleanup:
adeaf8
     VIR_FREE(groupid);
adeaf8
     VIR_FREE(seccontext);
adeaf8
     VIR_FREE(processid);
adeaf8
+    VIR_FREE(processtime);
adeaf8
     return ret;
adeaf8
 
adeaf8
 error: