mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-20 05:37:57 +00:00
Redirect any output from the server to stderr to the log file
Mainly to capture the output of any 3rd party libraries
This commit is contained in:
parent
389f16d2bb
commit
bf0abad719
7
log.c
7
log.c
@ -498,6 +498,11 @@ static void _open_log_file(_log_iterator *it)
|
|||||||
_log_current_datetime(it, LOG_LEVEL_INFO);
|
_log_current_datetime(it, LOG_LEVEL_INFO);
|
||||||
log_mkdir_trace(dir);
|
log_mkdir_trace(dir);
|
||||||
_logs_printf_nl(LOG_LEVEL_INFO, __NOWHERE__, "Logging to %s (fd %d)", _log_file_path, fileno(_log_file));
|
_logs_printf_nl(LOG_LEVEL_INFO, __NOWHERE__, "Logging to %s (fd %d)", _log_file_path, fileno(_log_file));
|
||||||
|
|
||||||
|
// if stderr should be redirected
|
||||||
|
if (logfile_stderr == NO_FILE)
|
||||||
|
dup2(fileno(_log_file),STDERR_FILENO);
|
||||||
|
|
||||||
// Update the log symlink to point to the latest log file.
|
// Update the log symlink to point to the latest log file.
|
||||||
strbuf sbsymlink = strbuf_alloca(400);
|
strbuf sbsymlink = strbuf_alloca(400);
|
||||||
strbuf_system_log_path(sbsymlink);
|
strbuf_system_log_path(sbsymlink);
|
||||||
@ -634,7 +639,7 @@ static void _flush_log_stderr()
|
|||||||
fflush(logfile_stderr);
|
fflush(logfile_stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void disable_log_stderr()
|
void redirect_stderr_to_log()
|
||||||
{
|
{
|
||||||
if (logfile_stderr && logfile_stderr != NO_FILE) {
|
if (logfile_stderr && logfile_stderr != NO_FILE) {
|
||||||
fflush(logfile_stderr);
|
fflush(logfile_stderr);
|
||||||
|
2
log.h
2
log.h
@ -50,7 +50,7 @@ int string_to_log_level(const char *text);
|
|||||||
// Log output control.
|
// Log output control.
|
||||||
extern int logLevel_NoLogFileConfigured;
|
extern int logLevel_NoLogFileConfigured;
|
||||||
void close_log_file();
|
void close_log_file();
|
||||||
void disable_log_stderr();
|
void redirect_stderr_to_log();
|
||||||
void logFlush();
|
void logFlush();
|
||||||
void logConfigChanged();
|
void logConfigChanged();
|
||||||
|
|
||||||
|
2
server.c
2
server.c
@ -754,7 +754,6 @@ static int app_server_start(const struct cli_parsed *parsed, struct cli_context
|
|||||||
*/
|
*/
|
||||||
DEBUG(verbose, "Grand-Child Process, reopening log");
|
DEBUG(verbose, "Grand-Child Process, reopening log");
|
||||||
close_log_file();
|
close_log_file();
|
||||||
disable_log_stderr();
|
|
||||||
int fd;
|
int fd;
|
||||||
if ((fd = open("/dev/null", O_RDWR, 0)) == -1)
|
if ((fd = open("/dev/null", O_RDWR, 0)) == -1)
|
||||||
exit(WHY_perror("open(\"/dev/null\")"));
|
exit(WHY_perror("open(\"/dev/null\")"));
|
||||||
@ -770,6 +769,7 @@ static int app_server_start(const struct cli_parsed *parsed, struct cli_context
|
|||||||
exit(WHYF_perror("dup2(%d,stderr)", fd));
|
exit(WHYF_perror("dup2(%d,stderr)", fd));
|
||||||
if (fd > 2)
|
if (fd > 2)
|
||||||
(void)close(fd);
|
(void)close(fd);
|
||||||
|
redirect_stderr_to_log();
|
||||||
/* The execpath option is provided so that a JNI call to "start" can be made which
|
/* The execpath option is provided so that a JNI call to "start" can be made which
|
||||||
creates a new server daemon process with the correct argv[0]. Otherwise, the servald
|
creates a new server daemon process with the correct argv[0]. Otherwise, the servald
|
||||||
process appears as a process with argv[0] = "org.servalproject". */
|
process appears as a process with argv[0] = "org.servalproject". */
|
||||||
|
Loading…
Reference in New Issue
Block a user