change global vars to _ prefix
authorRobert Swiecki <robert@swiecki.net>
Sat, 10 Feb 2018 19:32:04 +0000 (20:32 +0100)
committerRobert Swiecki <robert@swiecki.net>
Sat, 10 Feb 2018 19:32:04 +0000 (20:32 +0100)
Makefile
cgroup.cc
cmdline.cc
contain.cc
logs.cc
sandbox.cc
subproc.cc

index f170c72ebbb3ef6565a50342cc00ba74c05ed297..3fa6f02110e48b2f274f44cc4fd0794af247e978 100644 (file)
--- 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.
index f52cf1aa66ceb1fde243c71c525133a91c9e0f28..b284e552dab5b420ce8a74c8a41f45111e643991 100644 (file)
--- 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
index 90923b806b0e3fcb655a76c60ab9377ab65a49e6..cc0c0a7dc82b8673ba82fcac9609f30677bc1c92 100644 (file)
@@ -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) {
index e47058901bd5568bb3e02b6eedfb14ab83a6ea90..089c7e6574f280d816f0ec41bfffaeb20c41a336 100644 (file)
 
 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 32115d967a8c7569809bb675e74511f2ab11e87a..d7404a62ec64c6b0293e90e4b3555460f1bcf9b1 100644 (file)
--- a/logs.cc
+++ b/logs.cc
 
 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
index 6d58f43f5f271deeff76e74e670cd9255bccc8f5..02e3cb9e891e8faa0cdf6a4d38193e118c43a414 100644 (file)
@@ -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) {
index 51e06cedf2f4ff8747a4f8e0c2d77aa50bfb5659..97187a468f992458655c941b3d38620af91e6bde 100644 (file)
@@ -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));