all: move to C++
authorRobert Swiecki <robert@swiecki.net>
Fri, 9 Feb 2018 17:55:42 +0000 (18:55 +0100)
committerRobert Swiecki <robert@swiecki.net>
Fri, 9 Feb 2018 17:55:42 +0000 (18:55 +0100)
21 files changed:
Makefile
caps.cc
cgroup.cc
cmdline.cc
config.cc
config.h
contain.cc
cpu.cc
log.c [deleted file]
log.cc [new file with mode: 0644]
log.h
mnt.cc
net.cc
nsjail.cc
nsjail.h
pid.cc
sandbox.cc
subproc.cc
user.cc
util.cc
uts.cc

index 74519ff16ee2f0e1d5f64a6671e9d482633f359a..7d2c1c38a89276f776435abf5a2fbf1602ed41b1 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -35,8 +35,8 @@ LDFLAGS += -pie -Wl,-z,noexecstack -lpthread $(shell pkg-config --libs protobuf)
 
 BIN = nsjail
 LIBS = kafel/libkafel.a
-SRCS_C = log.c
-SRCS_CXX = caps.cc cgroup.cc cmdline.cc config.cc contain.cc cpu.cc mnt.cc net.cc nsjail.cc pid.cc sandbox.cc subproc.cc uts.cc user.cc util.cc
+SRCS_C =
+SRCS_CXX = caps.cc cgroup.cc cmdline.cc config.cc contain.cc cpu.cc log.cc mnt.cc net.cc nsjail.cc pid.cc sandbox.cc subproc.cc uts.cc user.cc util.cc
 SRCS_PROTO = config.proto
 SRCS_PB_CXX = $(SRCS_PROTO:.proto=.pb.cc)
 SRCS_PB_H = $(SRCS_PROTO:.proto=.pb.h)
@@ -92,28 +92,29 @@ depend:
        makedepend -Y -Ykafel/include -- -- $(SRCS_C) $(SRCS_CXX) $(SRCS_PB_CXX)
 
 indent:
-       clang-format -style="{BasedOnStyle: google, IndentWidth: 8, UseTab: Always, IndentCaseLabels: false, ColumnLimit: 100, AlignAfterOpenBracket: false}" -i -sort-includes *.c *.h $(SRCS_CXX)
+       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: 4, UseTab: Always, ColumnLimit: 100}" -i $(SRCS_PROTO)
 
 # DO NOT DELETE THIS LINE -- make depend depends on it.
 
-log.o: log.h nsjail.h
-caps.o: caps.h nsjail.h log.h common.h util.h
+caps.o: caps.h nsjail.h common.h log.h util.h
 cgroup.o: cgroup.h nsjail.h log.h util.h
-cmdline.o: cmdline.h nsjail.h log.h caps.h common.h config.h mnt.h sandbox.h
+cmdline.o: cmdline.h nsjail.h caps.h common.h config.h log.h mnt.h sandbox.h
 cmdline.o: user.h util.h
-config.o: log.h nsjail.h caps.h cmdline.h common.h config.h mnt.h user.h
-config.o: util.h
-contain.o: contain.h nsjail.h log.h caps.h cgroup.h cpu.h mnt.h net.h pid.h
+config.o: caps.h nsjail.h cmdline.h common.h config.h config.pb.h log.h mnt.h
+config.o: user.h util.h
+contain.o: contain.h nsjail.h caps.h cgroup.h cpu.h log.h mnt.h net.h pid.h
 contain.o: user.h uts.h
 cpu.o: cpu.h nsjail.h log.h util.h
-mnt.o: mnt.h nsjail.h log.h common.h subproc.h util.h
+log.o: log.h nsjail.h
+mnt.o: mnt.h nsjail.h common.h log.h subproc.h util.h
 net.o: net.h nsjail.h log.h subproc.h
 nsjail.o: nsjail.h cmdline.h common.h log.h net.h subproc.h util.h
 pid.o: pid.h nsjail.h log.h subproc.h
 sandbox.o: sandbox.h nsjail.h kafel/include/kafel.h log.h
