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