nsjconf->max_conns_per_ip = strtoul(optarg, NULL, 0);
break;
case 'l':
- logs::logFile(optarg);
+ logs::logFile(optarg, STDERR_FILENO);
break;
case 'L':
- logs::logFile(std::string("/dev/fd/") + optarg);
+ logs::logFile("", std::strtol(optarg, NULL, 0));
break;
case 'd':
nsjconf->daemonize = true;
}
if (nsjconf->daemonize && !logs::logSet()) {
- logs::logFile(_LOG_DEFAULT_FILE);
+ logs::logFile(_LOG_DEFAULT_FILE, STDERR_FILENO);
}
if (!setupMounts(nsjconf.get())) {
return nullptr;
nsjconf->daemonize = njc.daemon();
if (njc.has_log_fd()) {
- logs::logFile(std::string("/dev/fd/") + std::to_string(njc.log_fd()));
+ logs::logFile("", njc.log_fd());
}
if (njc.has_log_file()) {
- logs::logFile(njc.log_file());
+ logs::logFile(njc.log_file(), STDERR_FILENO);
}
+
if (njc.has_log_level()) {
switch (njc.log_level()) {
case nsjail::LogLevel::DEBUG:
/* FD to log to. */
optional int32 log_fd = 16;
- /* File to save logs to */
+ /* File to save logs to. */
optional string log_file = 17;
/* Minimum log level displayed.
See 'msg LogLevel' description for more */
envar: "HOME=/home/znc"
envar: "TMP=/tmp"
+log_fd: 2
+
rlimit_as: 4096
rlimit_cpu_type: INF
rlimit_fsize: 4096
_log_level = ll;
}
-void logFile(const std::string& logfile) {
+void logFile(const std::string& log_file, int log_fd) {
_log_set = true;
- int newlogfd = TEMP_FAILURE_RETRY(
- open(logfile.c_str(), O_CREAT | O_RDWR | O_APPEND | O_CLOEXEC, 0640));
- if (newlogfd == -1) {
- PLOG_W("Couldn't open logfile open('%s')", logfile.c_str());
- return;
+ int newlogfd = -1;
+ if (!log_file.empty()) {
+ newlogfd = TEMP_FAILURE_RETRY(
+ open(log_file.c_str(), O_CREAT | O_RDWR | O_APPEND | O_CLOEXEC, 0640));
+ if (newlogfd == -1) {
+ PLOG_W("Couldn't open('%s')", log_file.c_str());
+ }
}
/* Close previous log_fd */
if (_log_fd > STDERR_FILENO) {
close(_log_fd);
}
- setDupLogFdOr(newlogfd, STDERR_FILENO);
+ setDupLogFdOr(newlogfd, log_fd);
close(newlogfd);
}
__attribute__((format(printf, 5, 6)));
void logStop(int sig);
void logLevel(enum llevel_t ll);
-void logFile(const std::string& logfile);
+void logFile(const std::string& log_file, int log_fd);
bool logSet();
} // namespace logs