journald-syslog.c revision 7ccbd1ae843d77275f2c542582a9a80e5e058a70
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2011 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stddef.h>
#include <unistd.h>
#include "sd-messages.h"
#include "fd-util.h"
#include "formats-util.h"
#include "journald-console.h"
#include "journald-kmsg.h"
#include "journald-server.h"
#include "journald-syslog.h"
#include "journald-wall.h"
#include "process-util.h"
#include "selinux-util.h"
#include "socket-util.h"
#include "string-util.h"
#include "syslog-util.h"
/* Warn once every 30s if we missed syslog message */
static void forward_syslog_iovec(Server *s, const struct iovec *iovec, unsigned n_iovec, const struct ucred *ucred, const struct timeval *tv) {
static const union sockaddr_union sa = {
};
.msg_iovlen = n_iovec,
};
union {
} control;
assert(s);
if (ucred) {
}
* the SO_TIMESTAMP auxiliary data, and hence we don't. */
return;
/* The socket is full? I guess the syslog implementation is
* too slow, and we shouldn't wait for that... */
s->n_forward_syslog_missed++;
return;
}
struct ucred u;
/* Hmm, presumably the sender process vanished
* by now, or we don't have CAP_SYS_AMDIN, so
* let's fix it as good as we can, and retry */
u = *ucred;
return;
s->n_forward_syslog_missed++;
return;
}
}
}
static void forward_syslog_raw(Server *s, int priority, const char *buffer, const struct ucred *ucred, const struct timeval *tv) {
assert(s);
return;
}
void server_forward_syslog(Server *s, int priority, const char *identifier, const char *message, const struct ucred *ucred, const struct timeval *tv) {
int n = 0;
time_t t;
assert(s);
return;
/* First: priority field */
/* Second: timestamp */
if (!tm)
return;
return;
/* Third: identifier and PID */
if (ucred) {
if (!identifier) {
}
if (identifier)
} else if (identifier) {
}
/* Fourth: message */
}
int syslog_fixup_facility(int priority) {
if ((priority & LOG_FACMASK) == 0)
return priority;
}
const char *p;
char *t;
size_t l, e;
p = *buf;
p += strspn(p, WHITESPACE);
l = strcspn(p, WHITESPACE);
if (l <= 0 ||
p[l-1] != ':')
return 0;
e = l;
l--;
if (p[l-1] == ']') {
size_t k = l-1;
for (;;) {
if (p[k] == '[') {
if (t)
*pid = t;
l = k;
break;
}
if (k == 0)
break;
k--;
}
}
t = strndup(p, l);
if (t)
*identifier = t;
if (strchr(WHITESPACE, p[e]))
e++;
*buf = p + e;
return e;
}
static void syslog_skip_date(char **buf) {
enum {
} sequence[] = {
};
char *p;
unsigned i;
p = *buf;
for (i = 0; i < ELEMENTSOF(sequence); i++, p++) {
if (!*p)
return;
switch (sequence[i]) {
case SPACE:
if (*p != ' ')
return;
break;
case SPACE_OR_NUMBER:
if (*p == ' ')
break;
/* fall through */
case NUMBER:
if (*p < '0' || *p > '9')
return;
break;
case LETTER:
if (!(*p >= 'A' && *p <= 'Z') &&
!(*p >= 'a' && *p <= 'z'))
return;
break;
case COLON:
if (*p != ':')
return;
break;
}
}
*buf = p;
}
Server *s,
const char *buf,
const char *label,
unsigned n = 0;
const char *orig;
assert(s);
if (s->forward_to_syslog)
syslog_skip_date((char**) &buf);
if (s->forward_to_kmsg)
if (s->forward_to_console)
if (s->forward_to_wall)
if (priority & LOG_FACMASK) {
}
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);
}
int server_open_syslog_socket(Server *s) {
static const int one = 1;
int r;
assert(s);
if (s->syslog_fd < 0) {
static const union sockaddr_union sa = {
};
if (s->syslog_fd < 0)
r = bind(s->syslog_fd, &sa.sa, offsetof(union sockaddr_union, un.sun_path) + strlen(sa.un.sun_path));
if (r < 0)
} else
if (r < 0)
#ifdef HAVE_SELINUX
if (mac_selinux_use()) {
if (r < 0)
}
#endif
if (r < 0)
r = sd_event_add_io(s->event, &s->syslog_event_source, s->syslog_fd, EPOLLIN, server_process_datagram, s);
if (r < 0)
return log_error_errno(r, "Failed to add syslog server fd to event loop: %m");
return 0;
}
void server_maybe_warn_forward_syslog_missed(Server *s) {
usec_t n;
assert(s);
if (s->n_forward_syslog_missed <= 0)
return;
n = now(CLOCK_MONOTONIC);
return;
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;
}