X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fjournal%2Fjournald-stream.c;h=be498d4919d1d7192070403b59e93e59d8b60039;hb=8433e33955f797510a3f323da9ffa08d12c374f4;hp=c032ee4a0ef2c2fd66f72cc05171bb36c29fb3f8;hpb=eff05270986a13e7de93ae16311f654d3f7c166f;p=elogind.git diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c index c032ee4a0..be498d491 100644 --- a/src/journal/journald-stream.c +++ b/src/journal/journald-stream.c @@ -35,6 +35,7 @@ #include "journald-syslog.h" #include "journald-kmsg.h" #include "journald-console.h" +#include "journald-wall.h" #define STDOUT_STREAMS_MAX 4096 @@ -106,6 +107,9 @@ static int stdout_stream_log(StdoutStream *s, const char *p) { if (s->forward_to_console || s->server->forward_to_console) server_forward_console(s->server, priority, s->identifier, p, &s->ucred); + if (s->server->forward_to_wall) + server_forward_wall(s->server, priority, s->identifier, p, &s->ucred); + IOVEC_SET_STRING(iovec[n++], "_TRANSPORT=stdout"); syslog_priority[strlen("PRIORITY=")] = '0' + LOG_PRI(priority); @@ -302,7 +306,7 @@ static int stdout_stream_process(sd_event_source *es, int fd, uint32_t revents, if (errno == EAGAIN) return 0; - log_warning("Failed to read from stream: %m"); + log_warning_errno(errno, "Failed to read from stream: %m"); goto terminate; } @@ -337,8 +341,7 @@ void stdout_stream_free(StdoutStream *s) { s->event_source = sd_event_source_unref(s->event_source); } - if (s->fd >= 0) - close_nointr_nofail(s->fd); + safe_close(s->fd); #ifdef HAVE_SELINUX if (s->security_context) @@ -367,19 +370,19 @@ static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revent if (errno == EAGAIN) return 0; - log_error("Failed to accept stdout connection: %m"); + log_error_errno(errno, "Failed to accept stdout connection: %m"); return -errno; } if (s->n_stdout_streams >= STDOUT_STREAMS_MAX) { log_warning("Too many stdout streams, refusing connection."); - close_nointr_nofail(fd); + safe_close(fd); return 0; } stream = new0(StdoutStream, 1); if (!stream) { - close_nointr_nofail(fd); + safe_close(fd); return log_oom(); } @@ -387,31 +390,31 @@ static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revent r = getpeercred(fd, &stream->ucred); if (r < 0) { - log_error("Failed to determine peer credentials: %m"); + log_error_errno(errno, "Failed to determine peer credentials: %m"); goto fail; } #ifdef HAVE_SELINUX - if (use_selinux()) { + if (mac_selinux_use()) { if (getpeercon(fd, &stream->security_context) < 0 && errno != ENOPROTOOPT) - log_error("Failed to determine peer security context: %m"); + log_error_errno(errno, "Failed to determine peer security context: %m"); } #endif if (shutdown(fd, SHUT_WR) < 0) { - log_error("Failed to shutdown writing side of socket: %m"); + log_error_errno(errno, "Failed to shutdown writing side of socket: %m"); goto fail; } - r = sd_event_add_io(s->event, fd, EPOLLIN, stdout_stream_process, stream, &stream->event_source); + r = sd_event_add_io(s->event, &stream->event_source, fd, EPOLLIN, stdout_stream_process, stream); if (r < 0) { - log_error("Failed to add stream to event loop: %s", strerror(-r)); + log_error_errno(r, "Failed to add stream to event loop: %m"); goto fail; } r = sd_event_source_set_priority(stream->event_source, SD_EVENT_PRIORITY_NORMAL+5); if (r < 0) { - log_error("Failed to adjust stdout event source priority: %s", strerror(-r)); + log_error_errno(r, "Failed to adjust stdout event source priority: %m"); goto fail; } @@ -438,39 +441,29 @@ int server_open_stdout_socket(Server *s) { }; s->stdout_fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); - if (s->stdout_fd < 0) { - log_error("socket() failed: %m"); - return -errno; - } + if (s->stdout_fd < 0) + return log_error_errno(errno, "socket() failed: %m"); unlink(sa.un.sun_path); r = bind(s->stdout_fd, &sa.sa, offsetof(union sockaddr_union, un.sun_path) + strlen(sa.un.sun_path)); - if (r < 0) { - log_error("bind() failed: %m"); - return -errno; - } + if (r < 0) + return log_error_errno(errno, "bind(%s) failed: %m", sa.un.sun_path); chmod(sa.un.sun_path, 0666); - if (listen(s->stdout_fd, SOMAXCONN) < 0) { - log_error("listen() failed: %m"); - return -errno; - } + if (listen(s->stdout_fd, SOMAXCONN) < 0) + return log_error_errno(errno, "listen(%s) failed: %m", sa.un.sun_path); } else fd_nonblock(s->stdout_fd, 1); - r = sd_event_add_io(s->event, s->stdout_fd, EPOLLIN, stdout_stream_new, s, &s->stdout_event_source); - if (r < 0) { - log_error("Failed to add stdout server fd to event source: %s", strerror(-r)); - return r; - } + r = sd_event_add_io(s->event, &s->stdout_event_source, s->stdout_fd, EPOLLIN, stdout_stream_new, s); + if (r < 0) + return log_error_errno(r, "Failed to add stdout server fd to event source: %m"); r = sd_event_source_set_priority(s->stdout_event_source, SD_EVENT_PRIORITY_NORMAL+10); - if (r < 0) { - log_error("Failed to adjust priority of stdout server event source: %s", strerror(-r)); - return r; - } + if (r < 0) + return log_error_errno(r, "Failed to adjust priority of stdout server event source: %m"); return 0; }