<fs> xfs-info /badpath
<fs> xfs-info /badpath
Before patch: libguestfs: error: xfs_info: xfs_info: /sysroot/badpath is not a mounted XFS filesystem After patch: libguestfs: error: xfs_info: xfs_info: /badpath is not a mounted XFS filesystem Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/daemon.h | 2 ++ daemon/guestfsd.c | 18 ++++++++++++++++++ daemon/xfs.c | 7 +++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/daemon/daemon.h b/daemon/daemon.h index 39cc3f3..635ce86 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -114,6 +114,8 @@ extern void udev_settle (void); extern int random_name (char *template); +extern char *tidy_log_path (char *log); + /* This just stops gcc from giving a warning about our custom printf * formatters %Q and %R. See guestfs(3)/EXTENDING LIBGUESTFS for more * info about these. diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index 2b0acf9..8fc40bf 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -1256,3 +1256,21 @@ udev_settle (void) (void) command (NULL, NULL, "udevadm", "settle", NULL); (void) command (NULL, NULL, "udevsettle", NULL); } + +char * +tidy_log_path (char *log) +{ + char *p, *buf; + size_t len = strlen (log); + size_t off; + p = strstr (log, "/sysroot"); + if (p) { + off = p - log; + buf = malloc (len + 1); + strncpy (buf, log, off); + strcpy (buf + off, log + off + 8); + return buf; + } else { + return log; + } +} diff --git a/daemon/xfs.c b/daemon/xfs.c index 5d267e6..1299a47 100644 --- a/daemon/xfs.c +++ b/daemon/xfs.c @@ -325,7 +325,9 @@ do_xfs_info (const char *pathordevice) r = command (&out, &err, "xfs_info", buf, NULL); free (buf); if (r == -1) { - reply_with_error ("%s", err); + buf = tidy_log_path (err); + reply_with_error ("%s", buf); + free (buf); goto error; } @@ -336,7 +338,8 @@ do_xfs_info (const char *pathordevice) ret = parse_xfs_info (lines); error: - free (err); + if (err) + free (err); free (out); if (lines) free_strings (lines); -- 1.7.11.2.249.g31c7954