journald-syslog.c revision 4a61c3e51e96a747c30598d78ee3a24e7c569e9f
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis This file is part of systemd.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis Copyright 2011 Lennart Poettering
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis systemd is free software; you can redistribute it and/or modify it
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis under the terms of the GNU Lesser General Public License as published by
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis the Free Software Foundation; either version 2.1 of the License, or
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis (at your option) any later version.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis systemd is distributed in the hope that it will be useful, but
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis WITHOUT ANY WARRANTY; without even the implied warranty of
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis Lesser General Public License for more details.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis You should have received a copy of the GNU Lesser General Public License
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis along with systemd; If not, see <http://www.gnu.org/licenses/>.
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis/* Warn once every 30s if we missed syslog message */
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis#define WARN_FORWARD_SYSLOG_MISSED_USEC (30 * USEC_PER_SEC)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtisstatic void forward_syslog_iovec(Server *s, const struct iovec *iovec, unsigned n_iovec, const struct ucred *ucred, const struct timeval *tv) {
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis .un.sun_path = "/run/systemd/journal/syslog",
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis .msg_namelen = offsetof(union sockaddr_union, un.sun_path)
25c28e83beb90e7c80452a7c818c5e6f73a07dc8Piotr Jasiukajtis uint8_t buf[CMSG_SPACE(sizeof(struct ucred))];
assert(s);
if (ucred) {
s->n_forward_syslog_missed++;
struct ucred u;
u = *ucred;
s->n_forward_syslog_missed++;
static void forward_syslog_raw(Server *s, int priority, const char *buffer, const struct ucred *ucred, const struct timeval *tv) {
assert(s);
void server_forward_syslog(Server *s, int priority, const char *identifier, const char *message, const struct ucred *ucred, const struct timeval *tv) {
time_t t;
assert(s);
if (!tm)
if (ucred) {
if (!identifier) {
if (identifier)
} else if (identifier) {
return priority;
size_t l, e;
p = *buf;
*pid = t;
t = strndup(p, l);
*identifier = t;
*buf = p + e;
} sequence[] = {
p = *buf;
switch (sequence[i]) {
case SPACE:
case SPACE_OR_NUMBER:
case NUMBER:
case LETTER:
case COLON:
*buf = p;
Server *s,
const char *buf,
const char *label,
const char *orig;
assert(s);
if (s->forward_to_syslog)
if (s->forward_to_kmsg)
if (s->forward_to_console)
if (s->forward_to_wall)
if (identifier) {
if (syslog_identifier)
if (pid) {
if (syslog_pid)
if (message)
server_dispatch_message(s, iovec, n, ELEMENTSOF(iovec), ucred, tv, label, label_len, NULL, priority, 0);
assert(s);
if (s->syslog_fd < 0) {
if (s->syslog_fd < 0)
r = bind(s->syslog_fd, &sa.sa, offsetof(union sockaddr_union, un.sun_path) + strlen(sa.un.sun_path));
#ifdef HAVE_SELINUX
if (mac_selinux_use()) {
r = sd_event_add_io(s->event, &s->syslog_event_source, s->syslog_fd, EPOLLIN, server_process_datagram, s);
usec_t n;
assert(s);
if (s->n_forward_syslog_missed <= 0)
server_driver_message(s, SD_MESSAGE_FORWARD_SYSLOG_MISSED, "Forwarding to syslog missed %u messages.", s->n_forward_syslog_missed);
s->n_forward_syslog_missed = 0;
s->last_warn_forward_syslog_missed = n;