Similar to sysroot_path, but first resolves (using realpath) the given path within sysroot. --- daemon/daemon.h | 1 + daemon/guestfsd.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/daemon/daemon.h b/daemon/daemon.h index 6535658..94537b7 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -51,6 +51,7 @@ extern const char *sysroot; extern size_t sysroot_len; extern char *sysroot_path (const char *path); +extern char *sysroot_realpath (const char *path); extern int is_root_device (const char *device); diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index 6519ea6..622bda1 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -455,6 +455,27 @@ sysroot_path (const char *path) return r; } +/* Resolve path within sysroot, calling sysroot_path on the resolved path. + * + * Caller must check for NULL and call reply_with_perror ("malloc/realpath") + * if it is. Caller must also free the string. + * + * See also the custom %R printf formatter which does shell quoting too. + */ +char * +sysroot_realpath (const char *path) +{ + CLEANUP_FREE char *rp = NULL; + + CHROOT_IN; + rp = realpath (path, NULL); + CHROOT_OUT; + if (rp == NULL) + return NULL; + + return sysroot_path (rp); +} + int xwrite (int sock, const void *v_buf, size_t len) { -- 1.9.0