change global vars to _ prefix

This commit is contained in:
Robert Swiecki 2018-02-10 20:32:04 +01:00
parent de3f1371f0
commit 0efa230cdd
7 changed files with 62 additions and 36 deletions

View File

@ -85,7 +85,7 @@ depend:
makedepend -Y -Ykafel/include -- -- $(SRCS_CXX) $(SRCS_PB_CXX) makedepend -Y -Ykafel/include -- -- $(SRCS_CXX) $(SRCS_PB_CXX)
indent: indent:
clang-format -style="{BasedOnStyle: google, IndentWidth: 8, UseTab: Always, IndentCaseLabels: false, ColumnLimit: 100, AlignAfterOpenBracket: false}" -i -sort-includes *.h $(SRCS_CXX) clang-format -style="{BasedOnStyle: google, IndentWidth: 8, UseTab: Always, IndentCaseLabels: false, ColumnLimit: 100, AlignAfterOpenBracket: false, AllowShortFunctionsOnASingleLine: false}" -i -sort-includes *.h $(SRCS_CXX)
clang-format -style="{BasedOnStyle: google, IndentWidth: 4, UseTab: Always, ColumnLimit: 100}" -i $(SRCS_PROTO) clang-format -style="{BasedOnStyle: google, IndentWidth: 4, UseTab: Always, ColumnLimit: 100}" -i $(SRCS_PROTO)
# DO NOT DELETE THIS LINE -- make depend depends on it. # DO NOT DELETE THIS LINE -- make depend depends on it.

View File

@ -282,6 +282,8 @@ void finishFromParent(nsjconf_t* nsjconf, pid_t pid) {
finishFromParentCpu(nsjconf, pid); finishFromParentCpu(nsjconf, pid);
} }
bool initNs(void) { return true; } bool initNs(void) {
return true;
}
} // namespace cgroup } // namespace cgroup

View File

