Resolves: RHEL-85950 - FRR doesn't send logs to stdout when running as a daemon
This commit is contained in:
parent
e350fe293c
commit
ee803a9b29
108
0012-print-log-to-stdout.patch
Normal file
108
0012-print-log-to-stdout.patch
Normal file
@ -0,0 +1,108 @@
|
||||
From 4d28aea95851dc14b3987b004f457d7a4a1535f8 Mon Sep 17 00:00:00 2001
|
||||
From: Lou Berger <lberger@labn.net>
|
||||
Date: Sun, 2 Oct 2022 15:56:07 +0000
|
||||
Subject: [PATCH] lib: when running as a daemon, only redirect sdtin, stdout,
|
||||
sdterr to null when a tty.
|
||||
|
||||
Also write memstat to stderr when stderr is not a tty
|
||||
and allow for --log stdout
|
||||
|
||||
Signed-off-by: Lou Berger <lberger@labn.net>
|
||||
---
|
||||
lib/libfrr.c | 44 +++++++++++++++++++++++++++++++-------------
|
||||
1 file changed, 31 insertions(+), 13 deletions(-)
|
||||
|
||||
diff --git a/lib/libfrr.c b/lib/libfrr.c
|
||||
index 07e2eafec59c..e8900572694a 100644
|
||||
--- a/lib/libfrr.c
|
||||
+++ b/lib/libfrr.c
|
||||
@@ -130,6 +130,7 @@ static const struct optspec os_always = {
|
||||
" --limit-fds Limit number of fds supported\n",
|
||||
lo_always};
|
||||
|
||||
+static bool logging_to_stdout = false; /* set when --log stdout specified */
|
||||
|
||||
static const struct option lo_cfg[] = {
|
||||
{"config_file", required_argument, NULL, 'f'},
|
||||
@@ -738,6 +739,11 @@ struct event_loop *frr_init(void)
|
||||
while ((log_arg = log_args_pop(di->early_logging))) {
|
||||
command_setup_early_logging(log_arg->target,
|
||||
di->early_loglevel);
|
||||
+ /* this is a bit of a hack,
|
||||
+ but need to notice when
|
||||
+ the target is stdout */
|
||||
+ if (strcmp(log_arg->target, "stdout") == 0)
|
||||
+ logging_to_stdout = true;
|
||||
XFREE(MTYPE_TMP, log_arg);
|
||||
}
|
||||
|
||||
@@ -1088,9 +1094,15 @@ static void frr_terminal_close(int isexit)
|
||||
"%s: failed to open /dev/null: %s", __func__,
|
||||
safe_strerror(errno));
|
||||
} else {
|
||||
- dup2(nullfd, 0);
|
||||
- dup2(nullfd, 1);
|
||||
- dup2(nullfd, 2);
|
||||
+ int fd;
|
||||
+ /*
|
||||
+ * only redirect stdin, stdout, stderr to null when a tty also
|
||||
+ * don't redirect when stdout is set with --log stdout
|
||||
+ */
|
||||
+ for (fd = 2; fd >= 0; fd--)
|
||||
+ if (isatty(fd) &&
|
||||
+ (fd != STDOUT_FILENO || !logging_to_stdout))
|
||||
+ dup2(nullfd, fd);
|
||||
close(nullfd);
|
||||
}
|
||||
}
|
||||
@@ -1168,9 +1180,16 @@ void frr_run(struct event_loop *master)
|
||||
"%s: failed to open /dev/null: %s",
|
||||
__func__, safe_strerror(errno));
|
||||
} else {
|
||||
- dup2(nullfd, 0);
|
||||
- dup2(nullfd, 1);
|
||||
- dup2(nullfd, 2);
|
||||
+ int fd;
|
||||
+ /*
|
||||
+ * only redirect stdin, stdout, stderr to null when a
|
||||
+ * tty also don't redirect when stdout is set with --log
|
||||
+ * stdout
|
||||
+ */
|
||||
+ for (fd = 2; fd >= 0; fd--)
|
||||
+ if (isatty(fd) &&
|
||||
+ (fd != STDOUT_FILENO || !logging_to_stdout))
|
||||
+ dup2(nullfd, fd);
|
||||
close(nullfd);
|
||||
}
|
||||
|
||||
@@ -1194,7 +1213,7 @@ void frr_fini(void)
|
||||
{
|
||||
FILE *fp;
|
||||
char filename[128];
|
||||
- int have_leftovers;
|
||||
+ int have_leftovers = 0;
|
||||
|
||||
hook_call(frr_fini);
|
||||
|
||||
@@ -1220,16 +1239,15 @@ void frr_fini(void)
|
||||
/* frrmod_init -> nothing needed / hooks */
|
||||
rcu_shutdown();
|
||||
|
||||
- if (!debug_memstats_at_exit)
|
||||
- return;
|
||||
-
|
||||
- have_leftovers = log_memstats(stderr, di->name);
|
||||
+ /* also log memstats to stderr when stderr goes to a file*/
|
||||
+ if (debug_memstats_at_exit || !isatty(STDERR_FILENO))
|
||||
+ have_leftovers = log_memstats(stderr, di->name);
|
||||
|
||||
/* in case we decide at runtime that we want exit-memstats for
|
||||
- * a daemon, but it has no stderr because it's daemonized
|
||||
+ * a daemon
|
||||
* (only do this if we actually have something to print though)
|
||||
*/
|
||||
- if (!have_leftovers)
|
||||
+ if (!debug_memstats_at_exit || !have_leftovers)
|
||||
return;
|
||||
|
||||
snprintf(filename, sizeof(filename), "/tmp/frr-memstats-%s-%llu-%llu",
|
6
frr.spec
6
frr.spec
@ -7,7 +7,7 @@
|
||||
|
||||
Name: frr
|
||||
Version: 8.5.3
|
||||
Release: 7%{?checkout}%{?dist}
|
||||
Release: 8%{?checkout}%{?dist}
|
||||
Summary: Routing daemon
|
||||
License: GPLv2+
|
||||
URL: http://www.frrouting.org
|
||||
@ -74,6 +74,7 @@ Patch0008: 0008-CVE-2023-46753.patch
|
||||
Patch0009: 0009-bfd-bgp-shutdown-notification.patch
|
||||
Patch0010: 0010-bgp-bfd-drop-connection.patch
|
||||
Patch0011: 0011-bgp-graceful-restart-noop.patch
|
||||
Patch0012: 0012-print-log-to-stdout.patch
|
||||
|
||||
%description
|
||||
FRRouting is free software that manages TCP/IP based routing protocols. It takes
|
||||
@ -279,6 +280,9 @@ make check PYTHON=%{__python3}
|
||||
%endif
|
||||
|
||||
%changelog
|
||||
* Thu Apr 03 2025 Michal Ruprich <mruprich@redhat.com> - 8.5.3-8
|
||||
- Resolves: RHEL-85950 - FRR doesn't send logs to stdout when running as a daemon
|
||||
|
||||
* Fri Feb 14 2025 Michal Ruprich <mruprich@redhat.com> - 8.5.3-7
|
||||
- Resolves: RHEL-68432 - FRR gives false warning when Graceful Restart enabled
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user