[Libguestfs] [PATCH] tmpdirs: Make the ‘su broken’ error message actionable.

Richard W.M. Jones rjones at redhat.com
Wed Feb 7 16:29:12 UTC 2018


Revert "tmpdirs: Blame systemd because su is broken."

This reverts commit 9464304d7a6b9b01e9eee32620ef3831e2b10875.

Replace with an actionable error message.
---
 lib/tmpdirs.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/lib/tmpdirs.c b/lib/tmpdirs.c
index bda3ee694..804c58be0 100644
--- a/lib/tmpdirs.c
+++ b/lib/tmpdirs.c
@@ -180,18 +180,22 @@ guestfs_impl_get_sockdir (guestfs_h *g)
 }
 
 static int
-lazy_make_tmpdir (guestfs_h *g, char *(*getdir) (guestfs_h *g), char **dest)
+lazy_make_tmpdir (guestfs_h *g,
+                  char *(*getdir) (guestfs_h *g), int is_runtime_dir,
+                  char **dest)
 {
   if (!*dest) {
     CLEANUP_FREE char *tmpdir = getdir (g);
     char *tmppath = safe_asprintf (g, "%s/libguestfsXXXXXX", tmpdir);
     if (mkdtemp (tmppath) == NULL) {
-      int bad_systemd = errno == EACCES && STRPREFIX (tmpdir, "/run/user/");
+      int bad_systemd = is_runtime_dir && errno == EACCES &&
+        STRPREFIX (tmpdir, "/run/user/");
 
       if (!bad_systemd)
         perrorf (g, _("%s: cannot create temporary directory"), tmppath);
       else
-        error (g, _("%s: cannot create temporary directory.  You may be hitting systemd bug https://bugzilla.redhat.com/967509"), tmppath);
+        error (g, _("%s: cannot create temporary directory.  It may be that $XDG_RUNTIME_DIR is pointing to a directory which we cannot write to, for example if you used ‘su [user]’ to change to this user account (see https://bugzilla.redhat.com/967509).  You can correct this by adjusting XDG_RUNTIME_DIR and possibly creating /run/user/%d with the right ownership."),
+               tmppath, (int) geteuid ());
       free (tmppath);
       return -1;
     }
@@ -219,13 +223,13 @@ lazy_make_tmpdir (guestfs_h *g, char *(*getdir) (guestfs_h *g), char **dest)
 int
 guestfs_int_lazy_make_tmpdir (guestfs_h *g)
 {
-  return lazy_make_tmpdir (g, guestfs_get_tmpdir, &g->tmpdir);
+  return lazy_make_tmpdir (g, guestfs_get_tmpdir, 0, &g->tmpdir);
 }
 
 int
 guestfs_int_lazy_make_sockdir (guestfs_h *g)
 {
-  return lazy_make_tmpdir (g, guestfs_get_sockdir, &g->sockdir);
+  return lazy_make_tmpdir (g, guestfs_get_sockdir, 1, &g->sockdir);
 }
 
 /**
-- 
2.13.2




More information about the Libguestfs mailing list