change global vars to _ prefix
This commit is contained in:
parent
de3f1371f0
commit
0efa230cdd
2
Makefile
2
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.
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
28
contain.cc
28
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;
|
||||
|
52
logs.cc
52
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
|
||||
|
@ -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) {
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user