From 9519f1038b918231c6368b3beb2b6c5316458871 Mon Sep 17 00:00:00 2001 From: Robert Swiecki Date: Mon, 29 May 2017 16:52:24 +0200 Subject: [PATCH] mount: introduce mountDescribeMountPt --- cmdline.c | 7 +------ mount.c | 48 +++++++++++++++++++++++++++++------------------- mount.h | 1 + 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/cmdline.c b/cmdline.c index 42d7232..8924af7 100644 --- a/cmdline.c +++ b/cmdline.c @@ -223,12 +223,7 @@ void cmdlineLogParams(struct nsjconf_t *nsjconf) { struct mounts_t *p; TAILQ_FOREACH(p, &nsjconf->mountpts, pointers) { - LOG_I - ("Mount point: src:'%s' dst:'%s' type:'%s' flags:%s options:'%s' isDir:%s mandatory:%s src_content:%s (size:%zu)", - p->src ? p->src : "[NULL]", p->dst, p->fs_type ? p->fs_type : "[NULL]", - mountFlagsToStr(p->flags), p->options ? p->options : "[NULL]", - p->isDir ? "true" : "false", p->mandatory ? "true" : "false", - p->src_content ? "true" : "false", p->src_content_len); + LOG_I("Mount point: %s", mountDescribeMountPt(p)); } } { diff --git a/mount.c b/mount.c index 7e73e1e..ba55951 100644 --- a/mount.c +++ b/mount.c @@ -122,10 +122,7 @@ static bool mountMount(struct mounts_t *mpt, const char *newroot, const char *tm char dst[PATH_MAX]; snprintf(dst, sizeof(dst), "%s/%s", newroot, mpt->dst); - LOG_D("Mounting '%s' on '%s' (fstype:'%s', flags:%s, options:'%s', is_dir:%s)", - mpt->src ? mpt->src : "[NULL]", dst, mpt->fs_type ? mpt->fs_type : "[NULL]", - mountFlagsToStr(mpt->flags), mpt->options ? mpt->options : "[NULL]", - mpt->isDir ? "True" : "False"); + LOG_D("Mounting '%s'", mountDescribeMountPt(mpt)); char srcpath[PATH_MAX]; if (mpt->src != NULL && strlen(mpt->src) > 0) { @@ -178,23 +175,15 @@ static bool mountMount(struct mounts_t *mpt, const char *newroot, const char *tm unsigned long flags = mpt->flags & ~(MS_RDONLY); if (mount(srcpath, dst, mpt->fs_type, flags, mpt->options) == -1) { if (mpt->mandatory == false) { - PLOG_D - ("mount(src:'%s', dst:'%s', fstype:'%s', flags:'%s', mandatory:%s) failed. " - "Skipping this mount as it's non-mandatory", srcpath, dst, - mpt->fs_type ? mpt->fs_type : "[NULL]", mountFlagsToStr(mpt->flags), - mpt->mandatory ? "true" : "false"); + PLOG_D("mount('%s') src:'%s' dst:'%s' failed", mountDescribeMountPt(mpt), + srcpath, dst); } else if (errno == EACCES) { - PLOG_E - ("mount(src:'%s', dst:'%s', fstype:'%s', flags:'%s', mandatory:%s) failed. " - "Try fixing this problem by applying 'chmod o+x' to the '%s' directory and " - "its ancestors", srcpath, dst, mpt->fs_type ? mpt->fs_type : "[NULL]", - mountFlagsToStr(mpt->flags), mpt->src, - mpt->mandatory ? "true" : "false"); + PLOG_E("mount('%s') src:'%s' dst:'%s' failed. " + "Try fixing this problem by applying 'chmod o+x' to the '%s' directory and " + "its ancestors", mountDescribeMountPt(mpt), srcpath, dst, srcpath); } else { - PLOG_E - ("mount(src:'%s', dst:'%s', fstype:'%s', flags:'%s' mandatory:%s) failed", - srcpath, dst, mpt->fs_type ? mpt->fs_type : "[NULL]", - mountFlagsToStr(mpt->flags), mpt->mandatory ? "true" : "false"); + PLOG_E("mount('%s') src:'%s' dst:'%s' failed", mountDescribeMountPt(mpt), + srcpath, dst); } if (mpt->mandatory) { return false; @@ -422,3 +411,24 @@ bool mountAddMountPt(struct nsjconf_t * nsjconf, const char *src, const char *ds return true; } + +const char *mountDescribeMountPt(struct mounts_t *mpt) +{ + static __thread char mount_pt_descr[4096]; + + snprintf(mount_pt_descr, sizeof(mount_pt_descr), + "src:'%s' dst:'%s' type:'%s' flags:%s options:'%s' isDir:%s", + mpt->src ? mpt->src : "[NULL]", mpt->dst, mpt->fs_type ? mpt->fs_type : "[NULL]", + mountFlagsToStr(mpt->flags), mpt->options ? mpt->options : "[NULL]", + mpt->isDir ? "true" : "false"); + + if (mpt->mandatory == false) { + utilSSnPrintf(mount_pt_descr, sizeof(mount_pt_descr), " mandatory:false"); + } + if (mpt->src_content) { + utilSSnPrintf(mount_pt_descr, sizeof(mount_pt_descr), " src_content_len:%zu", + mpt->src_content_len); + } + + return mount_pt_descr; +} diff --git a/mount.h b/mount.h index 2cfcc5a..fa4f424 100644 --- a/mount.h +++ b/mount.h @@ -33,5 +33,6 @@ bool mountAddMountPt(struct nsjconf_t *nsjconf, const char *src, const char *dst const char *fstype, const char *options, uintptr_t flags, const bool * isDir, bool mandatory, const char *src_env, const char *dst_env, const uint8_t * src_content, size_t src_content_len); +const char *mountDescribeMountPt(struct mounts_t *mpt); #endif /* NS_MOUNT_H */