journald.c revision 8b18eb674ce4d14e4819e102a0d6679a0fd2e6ce
90N/A along with systemd; If not, see <http://www.gnu.org/licenses/>.
4466N/A#include "journal-file.h"
7243N/A#include "sd-daemon.h"
7243N/A#include "socket-util.h"
7243N/A#include "acl-util.h"
7243N/A#include "cgroup-util.h"
5680N/A#include "journal-rate-limit.h"
90N/A#include "sd-journal.h"
6251N/A#include "journal-internal.h"
unsigned n_stdout_streams;
} Server;
typedef enum StdoutStreamState {
struct StdoutStream {
int fd;
char *tag;
int priority;
DIR *d;
return s->cached_available_space;
if (s->system_journal)
d = opendir(p);
free(p);
goto finish;
goto finish;
if (!de)
closedir(d);
return avail;
assert(f);
if (uid <= 0)
if (!acl) {
goto finish;
goto finish;
JournalFile *f;
assert(s);
if (s->runtime_journal)
return s->runtime_journal;
if (uid <= 0)
return s->system_journal;
return s->system_journal;
if (asprintf(&p, "/var/log/journal/%s/user-%lu.journal", sd_id128_to_string(machine, ids), (unsigned long) uid) < 0)
return s->system_journal;
assert(f);
free(p);
return s->system_journal;
return s->system_journal;
Iterator i;
JournalFile *f;
if (s->runtime_journal) {
if (s->system_journal) {
r = journal_file_rotate(&f);
if (r < 0 && r != -ENOENT)
free(p);
if (r < 0 && r != -ENOENT)
free(p);
s->cached_available_space_timestamp = 0;
return NULL;
return NULL;
init_path[0] = 0;
return path;
JournalFile *f;
bool vacuumed = false;
assert(s);
assert(n > 0);
if (ucred) {
char *path;
if (comm)
free(t);
if (comm)
free(t);
if (cmdline)
free(t);
if (path) {
if (cgroup)
if (tv) {
t = gethostname_malloc();
if (hostname)
free(t);
assert(n <= m);
server_vacuum(s);
vacuumed = true;
goto retry;
int priority) {
int rl;
char *path, *c;
assert(s);
if (!ucred)
goto finish;
if (!path)
goto finish;
if (rl == 0) {
snprintf(suppress_message, sizeof(suppress_message), "MESSAGE=Suppressed %u messages from %s", rl - 1, path);
static void process_syslog_message(Server *s, const char *buf, struct ucred *ucred, struct timeval *tv) {
assert(s);
if (message)
static void process_native_message(Server *s, const void *buffer, size_t buffer_size, struct ucred *ucred, struct timeval *tv) {
assert(s);
p = buffer;
while (remaining > 0) {
remaining--;
struct iovec *c;
iovec = c;
if (valid_user_field(p, q - p)) {
uint64_t l;
l = le64toh(l);
memcpy(k, p, e - p);
if (valid_user_field(p, e - p)) {
free(k);
int priority;
assert(s);
assert(p);
if (s->priority_prefix &&
if (message) {
if (s->tag) {
if (s->tee_console) {
int console;
if (console >= 0) {
if (s->tag) {
assert(s);
assert(p);
switch (s->state) {
case STDOUT_STREAM_TAG:
if (!s->tag) {
return -EINVAL;
case STDOUT_STREAM_PRIORITY:
return -EINVAL;
return -EINVAL;
return -EINVAL;
case STDOUT_STREAM_RUNNING:
return stdout_stream_log(s, p, l);
assert(s);
p = s->buffer;
char *end;
if (!end) {
p += skip;
p += remaining;
remaining = 0;
if (p > s->buffer) {
ssize_t l;
assert(s);
return -errno;
r = stdout_stream_scan(s, true);
s->length += l;
r = stdout_stream_scan(s, false);
assert(s);
if (s->server) {
if (s->fd >= 0) {
if (s->server)
free(s);
int fd, r;
assert(s);
if (fd < 0) {
return -errno;
if (!stream) {
return -ENOMEM;
r = -errno;
goto fail;
r = -errno;
goto fail;
r = -errno;
goto fail;
s->n_stdout_streams ++;
fail:
char *fn;
if (!s->system_journal) {
if (!fn)
return -ENOMEM;
if (!fn)
return -ENOMEM;
if (r == -ENOENT)
if (!s->runtime_journal) {
if (!fn)
return -ENOMEM;
if (s->system_journal) {
if (r == -ENOENT)
if (s->runtime_journal) {
sd_journal *j;
assert(s);
if (!s->runtime_journal)
if (!s->system_journal)
SD_JOURNAL_FOREACH(j) {
JournalFile *f;
f = j->current_file;
goto finish;
if (r == -E2BIG) {
server_vacuum(s);
goto finish;
static void forward_syslog(Server *s, const void *buffer, size_t length, struct ucred *ucred, struct timeval *tv) {
} control;
assert(s);
struct ucred u;
u = *ucred;
assert(s);
ssize_t n;
return -EIO;
if (n != sizeof(sfsi)) {
return -EIO;
return -errno;
return -EIO;
} control;
ssize_t n;
return -errno;
size_t l;
return -ENOMEM;
s->buffer_size = l;
s->buffer = b;
return -errno;
s->buffer[n] = 0;
return -EIO;
return -EIO;
int one, r;
assert(s);
if (s->syslog_fd < 0) {
if (s->syslog_fd < 0) {
return -errno;
r = bind(s->syslog_fd, &sa.sa, offsetof(union sockaddr_union, un.sun_path) + strlen(sa.un.sun_path));
return -errno;
return -errno;
return -errno;
return -errno;
return -errno;
int one, r;
assert(s);
if (s->native_fd < 0) {
if (s->native_fd < 0) {
return -errno;
r = bind(s->native_fd, &sa.sa, offsetof(union sockaddr_union, un.sun_path) + strlen(sa.un.sun_path));
return -errno;
return -errno;
return -errno;
return -errno;
assert(s);
if (s->stdout_fd < 0) {
if (s->stdout_fd < 0) {
return -errno;
r = bind(s->stdout_fd, &sa.sa, offsetof(union sockaddr_union, un.sun_path) + strlen(sa.un.sun_path));
return -errno;
return -errno;
return -errno;
assert(s);
if (s->signal_fd < 0) {
return -errno;
return -errno;
int n, r, fd;
assert(s);
zero(*s);
s->compress = true;
if (!s->user_journals) {
return -ENOMEM;
if (s->epoll_fd < 0) {
return -errno;
n = sd_listen_fds(true);
if (s->native_fd >= 0) {
return -EINVAL;
if (s->stdout_fd >= 0) {
return -EINVAL;
if (s->syslog_fd >= 0) {
return -EINVAL;
return -EINVAL;
r = open_syslog_socket(s);
r = open_native_socket(s);
r = open_stdout_socket(s);
r = system_journal_open(s);
r = open_signalfd(s);
if (!s->rate_limit)
return -ENOMEM;
JournalFile *f;
assert(s);
while (s->stdout_streams)
if (s->system_journal)
if (s->runtime_journal)
if (s->epoll_fd >= 0)
if (s->signal_fd >= 0)
if (s->syslog_fd >= 0)
if (s->native_fd >= 0)
if (s->stdout_fd >= 0)
if (s->rate_limit)
return EXIT_FAILURE;
log_open();
goto finish;
sd_notify(false,
r = -errno;
goto finish;
goto finish;
sd_notify(false,