c83da77762
1 OBS-URL: https://build.opensuse.org/request/show/353460 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/systemd?expand=0&rev=228
176 lines
5.4 KiB
Diff
176 lines
5.4 KiB
Diff
Use and set default logging console for both journald and kernel messages
|
|
|
|
---
|
|
src/journal/journald-console.c | 100 +++++++++++++++++++++++++++++++++++++++++
|
|
src/journal/journald-console.h | 3 +
|
|
src/journal/journald-server.c | 5 ++
|
|
3 files changed, 108 insertions(+)
|
|
|
|
Index: systemd-228/src/journal/journald-console.c
|
|
===================================================================
|
|
--- systemd-228.orig/src/journal/journald-console.c
|
|
+++ systemd-228/src/journal/journald-console.c
|
|
@@ -22,6 +22,14 @@
|
|
#include <fcntl.h>
|
|
#include <sys/socket.h>
|
|
#include <time.h>
|
|
+#ifdef HAVE_SYSV_COMPAT
|
|
+# include <linux/tiocl.h>
|
|
+# include <linux/vt.h>
|
|
+# include <sys/ioctl.h>
|
|
+# include <sys/klog.h>
|
|
+# include <errno.h>
|
|
+# include "string-util.h"
|
|
+#endif
|
|
|
|
#include "alloc-util.h"
|
|
#include "fd-util.h"
|
|
@@ -50,6 +58,76 @@ static bool prefix_timestamp(void) {
|
|
return cached_printk_time;
|
|
}
|
|
|
|
+void default_tty_path(Server *s)
|
|
+{
|
|
+#ifdef HAVE_SYSV_COMPAT
|
|
+ static const char list[] = "/dev/tty10\0" "/dev/console\0";
|
|
+ const char *vc;
|
|
+
|
|
+ if (s->tty_path)
|
|
+ return;
|
|
+
|
|
+ NULSTR_FOREACH(vc, list) {
|
|
+ _cleanup_close_ int fd = -1;
|
|
+
|
|
+ if (access(vc, F_OK) < 0)
|
|
+ continue;
|
|
+
|
|
+ fd = open_terminal(vc, O_WRONLY|O_NOCTTY|O_CLOEXEC);
|
|
+ if (fd < 0)
|
|
+ continue;
|
|
+
|
|
+ s->tty_path = strdup(vc);
|
|
+ break;
|
|
+ }
|
|
+#endif
|
|
+}
|
|
+
|
|
+void klogconsole(Server *s)
|
|
+{
|
|
+#ifdef HAVE_SYSV_COMPAT
|
|
+ _cleanup_free_ char *klogconsole_params = NULL;
|
|
+ _cleanup_close_ int fd = -1;
|
|
+ const char *vc = s->tty_path;
|
|
+ const char *num;
|
|
+ int tiocl[2];
|
|
+ int r;
|
|
+
|
|
+ if (!vc || *vc == 0 || !strneq("/dev/tty", vc, 8))
|
|
+ return;
|
|
+
|
|
+ num = vc + strcspn(vc, "0123456789");
|
|
+ if (safe_atoi(num, &r) < 0)
|
|
+ return;
|
|
+
|
|
+ if (access(vc, F_OK) < 0)
|
|
+ return;
|
|
+
|
|
+ fd = open_terminal(vc, O_RDWR|O_NOCTTY|O_CLOEXEC);
|
|
+ if (fd < 0)
|
|
+ return;
|
|
+
|
|
+ tiocl[0] = TIOCL_SETKMSGREDIRECT;
|
|
+ tiocl[1] = r;
|
|
+
|
|
+ if (ioctl(fd, TIOCLINUX, tiocl) < 0)
|
|
+ return;
|
|
+
|
|
+ zero(klogconsole_params);
|
|
+ r = parse_env_file("/etc/sysconfig/boot", NEWLINE,
|
|
+ "KLOGCONSOLE_PARAMS", &klogconsole_params,
|
|
+ NULL);
|
|
+ if (r < 0)
|
|
+ return;
|
|
+ if (!klogconsole_params || *klogconsole_params == 0)
|
|
+ return;
|
|
+
|
|
+ num = klogconsole_params + strcspn(klogconsole_params, "0123456789");
|
|
+ if (safe_atoi(num, &r) == 0)
|
|
+ klogctl(8, 0, r);
|
|
+#endif
|
|
+}
|
|
+
|
|
void server_forward_console(
|
|
Server *s,
|
|
int priority,
|
|
@@ -71,6 +149,12 @@ void server_forward_console(
|
|
if (LOG_PRI(priority) > s->max_level_console)
|
|
return;
|
|
|
|
+#ifdef HAVE_SYSV_COMPAT
|
|
+ /* Do not write security/authorization (private) messages to console */
|
|
+ if ((priority & LOG_FACMASK) == LOG_AUTHPRIV)
|
|
+ return;
|
|
+#endif
|
|
+
|
|
/* First: timestamp */
|
|
if (prefix_timestamp()) {
|
|
assert_se(clock_gettime(CLOCK_MONOTONIC, &ts) == 0);
|
|
@@ -107,7 +191,23 @@ void server_forward_console(
|
|
fd = open_terminal(tty, O_WRONLY|O_NOCTTY|O_CLOEXEC);
|
|
if (fd < 0) {
|
|
log_debug_errno(fd, "Failed to open %s for logging: %m", tty);
|
|
+#ifdef HAVE_SYSV_COMPAT
|
|
+ if (fd != -ENOENT && fd != -ENODEV)
|
|
+ return;
|
|
+ if (tty != s->tty_path)
|
|
+ return;
|
|
+ if (!streq("/dev/console", tty)) {
|
|
+ if (s->tty_path)
|
|
+ free(s->tty_path);
|
|
+ s->tty_path = NULL;
|
|
+ tty = "/dev/console";
|
|
+ fd = open_terminal(tty, O_WRONLY|O_NOCTTY|O_CLOEXEC);
|
|
+ if (fd < 0)
|
|
+ return;
|
|
+ }
|
|
+#else
|
|
return;
|
|
+#endif
|
|
}
|
|
|
|
if (writev(fd, iovec, n) < 0)
|
|
Index: systemd-228/src/journal/journald-console.h
|
|
===================================================================
|
|
--- systemd-228.orig/src/journal/journald-console.h
|
|
+++ systemd-228/src/journal/journald-console.h
|
|
@@ -24,3 +24,6 @@
|
|
#include "journald-server.h"
|
|
|
|
void server_forward_console(Server *s, int priority, const char *identifier, const char *message, const struct ucred *ucred);
|
|
+
|
|
+void klogconsole(Server *s);
|
|
+void default_tty_path(Server *s);
|
|
Index: systemd-228/src/journal/journald-server.c
|
|
===================================================================
|
|
--- systemd-228.orig/src/journal/journald-server.c
|
|
+++ systemd-228/src/journal/journald-server.c
|
|
@@ -55,6 +55,7 @@
|
|
#include "journald-audit.h"
|
|
#include "journald-kmsg.h"
|
|
#include "journald-native.h"
|
|
+#include "journald-console.h"
|
|
#include "journald-rate-limit.h"
|
|
#include "journald-server.h"
|
|
#include "journald-stream.h"
|
|
@@ -1751,6 +1752,10 @@ int server_init(Server *s) {
|
|
|
|
server_parse_config_file(s);
|
|
server_parse_proc_cmdline(s);
|
|
+ default_tty_path(s);
|
|
+
|
|
+ if (s->tty_path)
|
|
+ klogconsole(s);
|
|
|
|
if (!!s->rate_limit_interval ^ !!s->rate_limit_burst) {
|
|
log_debug("Setting both rate limit interval and burst from "USEC_FMT",%u to 0,0",
|