From 0efa230cdd54d42077557095932c37fde2e069d8 Mon Sep 17 00:00:00 2001 From: Robert Swiecki Date: Sat, 10 Feb 2018 20:32:04 +0100 Subject: [PATCH] change global vars to _ prefix --- Makefile | 2 +- cgroup.cc | 4 +++- cmdline.cc | 4 +++- contain.cc | 28 +++++++++++++++++++++------- logs.cc | 52 ++++++++++++++++++++++++++++------------------------ sandbox.cc | 4 +++- subproc.cc | 4 +++- 7 files changed, 62 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index f170c72..3fa6f02 100644 --- a/Makefile +++ b/Makefile @@ -85,7 +85,7 @@ depend: makedepend -Y -Ykafel/include -- -- $(SRCS_CXX) $(SRCS_PB_CXX) 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) # DO NOT DELETE THIS LINE -- make depend depends on it. diff --git a/cgroup.cc b/cgroup.cc index f52cf1a..b284e55 100644 --- a/cgroup.cc +++ b/cgroup.cc @@ -282,6 +282,8 @@ void finishFromParent(nsjconf_t* nsjconf, pid_t pid) { finishFromParentCpu(nsjconf, pid); } -bool initNs(void) { return true; } +bool initNs(void) { + return true; +} } // namespace cgroup diff --git a/cmdline.cc b/cmdline.cc index 90923b8..cc0c0a7 100644 --- a/cmdline.cc +++ b/cmdline.cc @@ -159,7 +159,9 @@ struct custom_option deprecated_opts[] = { }; // 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) { if (option->opt.val < 0x80) { diff --git a/contain.cc b/contain.cc index e470589..089c7e6 100644 --- a/contain.cc +++ b/contain.cc @@ -50,15 +50,25 @@ 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) { #ifndef PR_SET_NO_NEW_PRIVS @@ -97,9 +107,13 @@ static bool containPrepareEnv(nsjconf_t* nsjconf) { 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) { struct rlimit64 rl; diff --git a/logs.cc b/logs.cc index 32115d9..d7404a6 100644 --- a/logs.cc +++ b/logs.cc @@ -41,11 +41,13 @@ namespace logs { -static int log_fd = STDERR_FILENO; -static bool log_fd_isatty = true; -static enum llevel_t log_level = INFO; +static int _log_fd = STDERR_FILENO; +static bool _log_fd_isatty = true; +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 @@ -53,28 +55,28 @@ __attribute__((constructor)) static void log_init(void) { log_fd_isatty = isatty */ bool initLog(const std::string& logfile, llevel_t level) { /* Close previous log_fd */ - if (log_fd > STDERR_FILENO) { - close(log_fd); - log_fd = STDERR_FILENO; + if (_log_fd > STDERR_FILENO) { + close(_log_fd); + _log_fd = STDERR_FILENO; } - log_level = level; + _log_level = level; if (logfile.empty()) { - log_fd = fcntl(log_fd, F_DUPFD_CLOEXEC, 0); + _log_fd = fcntl(_log_fd, F_DUPFD_CLOEXEC, 0); } 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) { - log_fd = STDERR_FILENO; - log_fd_isatty = (isatty(log_fd) == 1 ? true : false); + _log_fd = STDERR_FILENO; + _log_fd_isatty = (isatty(_log_fd) == 1 ? true : false); PLOG_E("Couldn't open logfile open('%s')", logfile.c_str()); return false; } } - log_fd_isatty = (isatty(log_fd) == 1 ? true : false); + _log_fd_isatty = (isatty(_log_fd) == 1 ? true : false); return true; } 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; } @@ -107,27 +109,27 @@ void logMsg(enum llevel_t ll, const char* fn, int ln, bool perr, const char* fmt } /* Start printing logs */ - if (log_fd_isatty) { - dprintf(log_fd, "%s", logLevels[ll].prefix); + if (_log_fd_isatty) { + dprintf(_log_fd, "%s", logLevels[ll].prefix); } if (logLevels[ll].print_time) { - dprintf(log_fd, "[%s] ", timestr); + dprintf(_log_fd, "[%s] ", timestr); } 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_start(args, fmt); - vdprintf(log_fd, fmt, args); + vdprintf(_log_fd, fmt, args); va_end(args); if (perr) { - dprintf(log_fd, ": %s", strerr); + dprintf(_log_fd, ": %s", strerr); } - if (log_fd_isatty) { - dprintf(log_fd, "\033[0m"); + if (_log_fd_isatty) { + dprintf(_log_fd, "\033[0m"); } - dprintf(log_fd, "\n"); + dprintf(_log_fd, "\n"); /* End printing logs */ 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 diff --git a/sandbox.cc b/sandbox.cc index 6d58f43..02e3cb9 100644 --- a/sandbox.cc +++ b/sandbox.cc @@ -53,7 +53,9 @@ static bool prepareAndCommit(nsjconf_t* nsjconf) { return true; } -bool applyPolicy(nsjconf_t* nsjconf) { return prepareAndCommit(nsjconf); } +bool applyPolicy(nsjconf_t* nsjconf) { + return prepareAndCommit(nsjconf); +} bool preparePolicy(nsjconf_t* nsjconf) { if (nsjconf->kafel_file_path == NULL && nsjconf->kafel_string == NULL) { diff --git a/subproc.cc b/subproc.cc index 51e06ce..97187a4 100644 --- a/subproc.cc +++ b/subproc.cc @@ -225,7 +225,9 @@ static void removeProc(nsjconf_t* nsjconf, pid_t 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) { LOG_I("Total number of spawned namespaces: %d", countProc(nsjconf));