journald-stream.c revision 15a5e95075a7f6007dd97b2a165c8ed16fe683df
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering This file is part of systemd.
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering Copyright 2011 Lennart Poettering
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering systemd is free software; you can redistribute it and/or modify it
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering under the terms of the GNU Lesser General Public License as published by
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering (at your option) any later version.
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering systemd is distributed in the hope that it will be useful, but
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering Lesser General Public License for more details.
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering You should have received a copy of the GNU Lesser General Public License
3d7415f43f0fe6a821d7bc4a341ba371e8a30ef3Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
int fd;
char *label;
char *identifier;
char *unit_id;
int priority;
char *state_file;
if (s->server) {
if (s->event_source) {
free(s);
if (s->state_file)
assert(s);
if (!s->state_file) {
if (asprintf(&s->state_file, "/run/systemd/journal/streams/%lu:%lu", (unsigned long) st.st_dev, (unsigned long) st.st_ino) < 0)
return log_oom();
goto fail;
fprintf(f,
s->priority,
s->level_prefix,
s->forward_to_kmsg,
s->forward_to_console);
if (!escaped) {
r = -ENOMEM;
goto fail;
if (!escaped) {
r = -ENOMEM;
goto fail;
r = fflush_and_check(f);
goto fail;
r = -errno;
goto fail;
if (!s->fdstore) {
s->fdstore = true;
fail:
if (temp_path)
int priority;
assert(s);
assert(p);
if (isempty(p))
if (s->level_prefix)
server_forward_syslog(s->server, syslog_fixup_facility(priority), s->identifier, p, &s->ucred, NULL);
if (s->identifier) {
if (syslog_identifier)
if (message)
server_dispatch_message(s->server, iovec, n, ELEMENTSOF(iovec), &s->ucred, NULL, s->label, label_len, s->unit_id, priority, 0);
assert(s);
assert(p);
p = strstrip(p);
switch (s->state) {
case STDOUT_STREAM_IDENTIFIER:
if (isempty(p))
if (!s->identifier)
return log_oom();
case STDOUT_STREAM_UNIT_ID:
if (isempty(p))
if (!s->unit_id)
return log_oom();
case STDOUT_STREAM_PRIORITY:
return -EINVAL;
r = parse_boolean(p);
return -EINVAL;
s->level_prefix = !!r;
r = parse_boolean(p);
return -EINVAL;
s->forward_to_syslog = !!r;
r = parse_boolean(p);
return -EINVAL;
s->forward_to_kmsg = !!r;
r = parse_boolean(p);
return -EINVAL;
s->forward_to_console = !!r;
(void) stdout_stream_save(s);
case STDOUT_STREAM_RUNNING:
return stdout_stream_log(s, p);
assert(s);
p = s->buffer;
char *end;
if (end)
*end = 0;
r = stdout_stream_line(s, p);
p += skip;
p[remaining] = 0;
r = stdout_stream_line(s, p);
p += remaining;
remaining = 0;
if (p > s->buffer) {
ssize_t l;
assert(s);
goto terminate;
goto terminate;
stdout_stream_scan(s, true);
goto terminate;
s->length += l;
r = stdout_stream_scan(s, false);
goto terminate;
assert(s);
if (!stream)
return log_oom();
if (mac_selinux_use()) {
if (r < 0 && r != -EOPNOTSUPP)
s->n_stdout_streams ++;
if (ret)
static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revents, void *userdata) {
assert(s);
return -EIO;
if (fd < 0) {
return -errno;
_cleanup_free_ char
return log_oom();
NULL);
if (priority) {
if (level_prefix) {
if (forward_to_syslog) {
if (forward_to_kmsg) {
if (forward_to_console) {
assert(s);
return -ENOBUFS;
bool found = false;
Iterator i;
int fd;
found = true;
if (!found) {
fail:
assert(s);
if (s->stdout_fd < 0) {
if (s->stdout_fd < 0)
r = bind(s->stdout_fd, &sa.sa, offsetof(union sockaddr_union, un.sun_path) + strlen(sa.un.sun_path));
r = sd_event_add_io(s->event, &s->stdout_event_source, s->stdout_fd, EPOLLIN, stdout_stream_new, s);