From: Darrick J. Wong <djwong@xxxxxxxxxx> Trim the trailing slashes in the mountpoint string when we're printing parent pointer paths. Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx> --- io/parent.c | 9 +++++++-- libfrog/pptrs.c | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/io/parent.c b/io/parent.c index 6c0d81c12..36522f262 100644 --- a/io/parent.c +++ b/io/parent.c @@ -97,6 +97,7 @@ path_print( struct pptr_args *args = arg; char buf[PATH_MAX]; size_t len = PATH_MAX; + int mntpt_len = strlen(mntpt); int ret; if (args->filter_ino || args->filter_name) { @@ -105,8 +106,12 @@ path_print( return 0; } - ret = snprintf(buf, len, "%s", mntpt); - if (ret != strlen(mntpt)) + /* Trim trailing slashes from the mountpoint */ + while (mntpt_len > 0 && mntpt[mntpt_len - 1] == '/') + mntpt_len--; + + ret = snprintf(buf, len, "%.*s", mntpt_len, mntpt); + if (ret != mntpt_len) return ENAMETOOLONG; ret = path_list_to_string(path, buf + ret, len - ret); diff --git a/libfrog/pptrs.c b/libfrog/pptrs.c index b61a4e005..488682738 100644 --- a/libfrog/pptrs.c +++ b/libfrog/pptrs.c @@ -267,10 +267,15 @@ handle_to_path_walk( void *arg) { struct path_walk_info *pwi = arg; + int mntpt_len = strlen(mntpt); int ret; - ret = snprintf(pwi->buf, pwi->len, "%s", mntpt); - if (ret != strlen(mntpt)) + /* Trim trailing slashes from the mountpoint */ + while (mntpt_len > 0 && mntpt[mntpt_len - 1] == '/') + mntpt_len--; + + ret = snprintf(pwi->buf, pwi->len, "%.*s", mntpt_len, mntpt); + if (ret != mntpt_len) return ENAMETOOLONG; ret = path_list_to_string(path, pwi->buf + ret, pwi->len - ret);