mount: introduce mountDescribeMountPt
authorRobert Swiecki <robert@swiecki.net>
Mon, 29 May 2017 14:52:24 +0000 (16:52 +0200)
committerRobert Swiecki <robert@swiecki.net>
Mon, 29 May 2017 14:52:24 +0000 (16:52 +0200)
cmdline.c
mount.c
mount.h

index 42d72328e50e78f9200e0058a64078222d089fd5..8924af747703c1f11c28a9d3e96e708a58738c25 100644 (file)
--- 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 7e73e1ef3b494f32abf25eeb29139db78f73c5fb..ba5595103adec60474e89ddbe9849ce1987eac8b 100644 (file)
--- 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 2cfcc5a80efb4c58bcc5d04ff3fcc9e5f5602483..fa4f4246ffa7b07b59221e0c2ac34bd9fc73d756 100644 (file)
--- 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 */