@ -159,7 +159,9 @@ struct custom_option deprecated_opts[] = {
}; };
// clang-format on // clang-format on
static const char* logYesNo(bool yes) { return (yes ? "true" : "false"); } static const char* logYesNo(bool yes) {
return (yes ? "true" : "false");
}
static void cmdlineOptUsage(struct custom_option* option) { static void cmdlineOptUsage(struct custom_option* option) {
if (option->opt.val < 0x80) { if (option->opt.val < 0x80) {

View File

@ -50,15 +50,25 @@
namespace contain { namespace contain {
static bool containUserNs(nsjconf_t* nsjconf) { return user::initNsFromChild(nsjconf); } static bool containUserNs(nsjconf_t* nsjconf) {
return user::initNsFromChild(nsjconf);
}
static bool containInitPidNs(nsjconf_t* nsjconf) { return pid::initNs(nsjconf); } static bool containInitPidNs(nsjconf_t* nsjconf) {
return pid::initNs(nsjconf);
}
static bool containInitNetNs(nsjconf_t* nsjconf) { return net::initNsFromChild(nsjconf); } static bool containInitNetNs(nsjconf_t* nsjconf) {
return net::initNsFromChild(nsjconf);
}
static bool containInitUtsNs(nsjconf_t* nsjconf) { return uts::initNs(nsjconf); } static bool containInitUtsNs(nsjconf_t* nsjconf) {
return uts::initNs(nsjconf);
}
static bool containInitCgroupNs(void) { return cgroup::initNs(); } static bool containInitCgroupNs(void) {
return cgroup::initNs();
}
static bool containDropPrivs(nsjconf_t* nsjconf) { static bool containDropPrivs(nsjconf_t* nsjconf) {
#ifndef PR_SET_NO_NEW_PRIVS #ifndef PR_SET_NO_NEW_PRIVS
@ -97,9 +107,13 @@ static bool containPrepareEnv(nsjconf_t* nsjconf) {
return true; return true;
} }
static bool containInitMountNs(nsjconf_t* nsjconf) { return mnt::initNs(nsjconf); } static bool containInitMountNs(nsjconf_t* nsjconf) {
return mnt::initNs(nsjconf);
}
static bool containCPU(nsjconf_t* nsjconf) { return cpu::initCpu(nsjconf); } static bool containCPU(nsjconf_t* nsjconf) {
return cpu::initCpu(nsjconf);
}
static bool containSetLimits(nsjconf_t* nsjconf) { static bool containSetLimits(nsjconf_t* nsjconf) {
struct rlimit64 rl; struct rlimit64 rl;

52
logs.cc
View File

@ -41,11 +41,13 @@
namespace logs { namespace logs {
static int log_fd = STDERR_FILENO; static int _log_fd = STDERR_FILENO;
static bool log_fd_isatty = true; static bool _log_fd_isatty = true;
static enum llevel_t log_level = INFO; static enum llevel_t _log_level = INFO;
__attribute__((constructor)) static void log_init(void) { log_fd_isatty = isatty(log_fd); } __attribute__((constructor)) static void log_init(void) {
_log_fd_isatty = isatty(_log_fd);
}
/* /*
* Log to stderr by default. Use a dup()d fd, because in the future we'll associate the * Log to stderr by default. Use a dup()d fd, because in the future we'll associate the
@ -53,28 +55,28 @@ __attribute__((constructor)) static void log_init(void) { log_fd_isatty = isatty
*/ */
bool initLog(const std::string& logfile, llevel_t level) { bool initLog(const std::string& logfile, llevel_t level) {
/* Close previous log_fd */ /* Close previous log_fd */
if (log_fd > STDERR_FILENO) { if (_log_fd > STDERR_FILENO) {
close(log_fd); close(_log_fd);
log_fd = STDERR_FILENO; _log_fd = STDERR_FILENO;
} }
log_level = level; _log_level = level;
if (logfile.empty()) { if (logfile.empty()) {
log_fd = fcntl(log_fd, F_DUPFD_CLOEXEC, 0); _log_fd = fcntl(_log_fd, F_DUPFD_CLOEXEC, 0);
} else { } else {
if (TEMP_FAILURE_RETRY(log_fd = open(logfile.c_str(), if (TEMP_FAILURE_RETRY(_log_fd = open(logfile.c_str(),
O_CREAT | O_RDWR | O_APPEND | O_CLOEXEC, 0640)) == -1) { O_CREAT | O_RDWR | O_APPEND | O_CLOEXEC, 0640)) == -1) {
log_fd = STDERR_FILENO; _log_fd = STDERR_FILENO;
log_fd_isatty = (isatty(log_fd) == 1 ? true : false); _log_fd_isatty = (isatty(_log_fd) == 1 ? true : false);
PLOG_E("Couldn't open logfile open('%s')", logfile.c_str()); PLOG_E("Couldn't open logfile open('%s')", logfile.c_str());
return false; return false;
} }
} }
log_fd_isatty = (isatty(log_fd) == 1 ? true : false); _log_fd_isatty = (isatty(_log_fd) == 1 ? true : false);
return true; return true;
} }
void logMsg(enum llevel_t ll, const char* fn, int ln, bool perr, const char* fmt, ...) { void logMsg(enum llevel_t ll, const char* fn, int ln, bool perr, const char* fmt, ...) {
if (ll < log_level) { if (ll < _log_level) {
return; return;
} }
@ -107,27 +109,27 @@ void logMsg(enum llevel_t ll, const char* fn, int ln, bool perr, const char* fmt
} }
/* Start printing logs */ /* Start printing logs */
if (log_fd_isatty) { if (_log_fd_isatty) {
dprintf(log_fd, "%s", logLevels[ll].prefix); dprintf(_log_fd, "%s", logLevels[ll].prefix);
} }
if (logLevels[ll].print_time) { if (logLevels[ll].print_time) {
dprintf(log_fd, "[%s] ", timestr); dprintf(_log_fd, "[%s] ", timestr);
} }
if (logLevels[ll].print_funcline) { if (logLevels[ll].print_funcline) {
dprintf(log_fd, "[%s][%d] %s():%d ", logLevels[ll].descr, (int)getpid(), fn, ln); dprintf(_log_fd, "[%s][%d] %s():%d ", logLevels[ll].descr, (int)getpid(), fn, ln);
} }
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
vdprintf(log_fd, fmt, args); vdprintf(_log_fd, fmt, args);
va_end(args); va_end(args);
if (perr) { if (perr) {
dprintf(log_fd, ": %s", strerr); dprintf(_log_fd, ": %s", strerr);
} }
if (log_fd_isatty) { if (_log_fd_isatty) {
dprintf(log_fd, "\033[0m"); dprintf(_log_fd, "\033[0m");
} }
dprintf(log_fd, "\n"); dprintf(_log_fd, "\n");
/* End printing logs */ /* End printing logs */
if (ll == FATAL) { if (ll == FATAL) {
@ -135,6 +137,8 @@ void logMsg(enum llevel_t ll, const char* fn, int ln, bool perr, const char* fmt
} }
} }
void logStop(int sig) { LOG_I("Server stops due to fatal signal (%d) caught. Exiting", sig); } void logStop(int sig) {
LOG_I("Server stops due to fatal signal (%d) caught. Exiting", sig);
}
} // namespace logs } // namespace logs

View File

@ -53,7 +53,9 @@ static bool prepareAndCommit(nsjconf_t* nsjconf) {
return true; return true;
} }
bool applyPolicy(nsjconf_t* nsjconf) { return prepareAndCommit(nsjconf); } bool applyPolicy(nsjconf_t* nsjconf) {
return prepareAndCommit(nsjconf);
}
bool preparePolicy(nsjconf_t* nsjconf) { bool preparePolicy(nsjconf_t* nsjconf) {
if (nsjconf->kafel_file_path == NULL && nsjconf->kafel_string == NULL) { if (nsjconf->kafel_file_path == NULL && nsjconf->kafel_string == NULL) {

View File

@ -225,7 +225,9 @@ static void removeProc(nsjconf_t* nsjconf, pid_t pid) {
LOG_W("PID: %d not found (?)", pid); LOG_W("PID: %d not found (?)", pid);
} }
int countProc(nsjconf_t* nsjconf) { return nsjconf->pids.size(); } int countProc(nsjconf_t* nsjconf) {
return nsjconf->pids.size();
}
void displayProc(nsjconf_t* nsjconf) { void displayProc(nsjconf_t* nsjconf) {
LOG_I("Total number of spawned namespaces: %d", countProc(nsjconf)); LOG_I("Total number of spawned namespaces: %d", countProc(nsjconf));