Richard W.M. Jones
2018-Feb-07 16:29 UTC
[Libguestfs] [PATCH] tmpdirs: Make the ‘su broken’ error message actionable.
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
Pino Toscano
2018-Feb-07 17:02 UTC
Re: [Libguestfs] [PATCH] tmpdirs: Make the ‘su broken’ error message actionable.
On Wednesday, 7 February 2018 17:29:12 CET Richard W.M. Jones wrote:> 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/");s/bad_systemd/bad_runtime_dir/ ACK with the above change. -- Pino Toscano
Maybe Matching Threads
- [PATCH] tmpdirs: Blame systemd because su is broken.
- [PATCH 1/2] tmpdirs: centralize permissions handling
- [PATCH 2/3] lib: extract lazy tmpdir creation helper
- [PATCH 2/4] src/tmpdirs.c: Add internal documentation.
- [PATCH 1/3] launch: add internal helper for socket paths creation