mnt: convert describeMountPt from const char* to std::string
authorRobert Swiecki <robert@swiecki.net>
Sat, 10 Feb 2018 23:24:43 +0000 (00:24 +0100)
committerRobert Swiecki <robert@swiecki.net>
Sat, 10 Feb 2018 23:24:43 +0000 (00:24 +0100)
cmdline.cc
mnt.cc
mnt.h
net.cc
subproc.cc

index 2924297..a97ea77 100644 (file)
@@ -239,7 +239,8 @@ void logParams(nsjconf_t* nsjconf) {
            logYesNo(nsjconf->disable_no_new_privs), nsjconf->max_cpus);
 
        for (const auto& p : nsjconf->mountpts) {
-               LOG_I("%s: %s", p.isSymlink ? "Symlink" : "Mount point", mnt::describeMountPt(p));
+               LOG_I("%s: %s", p.isSymlink ? "Symlink" : "Mount point",
+                   mnt::describeMountPt(p).c_str());
        }
        for (const auto& uid : nsjconf->uids) {
                LOG_I("Uid map: inside_uid:%lu outside_uid:%lu count:%zu newuidmap:%s",
diff --git a/mnt.cc b/mnt.cc
index bd7a5be..9f175ad 100644 (file)
--- a/mnt.cc
+++ b/mnt.cc
@@ -124,7 +124,7 @@ static bool mountPt(mount_t* mpt, const char* newroot, const char* tmpdir) {
        char dst[PATH_MAX];
        snprintf(dst, sizeof(dst), "%s/%s", newroot, mpt->dst.c_str());
 
-       LOG_D("Mounting '%s'", describeMountPt(*mpt));
+       LOG_D("Mounting '%s'", describeMountPt(*mpt).c_str());
 
        char srcpath[PATH_MAX];
        if (!mpt->src.empty()) {
@@ -204,10 +204,10 @@ static bool mountPt(mount_t* mpt, const char* newroot, const char* tmpdir) {
                            "mount('%s') src:'%s' dst:'%s' failed. "
                            "Try fixing this problem by applying 'chmod o+x' to the '%s' "
                            "directory and its ancestors",
-                           describeMountPt(*mpt), srcpath, dst, srcpath);
+                           describeMountPt(*mpt).c_str(), srcpath, dst, srcpath);
                } else {
-                       PLOG_W("mount('%s') src:'%s' dst:'%s' failed", describeMountPt(*mpt),
-                           srcpath, dst);
+                       PLOG_W("mount('%s') src:'%s' dst:'%s' failed",
+                           describeMountPt(*mpt).c_str(), srcpath, dst);
                        if (strcmp(mpt->fs_type.c_str(), "proc") == 0) {
                                PLOG_W(
                                    "procfs can only be mounted if the original /proc doesn't have "
@@ -529,8 +529,8 @@ bool addMountPtTail(nsjconf_t* nsjconf, const char* src, const char* dst, const
        return true;
 }
 
-const char* describeMountPt(const mount_t& mpt) {
-       static __thread char mount_pt_descr[4096];
+const std::string describeMountPt(const mount_t& mpt) {
+       char mount_pt_descr[256];
 
        snprintf(mount_pt_descr, sizeof(mount_pt_descr),
            "src:'%s' dst:'%s' type:'%s' flags:%s options:'%s' isDir:%s", mpt.src.c_str(),
diff --git a/mnt.h b/mnt.h
index 756e293..4237853 100644 (file)
--- a/mnt.h
+++ b/mnt.h
@@ -44,7 +44,7 @@ bool addMountPtHead(nsjconf_t* nsjconf, const char* src, const char* dst, const
 bool addMountPtTail(nsjconf_t* nsjconf, const char* src, const char* dst, const char* fstype,
     const char* options, uintptr_t flags, isDir_t isDir, bool mandatory, const char* src_env,
     const char* dst_env, const char* src_content, size_t src_content_len, bool is_symlink);
-const char* describeMountPt(const mount_t& mpt);
+const std::string describeMountPt(const mount_t& mpt);
 
 }  // namespace mnt
 
diff --git a/net.cc b/net.cc
index 66ef6eb..123e0f8 100644 (file)
--- a/net.cc
+++ b/net.cc
@@ -173,8 +173,8 @@ bool limitConns(nsjconf_t* nsjconf, int connsock) {
                }
        }
        if (cnt >= nsjconf->max_conns_per_ip) {
-               LOG_W("Rejecting connection from '%s', max_conns_per_ip limit reached: %u", connstr.c_str(),
-                   nsjconf->max_conns_per_ip);
+               LOG_W("Rejecting connection from '%s', max_conns_per_ip limit reached: %u",
+                   connstr.c_str(), nsjconf->max_conns_per_ip);
                return false;
        }
 
index d09d181..78a1ee1 100644 (file)
@@ -325,8 +325,9 @@ int reapProc(nsjconf_t* nsjconf) {
                        if (WIFSIGNALED(status)) {
                                LOG_I(
                                    "PID: %d (%s) terminated with signal: %s (%d), (PIDs left: %d)",
-                                   si.si_pid, remote_txt.c_str(), util::sigName(WTERMSIG(status)).c_str(),
-                                   WTERMSIG(status), countProc(nsjconf) - 1);
+                                   si.si_pid, remote_txt.c_str(),
+                                   util::sigName(WTERMSIG(status)).c_str(), WTERMSIG(status),
+                                   countProc(nsjconf) - 1);
                                removeProc(nsjconf, si.si_pid);
                                rv = 100 + WTERMSIG(status);
                        }