From: Laine Stump <[email protected]>

As libvirt is used more and more in unprivileged/session mode,
file/socket permission errors have become more common. This patch adds
the username and uid of the process to the line in the log banner (the
first thing sent to every log target after the process starts) that
previously just gave the hostname.

We can expand on this idea to include more generally useful info about
the environment we're running in. (We just need to remember that in
this context we can't call anything that could lead to recursively
calling the logging system (i.e. we can't call any code that reports
an error, or a VIR_WARN, etc))

Signed-off-by: Laine Stump <[email protected]>
---

V2: removed all the "unprivileged/session mode" stuff as suggested by
Daniel. Now we just add user and uid to the existing hostname line

 src/util/virlog.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/util/virlog.c b/src/util/virlog.c
index cab23f613f..ccdf66c396 100644
--- a/src/util/virlog.c
+++ b/src/util/virlog.c
@@ -526,16 +526,18 @@ virLogToOneTarget(virLogSource *source,
                   bool *needInit)
 {
     if (*needInit) {
+        uid_t uid = geteuid();
+        g_autofree char *username = virGetUserName(uid);
         g_autofree char *hoststr = NULL;
 
         /* put some useful info at the top of the log. Avoid calling
          * any function that might end up reporting an error or
          * otherwise logging something, to prevent recursion.
          */
-
         virLogOneInitMsg(timestamp, VIR_LOG_VERSION_STRING, outputFunc, data);
 
-        hoststr = g_strdup_printf("hostname: %s", g_get_host_name());
+        hoststr = g_strdup_printf("hostname: %s, user: %s, uid: %u",
+                                  g_get_host_name(), username, uid);
         virLogOneInitMsg(timestamp, hoststr, outputFunc, data);
 
         *needInit = false;
-- 
2.53.0

Reply via email to