mnt: convert describeMountPt from const char* to std::string

This commit is contained in:
Robert Swiecki 2018-02-11 00:24:43 +01:00
parent 55e8e09c4a
commit 0513124b4f
5 changed files with 14 additions and 12 deletions

View 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",

12
mnt.cc
View File

@ -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(),

2
mnt.h
View File

@ -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

4
net.cc
View File

@ -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;
}

View 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);
}