-subproc.o: subproc.h nsjail.h cgroup.h common.h contain.h net.h sandbox.h
-subproc.o: user.h util.h log.h
+subproc.o: subproc.h nsjail.h cgroup.h common.h contain.h log.h net.h
+subproc.o: sandbox.h user.h util.h
 uts.o: uts.h nsjail.h log.h
-user.o: user.h nsjail.h log.h common.h subproc.h util.h
+user.o: user.h nsjail.h common.h log.h subproc.h util.h
 util.o: util.h nsjail.h common.h log.h
+config.pb.o: config.pb.h
diff --git a/caps.cc b/caps.cc
index c7e168e4d8caa3cb7509effe2d0f67d21b955ef5..0dd7460c8d5843886cfc2ed44a16d14f136bd151 100644 (file)
--- a/caps.cc
+++ b/caps.cc
 #include <sys/types.h>
 #include <unistd.h>
 
-extern "C" {
-#include "log.h"
-}
-
 #include "common.h"
+#include "log.h"
 #include "util.h"
 
 namespace caps {
index 21602790bc1a73e2e5bf3c6235df7e33a70720bd..a51e3ef11033445dbb98eac22e695285cfa9f301 100644 (file)
--- a/cgroup.cc
+++ b/cgroup.cc
 #include <sys/stat.h>
 #include <unistd.h>
 
-extern "C" {
 #include "log.h"
-}
-
 #include "util.h"
 
 namespace cgroup {
index 7cb61220cc7c7e6d56a84e770c3e55337218b163..2f5b74f6f9315fd22d35df47f1259b23528a8e37 100644 (file)
 
 #include <memory>
 
-extern "C" {
-#include "log.h"
-}
-
 #include "caps.h"
 #include "common.h"
 #include "config.h"
+#include "log.h"
 #include "mnt.h"
 #include "sandbox.h"
 #include "user.h"
@@ -441,7 +438,7 @@ std::unique_ptr<struct nsjconf_t> parseArgs(int argc, char* argv[]) {
                        nsjconf->cwd = optarg;
                        break;
                case 'C':
-                       if (configParse(nsjconf.get(), optarg) == false) {
+                       if (config::parseFile(nsjconf.get(), optarg) == false) {
                                LOG_F("Couldn't parse configuration from '%s' file", optarg);
                        }
                        break;
@@ -460,13 +457,13 @@ std::unique_ptr<struct nsjconf_t> parseArgs(int argc, char* argv[]) {
                        break;
                case 'l':
                        nsjconf->logfile = optarg;
-                       if (logInitLogFile(nsjconf.get()) == false) {
+                       if (log::initLogFile(nsjconf.get()) == false) {
                                return nullptr;
                        }
                        break;
                case 'L':
                        nsjconf->log_fd = strtol(optarg, NULL, 0);
-                       if (logInitLogFile(nsjconf.get()) == false) {
+                       if (log::initLogFile(nsjconf.get()) == false) {
                                return nullptr;
                        }
                        break;
@@ -475,19 +472,19 @@ std::unique_ptr<struct nsjconf_t> parseArgs(int argc, char* argv[]) {
                        break;
                case 'v':
                        nsjconf->loglevel = DEBUG;
-                       if (logInitLogFile(nsjconf.get()) == false) {
+                       if (log::initLogFile(nsjconf.get()) == false) {
                                return nullptr;
                        }
                        break;
                case 'q':
                        nsjconf->loglevel = WARNING;
-                       if (logInitLogFile(nsjconf.get()) == false) {
+                       if (log::initLogFile(nsjconf.get()) == false) {
                                return nullptr;
                        }
                        break;
                case 'Q':
                        nsjconf->loglevel = FATAL;
-                       if (logInitLogFile(nsjconf.get()) == false) {
+                       if (log::initLogFile(nsjconf.get()) == false) {
                                return nullptr;
                        }
                        break;
@@ -829,7 +826,7 @@ std::unique_ptr<struct nsjconf_t> parseArgs(int argc, char* argv[]) {
                TAILQ_INSERT_HEAD(&nsjconf->gids, p, pointers);
        }
 
-       if (logInitLogFile(nsjconf.get()) == false) {
+       if (log::initLogFile(nsjconf.get()) == false) {
                return nullptr;
        }
 
index ec2438c174d4b8b1758df67fcb5ff1ce571a0e57..13afbbbe9cabd26f54eb8a6b2cdd00cfb53f67d0 100644 (file)
--- a/config.cc
+++ b/config.cc
 #include <string>
 #include <vector>
 
-extern "C" {
-#include "log.h"
-}
 #include "caps.h"
 #include "cmdline.h"
 #include "common.h"
 #include "config.h"
 #include "config.pb.h"
+#include "log.h"
 #include "mnt.h"
 #include "user.h"
 #include "util.h"
 
+namespace config {
+
 #define DUP_IF_SET(njc, val) (njc.has_##val() ? njc.val().c_str() : NULL)
 
 static uint64_t configRLimit(
@@ -122,7 +122,7 @@ static bool configParseInternal(struct nsjconf_t* nsjconf, const nsjail::NsJailC
        }
 
        if (njc.has_log_fd() || njc.has_log_file() || njc.has_log_level()) {
-               if (logInitLogFile(nsjconf) == false) {
+               if (log::initLogFile(nsjconf) == false) {
                        return false;
                }
        }
@@ -305,7 +305,7 @@ static void LogHandler(
        LOG_W("config.cc: '%s'", message.c_str());
 }
 
-extern "C" bool configParse(struct nsjconf_t* nsjconf, const char* file) {
+bool parseFile(struct nsjconf_t* nsjconf, const char* file) {
        LOG_I("Parsing configuration from '%s'", file);
 
        int fd = open(file, O_RDONLY | O_CLOEXEC);
@@ -334,3 +334,5 @@ extern "C" bool configParse(struct nsjconf_t* nsjconf, const char* file) {
 
        return true;
 }
+
+}  // namespace config
index a789c3b0ec8ce1954866946e97f8e8ad65623932..157098a83bee6f2ae1b6f14bc24f386513ac2af8 100644 (file)
--- a/config.h
+++ b/config.h
 #ifndef NS_CONFIG_H
 #define NS_CONFIG_H
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #include <stdbool.h>
 
 #include "nsjail.h"
 
-bool configParse(struct nsjconf_t* nsjconf, const char* file);
+namespace config {
+
+bool parseFile(struct nsjconf_t* nsjconf, const char* file);
+
+}  // namespace config
 
-#ifdef __cplusplus
-}  // extern "C"
-#endif
 #endif /*  NS_CONFIG_H */
index c16f19ec9746084056e111497a4e763863d3f4f9..9f36bb78c0efecb3485139a4b660774386cfc694 100644 (file)
 #include <sys/resource.h>
 #include <unistd.h>
 
-extern "C" {
-#include "log.h"
-}
-
 #include "caps.h"
 #include "cgroup.h"
 #include "cpu.h"
+#include "log.h"
 #include "mnt.h"
 #include "net.h"
 #include "pid.h"
diff --git a/cpu.cc b/cpu.cc
index eaa636f4a25b740f037758bcc03e2d55ad8e9ab5..1c0c97afdc2c367a231f2df6bc4972f888a1db77 100644 (file)
--- a/cpu.cc
+++ b/cpu.cc
 #include <string.h>
 #include <unistd.h>
 
-extern "C" {
 #include "log.h"
-}
-
 #include "util.h"
 
 namespace cpu {
diff --git a/log.c b/log.c
deleted file mode 100644 (file)
index 42ffd9c..0000000
--- a/log.c
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
-
-   nsjail - logging
-   -----------------------------------------
-
-   Copyright 2014 Google Inc. All Rights Reserved.
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-     http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-
-*/
-
-#include "log.h"
-
-#include <errno.h>
-#include <fcntl.h>
-#include <getopt.h>
-#include <limits.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/syscall.h>
-#include <sys/types.h>
-#include <time.h>
-#include <unistd.h>
-
-#include "nsjail.h"
-
-static int log_fd = STDERR_FILENO;
-static bool log_fd_isatty = true;
-static enum llevel_t log_level = INFO;
-
-#define _LOG_DEFAULT_FILE "/var/log/nsjail.log"
-
-__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
- * connection socket with fd (0, 1, 2).
- */
-bool logInitLogFile(struct nsjconf_t* nsjconf) {
-       /* Close previous log_fd */
-       if (log_fd > STDERR_FILENO) {
-               close(log_fd);
-               log_fd = STDERR_FILENO;
-       }
-       log_fd = nsjconf->log_fd;
-       log_level = nsjconf->loglevel;
-
-       if (nsjconf->logfile == NULL && nsjconf->daemonize) {
-               nsjconf->logfile = _LOG_DEFAULT_FILE;
-       }
-       if (nsjconf->logfile == NULL) {
-               log_fd = fcntl(log_fd, F_DUPFD_CLOEXEC, 0);
-       } else {
-               if (TEMP_FAILURE_RETRY(
-                       log_fd = open(nsjconf->logfile, O_CREAT | O_RDWR | O_APPEND, 0640)) == -1) {
-                       log_fd = STDERR_FILENO;
-                       PLOG_E("Couldn't open logfile open('%s')", nsjconf->logfile);
-                       return false;
-               }
-       }
-       log_fd_isatty = (isatty(log_fd) == 1 ? true : false);
-       return true;
-}
-
-void logLog(enum llevel_t ll, const char* fn, int ln, bool perr, const char* fmt, ...) {
-       if (ll < log_level) {
-               return;
-       }
-
-       char strerr[512];
-       if (perr) {
-               snprintf(strerr, sizeof(strerr), "%s", strerror(errno));
-       }
-       struct ll_t {
-               const char* const descr;
-               const char* const prefix;
-               const bool print_funcline;
-               const bool print_time;
-       };
-       static struct ll_t const logLevels[] = {
-           {"D", "\033[0;4m", true, true},
-           {"I", "\033[1m", false, true},
-           {"W", "\033[0;33m", true, true},
-           {"E", "\033[1;31m", true, true},
-           {"F", "\033[7;35m", true, true},
-           {"HR", "\033[0m", false, false},
-           {"HB", "\033[1m", false, false},
-       };
-
-       time_t ltstamp = time(NULL);
-       struct tm utctime;
-       localtime_r(&ltstamp, &utctime);
-       char timestr[32];
-       if (strftime(timestr, sizeof(timestr) - 1, "%FT%T%z", &utctime) == 0) {
-               timestr[0] = '\0';
-       }
-
-       /* Start printing logs */
-       if (log_fd_isatty) {
-               dprintf(log_fd, "%s", logLevels[ll].prefix);
-       }
-       if (logLevels[ll].print_time) {
-               dprintf(log_fd, "[%s] ", timestr);
-       }
-       if (logLevels[ll].print_funcline) {
-               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);
-       va_end(args);
-       if (perr) {
-               dprintf(log_fd, ": %s", strerr);
-       }
-       if (log_fd_isatty) {
-               dprintf(log_fd, "\033[0m");
-       }
-       dprintf(log_fd, "\n");
-       /* End printing logs */
-
-       if (ll == FATAL) {
-               exit(0xff);
-       }
-}
-
-void logStop(int sig) { LOG_I("Server stops due to fatal signal (%d) caught. Exiting", sig); }
diff --git a/log.cc b/log.cc
new file mode 100644 (file)
index 0000000..88bbfc2
--- /dev/null
+++ b/log.cc
@@ -0,0 +1,144 @@
+/*
+
+   nsjail - logging
+   -----------------------------------------
+
+   Copyright 2014 Google Inc. All Rights Reserved.
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+*/
+
+#include "log.h"
+
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "nsjail.h"
+
+namespace log {
+
+static int log_fd = STDERR_FILENO;
+static bool log_fd_isatty = true;
+static enum llevel_t log_level = INFO;
+
+#define _LOG_DEFAULT_FILE "/var/log/nsjail.log"
+
+__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
+ * connection socket with fd (0, 1, 2).
+ */
+bool initLogFile(struct nsjconf_t* nsjconf) {
+       /* Close previous log_fd */
+       if (log_fd > STDERR_FILENO) {
+               close(log_fd);
+               log_fd = STDERR_FILENO;
+       }
+       log_fd = nsjconf->log_fd;
+       log_level = nsjconf->loglevel;
+
+       if (nsjconf->logfile == NULL && nsjconf->daemonize) {
+               nsjconf->logfile = _LOG_DEFAULT_FILE;
+       }
+       if (nsjconf->logfile == NULL) {
+               log_fd = fcntl(log_fd, F_DUPFD_CLOEXEC, 0);
+       } else {
+               if (TEMP_FAILURE_RETRY(
+                       log_fd = open(nsjconf->logfile, O_CREAT | O_RDWR | O_APPEND, 0640)) == -1) {
+                       log_fd = STDERR_FILENO;
+                       PLOG_E("Couldn't open logfile open('%s')", nsjconf->logfile);
+                       return 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) {
+               return;
+       }
+
+       char strerr[512];
+       if (perr) {
+               snprintf(strerr, sizeof(strerr), "%s", strerror(errno));
+       }
+       struct ll_t {
+               const char* const descr;
+               const char* const prefix;
+               const bool print_funcline;
+               const bool print_time;
+       };
+       static struct ll_t const logLevels[] = {
+           {"D", "\033[0;4m", true, true},
+           {"I", "\033[1m", false, true},
+           {"W", "\033[0;33m", true, true},
+           {"E", "\033[1;31m", true, true},
+           {"F", "\033[7;35m", true, true},
+           {"HR", "\033[0m", false, false},
+           {"HB", "\033[1m", false, false},
+       };
+
+       time_t ltstamp = time(NULL);
+       struct tm utctime;
+       localtime_r(&ltstamp, &utctime);
+       char timestr[32];
+       if (strftime(timestr, sizeof(timestr) - 1, "%FT%T%z", &utctime) == 0) {
+               timestr[0] = '\0';
+       }
+
+       /* Start printing logs */
+       if (log_fd_isatty) {
+               dprintf(log_fd, "%s", logLevels[ll].prefix);
+       }
+       if (logLevels[ll].print_time) {
+               dprintf(log_fd, "[%s] ", timestr);
+       }
+       if (logLevels[ll].print_funcline) {
+               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);
+       va_end(args);
+       if (perr) {
+               dprintf(log_fd, ": %s", strerr);
+       }
+       if (log_fd_isatty) {
+               dprintf(log_fd, "\033[0m");
+       }
+       dprintf(log_fd, "\n");
+       /* End printing logs */
+
+       if (ll == FATAL) {
+               exit(0xff);
+       }
+}
+
+void logStop(int sig) { LOG_I("Server stops due to fatal signal (%d) caught. Exiting", sig); }
+
+}  // namespace log
diff --git a/log.h b/log.h
index c265ac3c38be44af88b2f4a9bea0658b98049352..4129a3b55e83311ff195a44ef4a913b2f4ae1eec 100644 (file)
--- a/log.h
+++ b/log.h
 
 #include "nsjail.h"
 
-#define LOG_HELP(...) logLog(HELP, __func__, __LINE__, false, __VA_ARGS__);
-#define LOG_HELP_BOLD(...) logLog(HELP_BOLD, __func__, __LINE__, false, __VA_ARGS__);
-
-#define LOG_D(...) logLog(DEBUG, __func__, __LINE__, false, __VA_ARGS__);
-#define LOG_I(...) logLog(INFO, __func__, __LINE__, false, __VA_ARGS__);
-#define LOG_W(...) logLog(WARNING, __func__, __LINE__, false, __VA_ARGS__);
-#define LOG_E(...) logLog(ERROR, __func__, __LINE__, false, __VA_ARGS__);
-#define LOG_F(...) logLog(FATAL, __func__, __LINE__, false, __VA_ARGS__);
-
-#define PLOG_D(...) logLog(DEBUG, __func__, __LINE__, true, __VA_ARGS__);
-#define PLOG_I(...) logLog(INFO, __func__, __LINE__, true, __VA_ARGS__);
-#define PLOG_W(...) logLog(WARNING, __func__, __LINE__, true, __VA_ARGS__);
-#define PLOG_E(...) logLog(ERROR, __func__, __LINE__, true, __VA_ARGS__);
-#define PLOG_F(...) logLog(FATAL, __func__, __LINE__, true, __VA_ARGS__);
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-bool logInitLogFile(struct nsjconf_t* nsjconf);
-void logLog(enum llevel_t ll, const char* fn, int ln, bool perr, const char* fmt, ...)
+#define LOG_HELP(...) log::logMsg(HELP, __func__, __LINE__, false, __VA_ARGS__);
+#define LOG_HELP_BOLD(...) log::logMsg(HELP_BOLD, __func__, __LINE__, false, __VA_ARGS__);
+
+#define LOG_D(...) log::logMsg(DEBUG, __func__, __LINE__, false, __VA_ARGS__);
+#define LOG_I(...) log::logMsg(INFO, __func__, __LINE__, false, __VA_ARGS__);
+#define LOG_W(...) log::logMsg(WARNING, __func__, __LINE__, false, __VA_ARGS__);
+#define LOG_E(...) log::logMsg(ERROR, __func__, __LINE__, false, __VA_ARGS__);
+#define LOG_F(...) log::logMsg(FATAL, __func__, __LINE__, false, __VA_ARGS__);
+
+#define PLOG_D(...) log::logMsg(DEBUG, __func__, __LINE__, true, __VA_ARGS__);
+#define PLOG_I(...) log::logMsg(INFO, __func__, __LINE__, true, __VA_ARGS__);
+#define PLOG_W(...) log::logMsg(WARNING, __func__, __LINE__, true, __VA_ARGS__);
+#define PLOG_E(...) log::logMsg(ERROR, __func__, __LINE__, true, __VA_ARGS__);
+#define PLOG_F(...) log::logMsg(FATAL, __func__, __LINE__, true, __VA_ARGS__);
+
+namespace log {
+
+bool initLogFile(struct nsjconf_t* nsjconf);
+void logMsg(enum llevel_t ll, const char* fn, int ln, bool perr, const char* fmt, ...)
     __attribute__((format(printf, 5, 6)));
 void logStop(int sig);
 
-#ifdef __cplusplus
-}  // extern "C"
-#endif
+}  // namespace log
 
 #endif /* NS_LOG_H */
diff --git a/mnt.cc b/mnt.cc
index 864941a51236ca29e9115b838f8dad516f561818..da29793f239b07bbb32eace3952bede6b0e695f4 100644 (file)
--- a/mnt.cc
+++ b/mnt.cc
 #include <syscall.h>
 #include <unistd.h>
 
-extern "C" {
-#include "log.h"
-}
-
 #include "common.h"
+#include "log.h"
 #include "subproc.h"
 #include "util.h"
 
diff --git a/net.cc b/net.cc
index 120931525e60ebfe95fbd18dc676adf48cd7662a..d9e5d106f5a31c8b9b4c14657ce887e8b851032e 100644 (file)
--- a/net.cc
+++ b/net.cc
 #include <sys/types.h>
 #include <unistd.h>
 
-extern "C" {
 #include "log.h"
-}
-
 #include "subproc.h"
 
 extern char** environ;
index 0fac593276a0c76a516610731657d191cc4f1d7b..2b9b9dd2667f2168e6bac93b6670f7fc627e05e2 100644 (file)
--- a/nsjail.cc
+++ b/nsjail.cc
@@ -112,7 +112,7 @@ static void nsjailListenMode(struct nsjconf_t* nsjconf) {
        for (;;) {
                if (nsjailSigFatal > 0) {
                        subproc::killAll(nsjconf);
-                       logStop(nsjailSigFatal);
+                       log::logStop(nsjailSigFatal);
                        close(listenfd);
                        return;
                }
@@ -147,7 +147,7 @@ static int nsjailStandaloneMode(struct nsjconf_t* nsjconf) {
                }
                if (nsjailSigFatal > 0) {
                        subproc::killAll(nsjconf);
-                       logStop(nsjailSigFatal);
+                       log::logStop(nsjailSigFatal);
                        return -1;
                }
 
index 9b8ebf999e1971eb48a858259d533f905e41ff42..2b7161d6465880e1928c5f97c61d2c5ad6158a05 100644 (file)
--- a/nsjail.h
+++ b/nsjail.h
        }))
 #endif /* !defined(TEMP_FAILURE_RETRY) */
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 static const int nssigs[] = {
     SIGINT,
     SIGQUIT,
@@ -202,8 +198,4 @@ struct nsjconf_t {
        caps;
 };
 
-#ifdef __cplusplus
-}  // extern "C"
-#endif
-
 #endif /* _NSJAIL_H */
diff --git a/pid.cc b/pid.cc
index 30b9c181aaf81bf6f4ac2970c4f1d0931bc78021..b087114ecc1631095f10011c3cd10fb22edae086 100644 (file)
--- a/pid.cc
+++ b/pid.cc
 #include <sys/prctl.h>
 #include <unistd.h>
 
-extern "C" {
 #include "log.h"
-}
-
 #include "subproc.h"
 
 namespace pid {
index 3ac61688f612d6de2f0fc546799105230aaebd84..b7eadb134afd43199b3018897d77a8c4edddb1f9 100644 (file)
@@ -28,8 +28,8 @@
 
 extern "C" {
 #include "kafel.h"
-#include "log.h"
 }
+#include "log.h"
 
 namespace sandbox {
 
index 923a38bae7a07cf6737dccfbbb76e049e170e44c..3ec79280bb28bdeac44cb2b4af75c728e6674ade 100644 (file)
 #include "cgroup.h"
 #include "common.h"
 #include "contain.h"
+#include "log.h"
 #include "net.h"
 #include "sandbox.h"
 #include "user.h"
 #include "util.h"
 
-extern "C" {
-#include "log.h"
-}  // extern "C"
-
 namespace subproc {
 
 #if !defined(CLONE_NEWCGROUP)
diff --git a/user.cc b/user.cc
index a537d2d1cea0cdb5a9ec34a586df107ab9c04bab..a43485a80e768f69d89abeed67effac6681997a3 100644 (file)
--- a/user.cc
+++ b/user.cc
 #include <sys/types.h>
 #include <unistd.h>
 
-extern "C" {
-#include "log.h"
-}
-
 #include "common.h"
+#include "log.h"
 #include "subproc.h"
 #include "util.h"
 
diff --git a/util.cc b/util.cc
index 528767bbf8e33c14a5996611163625508669e370..409d56c8ec6249ca88a57c54649c470a56fe9f98 100644 (file)
--- a/util.cc
+++ b/util.cc
 #include <unistd.h>
 
 #include "common.h"
-
-extern "C" {
 #include "log.h"
-}
 
 namespace util {
 
diff --git a/uts.cc b/uts.cc
index c9129e7efe861162a4cdc2f2a9738bc6e1734e97..1f1081d667c05e59b0b56250070b206b9d4ad5d4 100644 (file)
--- a/uts.cc
+++ b/uts.cc
@@ -24,9 +24,7 @@
 #include <string.h>
 #include <unistd.h>
 
-extern "C" {
 #include "log.h"
-}
 
 namespace uts {