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