journald-console.c revision 709f6e46a35ec492b70eb92943d82a8d838ce918
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering This file is part of systemd.
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering Copyright 2011 Lennart Poettering
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering systemd is free software; you can redistribute it and/or modify it
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering under the terms of the GNU Lesser General Public License as published by
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering (at your option) any later version.
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering systemd is distributed in the hope that it will be useful, but
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering Lesser General Public License for more details.
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering You should have received a copy of the GNU Lesser General Public License
3731acf1acfb4a6eb68374a5b137f3b368f63381Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
0f4ba83c397e807939a4eb0b2cbd04ad4ab548ccLennart Poetteringstatic bool prefix_timestamp(void) {
0f4ba83c397e807939a4eb0b2cbd04ad4ab548ccLennart Poettering if (_unlikely_(cached_printk_time < 0)) {
0f4ba83c397e807939a4eb0b2cbd04ad4ab548ccLennart Poettering read_one_line_file("/sys/module/printk/parameters/time", &p) >= 0
0f4ba83c397e807939a4eb0b2cbd04ad4ab548ccLennart Poettering char tbuf[sizeof("[] ")-1 + DECIMAL_STR_MAX(ts.tv_sec) + DECIMAL_STR_MAX(ts.tv_nsec)-3 + 1];
0f4ba83c397e807939a4eb0b2cbd04ad4ab548ccLennart Poettering char header_pid[sizeof("[]: ")-1 + DECIMAL_STR_MAX(pid_t)];
938d2699d2e818bd996614e89ea3d668200ad2a8Zbigniew Jędrzejewski-Szmek if (LOG_PRI(priority) > s->max_level_console)
0f4ba83c397e807939a4eb0b2cbd04ad4ab548ccLennart Poettering /* First: timestamp */
0f4ba83c397e807939a4eb0b2cbd04ad4ab548ccLennart Poettering assert_se(clock_gettime(CLOCK_MONOTONIC, &ts) == 0);
0f4ba83c397e807939a4eb0b2cbd04ad4ab548ccLennart Poettering /* Second: identifier and PID */
0f4ba83c397e807939a4eb0b2cbd04ad4ab548ccLennart Poettering get_process_comm(ucred->pid, &ident_buf);
0f4ba83c397e807939a4eb0b2cbd04ad4ab548ccLennart Poettering xsprintf(header_pid, "["PID_FMT"]: ", ucred->pid);
0f4ba83c397e807939a4eb0b2cbd04ad4ab548ccLennart Poettering IOVEC_SET_STRING(iovec[n++], identifier);
0f4ba83c397e807939a4eb0b2cbd04ad4ab548ccLennart Poettering IOVEC_SET_STRING(iovec[n++], header_pid);
0f4ba83c397e807939a4eb0b2cbd04ad4ab548ccLennart Poettering IOVEC_SET_STRING(iovec[n++], identifier);
0f4ba83c397e807939a4eb0b2cbd04ad4ab548ccLennart Poettering /* Fourth: message */
0f4ba83c397e807939a4eb0b2cbd04ad4ab548ccLennart Poettering tty = s->tty_path ? s->tty_path : "/dev/console";
0f4ba83c397e807939a4eb0b2cbd04ad4ab548ccLennart Poettering fd = open_terminal(tty, O_WRONLY|O_NOCTTY|O_CLOEXEC);
0f4ba83c397e807939a4eb0b2cbd04ad4ab548ccLennart Poettering log_debug_errno(fd, "Failed to open %s for logging: %m", tty);
0f4ba83c397e807939a4eb0b2cbd04ad4ab548ccLennart Poettering log_debug_errno(errno, "Failed to write to %s for logging: %m", tty);